Created
September 26, 2011 09:25
-
-
Save edstenson/1241924 to your computer and use it in GitHub Desktop.
C# demo code for REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading; | |
| using Datasift.DatasiftStream; | |
| using Datasift.Interfaces; | |
| using Datasift; | |
| using Datasift.Api; | |
| using Datasift; | |
| using Datasift.Api; | |
| namespace DataSiftDemo | |
| { | |
| class ApiDemo | |
| { | |
| private ApiDemo() | |
| { | |
| //the configuration for this request | |
| Config config = new Config(Config.ConfigType.API, "Ed_S", "dcc088786009c7da28559119d3b2976b"); | |
| //create an API request object | |
| DatasiftApiRequest request = new DatasiftApiRequest(config); | |
| //send a CSDL to be compiled and get the response | |
| DatasiftApiResponse response = request.Compile("interaction.content contains \"google\""); | |
| Console.WriteLine("Compiled and got hash :" + response.Hash); | |
| //make a new request, getting some interactions for the csdl we just compiled | |
| //to get all available interactions | |
| string hash = response.Hash; | |
| //get a single interaction, using the third param to set the count | |
| response = request.Stream(hash, null, 1); | |
| //buffering usually starts on the first request so if we didn't get anything back wait and try again | |
| while (response.Stream.Count == 0) | |
| { | |
| Console.WriteLine("Nothing returned from the buffered stream sleeping for 5 seconds..."); | |
| Thread.Sleep(5000);//wait 5 seconds | |
| response = request.Stream(hash, null, 1); | |
| } | |
| Console.WriteLine("Number of interactions returned : " + response.Stream.Count + "\n\n"); | |
| Console.WriteLine("Stream response objects\n"); | |
| foreach (Interaction i in response.Stream) | |
| { | |
| Console.WriteLine(i.ToString()); | |
| } | |
| Console.WriteLine("Stream response objects end\n\n"); | |
| //now see the costs for this stream | |
| response = request.Cost(hash); | |
| Console.WriteLine("\nCosts : " + response.StreamCosts + "\n"); | |
| } | |
| static void Main(string[] args) | |
| { | |
| ApiDemo p = new ApiDemo(); | |
| //prevent console from closing until it recieves an input...just so we can look at any output made | |
| Console.ReadLine(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment