public void retrieveMetadataForFile() { Dictionary <String, Link> linksFromFirstFile = OAuthWorkFlow.linksFrom(files.page[3]); firstFileSelfUri = linksFromFirstFile["self"].uri; Hammock.Authentication.OAuth.OAuthCredentials credentials = OAuthWorkFlow.createOAuthCredentials(OAuthType.ProtectedResource, ApiCredentials.TOKEN.token, ApiCredentials.TOKEN.secret, null, null); Hammock.RestClient client = new Hammock.RestClient() { Authority = "", Credentials = credentials }; Hammock.RestRequest request = new Hammock.RestRequest() { Path = firstFileSelfUri }; request.AddHeader("Accept", "application/vnd.deere.axiom.v3+json"); Hammock.RestResponse response = client.Request(request); SampleApp.Sources.generated.v3.File firstFileDetails = Deserialise <SampleApp.Sources.generated.v3.File>(response.ContentStream); filename = firstFileDetails.name; }
public void retrieveApiCatalog() { Hammock.Authentication.OAuth.OAuthCredentials credentials = OAuthWorkFlow.createOAuthCredentials(OAuthType.ProtectedResource, ApiCredentials.TOKEN.token, ApiCredentials.TOKEN.secret, null, null); Hammock.RestClient client = new Hammock.RestClient() { Authority = "", Credentials = credentials }; Hammock.RestRequest request = new Hammock.RestRequest() { Path = "https://apicert.soa-proxy.deere.com/platform/" }; request.AddHeader("Accept", "application/vnd.deere.axiom.v3+json"); Hammock.RestResponse response = client.Request(request); ApiCatalog apiCatalog = Deserialise <ApiCatalog>(response.ContentStream); links = OAuthWorkFlow.linksFrom(apiCatalog); getFiles(); retrieveMetadataForFile(); downloadFileContentsAndComputeMd5(); downloadFileInPiecesAndComputeMd5(); }
public void getFiles() { Hammock.Authentication.OAuth.OAuthCredentials credentials = OAuthWorkFlow.createOAuthCredentials(OAuthType.ProtectedResource, ApiCredentials.TOKEN.token, ApiCredentials.TOKEN.secret, null, null); Hammock.RestClient client = new Hammock.RestClient() { Authority = "", Credentials = credentials }; Hammock.RestRequest request = new Hammock.RestRequest() { Path = links["files"].uri }; request.AddHeader("Accept", "application/vnd.deere.axiom.v3+json"); Hammock.RestResponse response = client.Request(request); CollectionPageDeserializer ds = new CollectionPageDeserializer(); files = ds.deserialize <SampleApp.Sources.generated.v3.File>(response.Content); Console.WriteLine("done"); }
private int makeHeadRequestToGetFileSize() { Hammock.Authentication.OAuth.OAuthCredentials credentials = OAuthWorkFlow.createOAuthCredentials(OAuthType.ProtectedResource, ApiCredentials.TOKEN.token, ApiCredentials.TOKEN.secret, null, null); Hammock.RestClient client = new Hammock.RestClient() { Authority = "", Credentials = credentials }; Hammock.RestRequest request = new Hammock.RestRequest() { Path = firstFileSelfUri, Method = WebMethod.Head }; request.AddHeader("Accept", "application/zip"); Hammock.RestResponse response = client.Request(request); /*if (!hasResponseCode(OK).matches(headRes)) { * firstFileSelfUri = null; * //fail(format("HEAD request to %s returned bad response code", firstFileSelfUri)); * }*/ //checkThat("Content-Length header", headRes.getHeaderFields().contains("Content-Length"), isTrue()); return(Convert.ToInt32(response.Headers["Content-Length"])); //return Integer.valueOf(headRes.getHeaderFields().valueOf("Content-Length")); }
public void retrieveFleetDetails() { OAuthCredentials credentials = OAuthWorkFlow.createOAuthCredentials(OAuthType.ProtectedResource, ApiCredentials.TOKEN.token, ApiCredentials.TOKEN.secret, null, null); Hammock.RestClient client = new Hammock.RestClient() { Authority = "", Credentials = credentials }; Hammock.RestRequest request = new Hammock.RestRequest() { Path = BASE_URI + "Fleet" }; request.AddHeader("Accept", "application/xml"); Hammock.RestResponse response = client.Request(request); request.Path = BASE_URI + response.Headers.Get("Location"); System.Diagnostics.Debug.WriteLine(""); makeRecursiveApiCallTillLastPageOfApiResponse(request, credentials, client); }
public void downloadFileContentsAndComputeMd5() { Hammock.Authentication.OAuth.OAuthCredentials credentials = OAuthWorkFlow.createOAuthCredentials(OAuthType.ProtectedResource, ApiCredentials.TOKEN.token, ApiCredentials.TOKEN.secret, null, null); Hammock.RestClient client = new Hammock.RestClient() { Authority = "", Credentials = credentials }; Hammock.RestRequest request = new Hammock.RestRequest() { Path = firstFileSelfUri }; request.AddHeader("Accept", "application/zip"); Hammock.RestResponse response = client.Request(request); checkFilenameInContentDispositionHeader(response); using (var md5 = MD5.Create()) { using (var stream = response.ContentStream) { md5FromSinglePieceDownload = md5.ComputeHash(stream); } } }
private Hammock.RestClient getRestClient() { Hammock.Authentication.OAuth.OAuthCredentials credentials = OAuthWorkFlow.createOAuthCredentials(OAuthType.ProtectedResource, ApiCredentials.TOKEN.token, ApiCredentials.TOKEN.secret, null, null); Hammock.RestClient client = new Hammock.RestClient() { Authority = "", Credentials = credentials }; return(client); }
public void getCurrentUser() { Hammock.RestClient client = getRestClient(); Hammock.RestRequest request = new Hammock.RestRequest() { Path = links["currentUser"].uri }; request.AddHeader("Accept", "application/vnd.deere.axiom.v3+json"); Hammock.RestResponse response = client.Request(request); Resource currentUser = Download.Deserialise <User>(response.ContentStream); userOrganizations = OAuthWorkFlow.linksFrom(currentUser)["organizations"].uri; }
private void getChunkFromStartAndRecurse(int start, int chunkSize, int fileSize //,DigestOutputStream byteDigest ) { int maxRange = fileSize - 1; int end = Math.Min(start + chunkSize, maxRange); Hammock.Authentication.OAuth.OAuthCredentials credentials = OAuthWorkFlow.createOAuthCredentials(OAuthType.ProtectedResource, ApiCredentials.TOKEN.token, ApiCredentials.TOKEN.secret, null, null); Hammock.RestClient client = new Hammock.RestClient() { Authority = "", Credentials = credentials }; Hammock.RestRequest request = new Hammock.RestRequest() { Path = firstFileSelfUri, Method = WebMethod.Get }; request.AddHeader("Accept", "application/zip"); request.AddHeader("Range", "bytes=" + start + "-" + end); Hammock.RestResponse response = client.Request(request); using (var md5 = MD5.Create()) { using (var stream = response.ContentStream) { md5FromMultiplePieceDownload = md5.ComputeHash(stream); } } checkFilenameInContentDispositionHeader(response); // copy(rangeResponse.getBody(), byteDigest); if (start + chunkSize < maxRange) { getChunkFromStartAndRecurse(start + chunkSize + 1, chunkSize, fileSize); } }
static void Main(string[] args) { SampleApp.Sources.democlient.OAuthWorkFlow of = new SampleApp.Sources.democlient.OAuthWorkFlow(); /* For Oauth tokens please un-comment line 1 to line 4 also please plugin your App Id and Secret from https://developer.deere.com app profile in ApiCredentials.cs CLIENT constructor * Once access tokens are generated please plug te valus into ApiCredentials.cs OAuthToken constructor * * To run the file download example, please comment out Line 1 to Line 4 and un-comment Line 5 * To run the file download example, please comment out Line 1 to Line 5 and un-comment Line 6 */ of.retrieveApiCatalogToEstablishOAuthProviderDetails(); //Line 1 of.getRequestToken(); //Line 2 of.authorizeRequestToken(); //Line 3 of.exchangeRequestTokenForAccessToken(); //Line 4 //Download dn = new Download(); //Line 5 //Upload up = new Upload(); //Line 6 //dn.retrieveApiCatalog(); //Line 7 }
public void getUserOrganizations() { Hammock.RestClient client = getRestClient(); Hammock.RestRequest request = new Hammock.RestRequest() { Path = userOrganizations }; request.AddHeader("Accept", "application/vnd.deere.axiom.v3+json"); Hammock.RestResponse response = client.Request(request); CollectionPageDeserializer ds = new CollectionPageDeserializer(); CollectionPage <Organization> organizations = ds.deserialize <SampleApp.Sources.generated.v3.Organization>(response.Content); Dictionary <String, Link> linksFromFirst = OAuthWorkFlow.linksFrom(organizations.page[0]); fileUploadLink = linksFromFirst["uploadFile"]; }
public void retrieveApiCatalog() { Hammock.RestClient client = getRestClient(); Hammock.RestRequest request = new Hammock.RestRequest() { Path = "https://apicert.soa-proxy.deere.com/platform/" }; request.AddHeader("Accept", "application/vnd.deere.axiom.v3+json"); Hammock.RestResponse response = client.Request(request); ApiCatalog apiCatalog = Download.Deserialise <ApiCatalog>(response.ContentStream); links = OAuthWorkFlow.linksFrom(apiCatalog); getCurrentUser(); getUserOrganizations(); addFile(); uploadFile(); deleteUploadedFile(); }