Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataset Management API Support #83

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Desktop.ini
*.suo
*.user
.vs/
.vscode/

# Build results
bin/[Dd]ebug/
Expand Down
8 changes: 4 additions & 4 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Deploying a new release

Deployment is hard. There are too many manual steps. Let's at least enumerate
Deployment is hard. There are too many manual steps. Let's at least enumerate
them so everyone is on the same page.

Assuming all changes for the new release are commited, tests have been run and
Expand All @@ -9,11 +9,11 @@ are passing, and you're happy with the state of things...
1. Create a branch named `release`
1. Update [`ReleaseNotes.md`](ReleaseNotes.md), following the existing format
1. Bump the version number in [`Directory.build.props`](Directory.build.props) and [`appveyor.yml`](appveyor.yml)
1. Push the branch to GitHub and create a pull request
1. Create the NuGet packages (in the local solution root) for the new version: `dotnet pack --output .`
1. Test the NuGet packages! [How to install NuGet package locally](http://stackoverflow.com/questions/10240029/how-to-install-a-nuget-package-nupkg-file-locally)
1. Push the `release` branch to GitHub and create a pull request
1. If the build succeeds, accept the pull request
1. Create and push a tag from the new HEAD `git tag v#.#.#` and `git push --tags`
1. Create the NuGet packages (in the local solution root) for the new version: `dotnet pack --output ..\`
1. Test the NuGet packages! [How to install NuGet package locally](http://stackoverflow.com/questions/10240029/how-to-install-a-nuget-package-nupkg-file-locally)
1. [Create a new release](https://help.github.com/articles/creating-releases) using the tag
you just created and pasting in the release notes you just wrote up. Attach a copy of the latest `.nupkg` files generated above.
1. Push the new packages up to NuGet `dotnet nuget push`
6 changes: 5 additions & 1 deletion Directory.build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<Product>SODA</Product>
<RepositoryUrl>https://github.com/CityofSantaMonica/SODA.NET</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>0.9.0</Version>
<PackageIcon>icon.png</PackageIcon>
<Version>0.10.1</Version>
</PropertyGroup>
<ItemGroup>
<None Include="..\icon.png" Pack="true" PackagePath="\"/>
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions Net45.SODA.Tests/Net45.SODA.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.10.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
23 changes: 23 additions & 0 deletions NetCore30.SODA.Tests/NetCore30.SODA.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>

<IsPackable>false</IsPackable>

<AssemblyName>NetCore30.SODA.Tests</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SODA\SODA.csproj" />
</ItemGroup>

<Import Project="..\SODA.Tests\SODA.Tests.projitems" Label="Shared" />

</Project>
27 changes: 27 additions & 0 deletions NetCore30.Utilities.Tests/NetCore30.Utilities.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>

<IsPackable>false</IsPackable>

<AssemblyName>NetCore30.SODA.Utilities.Tests</AssemblyName>

<RootNamespace>NetCore30.SODA.Utilities.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.6.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SODA\SODA.csproj" />
<ProjectReference Include="..\Utilities\Utilities.csproj" />
</ItemGroup>

<Import Project="..\Utilities.Tests\Utilities.Tests.projitems" Label="Shared" />

</Project>
155 changes: 131 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# SODA.NET [![Build status](https://ci.appveyor.com/api/projects/status/yub6lyl79573lufv/branch/master?svg=true)](https://ci.appveyor.com/project/thekaveman/soda-net/branch/master)

A [Socrata Open Data API](http://dev.socrata.com) (SODA) client library targeting
.NET 4.5 and above.
A [Socrata Open Data API](https://dev.socrata.com) (SODA) client library targeting .NET 4.5 and above.

## Getting Started

SODA.NET is available as a [NuGet package](https://www.nuget.org/packages/CSM.SodaDotNet/).

Install-Package CSM.SodaDotNet
```console
dotnet add package CSM.SodaDotNet
```

## Usage examples

Expand Down Expand Up @@ -47,7 +48,7 @@ var results = dataset.Query<MyOtherClass>(soql);

```c#
//make sure to provide auth credentials!
var client =
var client =
new SodaClient("data.smgov.net", "AppToken", "user@domain.com", "password");

//Upsert some data serialized as CSV
Expand All @@ -59,46 +60,152 @@ IEnumerable<MyClass> payload = GetPayloadData();
client.Upsert(payload, "1234-wxyz");
```

Note: This library supports writing directly to datasets with the Socrata Open Data API. For write operations that use
data transformations in the Socrata Data Management Experience (the user interface for creating datasets), use the Socrata
Data Management API. For more details on when to use SODA vs the Socrata Data Management API, see the [Data Management API documentation](https://socratapublishing.docs.apiary.io/#)
**SodaClient** cam also be used for performing Dataset Management API requests

For more details on when to use SODA vs the Socrata Data Management API, see the [Data Management API documentation](https://socratapublishing.docs.apiary.io/#)

Creating datasets:
```c#
using System;
using SODA;
using System.Diagnostics;

namespace SocrataTest
{
class Program
{
static void Main(string[] args)
{
// Initialize the client
SodaClient pipelineClient = new SodaClient("https://{domain}", "{username}", "{password}");

// Read in File (or other source)
string filepath = @"C:\Users\{user}\Desktop\test.csv";
string csv = System.IO.File.ReadAllText(filepath);

// Create a Dataset - either public or private (default: private)
Revision dataset = pipelineClient.CreateDataset("MyNewDataset", "public");

string datasetId = dataset.GetFourFour();
Console.WriteLine(datasetId);

Source source = pipelineClient.CreateSource(csv, dataset, SodaDataFormat.CSV, "File");
SchemaTransforms input = pipelineClient.CreateInputSchema(source);
AppliedTransform output = input.Run();
output.AwaitCompletion(pipelineClient, status => { });

// Check for Errors
if (output.GetErrorCount() > 0)
{
Console.WriteLine(String.Format("ERRORS! {0} row(s) resulted in an error", output.GetErrorCount()));
pipelineClient.ExportErrorRows(@"C:\Users\{user}\Desktop\errors.csv", output);
// Optional Throw new Error...
}

// Apply the revision to the dataset
PipelineJob job = pipelineClient.Apply(output, dataset);

// Await the completion of the revision and output the processing log
job.AwaitCompletion(status => Console.WriteLine(status));

}
}
}
```

Creating update, replace, or delete revisions:
```cs
using System;
using SODA;
using System.Diagnostics;

namespace SocrataTest
{
class Program
{
static void Main(string[] args)
{
// Initialize the client
SodaClient pipelineClient = new SodaClient("https://{domain}", "{username}", "{password}");

// Read in File (or other source)
string filepath = @"C:\Users\{user}\Desktop\test.csv";
string csv = System.IO.File.ReadAllText(filepath);

// CREATING A REVISION
// Create a Revision (either update, replace, or delete)
Revision revision = pipelineClient.CreateRevision("update", "1234-abcd");

// Upload the file as a new source
Source newSource = pipelineClient.CreateSource(csv, revision, SodaDataFormat.CSV, "MyNewFile");
//Console.WriteLine(source.GetSchemaId());
// Get the schema of the new (latest) source
SchemaTransforms newInput = pipelineClient.CreateInputSchema(newSource);

// Run the output transforms
AppliedTransform newOutput = newInput.Run();

// Transforms are applied asynchronously, so we need to wait for them to complete
newOutput.AwaitCompletion(pipelineClient, status => { });

// Check for Errors
if(output.GetErrorCount() > 0)
{
Console.WriteLine(String.Format("ERRORS! {0} row(s) resulted in an error", output.GetErrorCount()));
pipelineClient.ExportErrorRows(@"C:\Users\{user}\Desktop\errors.csv", output);
// Optional Throw new Error...
}

// Apply the revision to replace/update the dataset
PipelineJob newJob = pipelineClient.Apply(newOutput, revision);

// Await the completion of the revision and output the processing log
newJob.AwaitCompletion(status => Console.WriteLine(status) );

}
}
}

```

## Build

Compilation can be done using
[Visual Studio Community Edition](https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx).

[NUnit](http://nunit.org/) was used to build and run the test projects. Check out the
[NUnit Test Adapter](https://visualstudiogallery.msdn.microsoft.com/6ab922d0-21c0-4f06-ab5f-4ecd1fe7175d)
to run tests from within Visual Studio.
You can also use the .NET CLI:

You can also use the `build.cmd` script, which assumes `msbuild` and `nuget` are available:
```console
git clone git@github.com:CityofSantaMonica/SODA.NET.git SODA.NET
cd SODA.NET
dotnet build
```

git clone git@github.com:CityofSantaMonica/SODA.NET.git SODA.NET
cd SODA.NET
.\build.cmd
## Tests

To create the Nuget package artifacts, pass an extra parameter:
[NUnit](http://nunit.org/) was used to build and run the test projects.

.\build.cmd CreatePackages
Run tests from the Visual Studio Test Explorer, or using the .NET CLI:

```console
dotnet test
```

## Contributing

Check out the
[Contributor Guidelines](https://github.com/CityOfSantaMonica/SODA.NET/blob/master/CONTRIBUTING.md)
Check out the [Contributor Guidelines](https://github.com/CityOfSantaMonica/SODA.NET/blob/master/CONTRIBUTING.md)
for more details.

## Copyright and License

Copyright 2017 City of Santa Monica, CA
Copyright 2019 City of Santa Monica, CA

Licensed under the
[MIT License](https://github.com/CityOfSantaMonica/SODA.NET/blob/master/LICENSE.txt)
Licensed under the [MIT License](https://github.com/CityOfSantaMonica/SODA.NET/blob/master/LICENSE.txt)

## Thank you

A tremendous amount of inspiration for this project came from the following projects. Thank you!

- [Octokit.net](https://github.com/octokit/octokit.net)
- [soda-java](https://github.com/socrata/soda-java/)
- [soda-dotnet](https://github.com/socrata/soda-dotnet) (defunct?)
- [Octokit.net](https://github.com/octokit/octokit.net)
- [soda-java](https://github.com/socrata/soda-java/)
- [soda-dotnet](https://github.com/socrata/soda-dotnet) (defunct?)
Loading