项目作者: CityofSantaMonica

项目描述 :
A Socrata Open Data API (SODA) client library for .NET
高级语言: C#
项目地址: git://github.com/CityofSantaMonica/SODA.NET.git
创建时间: 2014-08-28T21:29:31Z
项目社区:https://github.com/CityofSantaMonica/SODA.NET

开源协议:MIT License

下载


SODA.NET Build status

A Socrata Open Data API (SODA) client library targeting .NET 4.5 and above.

Getting Started

SODA.NET is available as a NuGet package.

  1. dotnet add package CSM.SodaDotNet

Usage examples

Simple, read-only access

  1. //initialize a new client
  2. //make sure you register for your own app token (http://dev.socrata.com/register)
  3. var client = new SodaClient("data.smgov.net", "REPLACE_WITH_YOUR_APP_TOKEN");
  4. //read metadata of a dataset using the resource identifier (Socrata 4x4)
  5. var metadata = client.GetMetadata("1234-wxyz");
  6. Console.WriteLine("{0} has {1} views.", metadata.Name, metadata.ViewsCount);
  7. //get a reference to the resource itself
  8. //the result (a Resouce object) is a generic type
  9. //the type parameter represents the underlying rows of the resource
  10. var dataset = client.GetResource<Dictionary<string, object>>("1234-wxyz");
  11. //of course, a custom type can be used as long as it is JSON serializable
  12. var dataset = client.GetResource<MyClass>("1234-wxyz");
  13. //Resource objects read their own data
  14. var allRows = dataset.GetRows();
  15. var first10Rows = dataset.GetRows(10);
  16. //collections of an arbitrary type can be returned
  17. //using SoQL and a fluent query building syntax
  18. var soql = new SoqlQuery().Select("column1", "column2")
  19. .Where("something > nothing")
  20. .Group("column3");
  21. var results = dataset.Query<MyOtherClass>(soql);

SodaClient is also capable of performing write operations

  1. //make sure to provide auth credentials!
  2. var client =
  3. new SodaClient("data.smgov.net", "AppToken", "user@domain.com", "password");
  4. //Upsert some data serialized as CSV
  5. string csvData = File.ReadAllText("data.csv");
  6. client.Upsert(csvData, SodaDataFormat.CSV, "1234-wxyz");
  7. //Upsert a collection of serializable entities
  8. IEnumerable<MyClass> payload = GetPayloadData();
  9. 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

Build

Compilation can be done using
Visual Studio Community Edition.

You can also use the .NET CLI:

  1. git clone git@github.com:CityofSantaMonica/SODA.NET.git SODA.NET
  2. cd SODA.NET
  3. dotnet build

Tests

NUnit was used to build and run the test projects.

Run tests from the Visual Studio Test Explorer, or using the .NET CLI:

  1. dotnet test

Contributing

Check out the Contributor Guidelines
for more details.

Copyright 2019 City of Santa Monica, CA

Licensed under the MIT License

Thank you

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