public GitHubRequestAsyncHandle(GitHubRequest request, RestRequestAsyncHandle handle) { Requires.ArgumentNotNull(request, "request"); Requires.ArgumentNotNull(handle, "handle"); _request = request; _handle = handle; }
public GitHubRequestAsyncHandle CallApiAsync <TResponseData>( GitHubRequest request, Action <IGitHubResponse <TResponseData> > callback, Action <GitHubException> onError) where TResponseData : new() { return(CallApiAsync <IGitHubResponse <TResponseData>, IRestResponse <TResponseData> >( request, r => new GitHubResponse <TResponseData>(r), (client, req, processResponse) => client.ExecuteAsync <TResponseData>(req, processResponse), callback, onError)); }
public GitHubRequestAsyncHandle CallApiAsync( GitHubRequest request, Action <IGitHubResponse> callback, Action <GitHubException> onError) { return(CallApiAsync <IGitHubResponse, IRestResponse>( request, r => new GitHubResponse(r), (client, req, processResponse) => client.ExecuteAsync(req, processResponse), callback, onError)); }
private GitHubRequestAsyncHandle CallApiAsync <TGitHubResponse, TRestResponse>( GitHubRequest request, Func <TRestResponse, TGitHubResponse> responseFactory, Func <IRestClient, IRestRequest, Action <TRestResponse, RestRequestAsyncHandle>, RestRequestAsyncHandle> restClientExecFunc, Action <TGitHubResponse> callback, Action <GitHubException> onError) where TGitHubResponse : IGitHubResponse where TRestResponse : IRestResponse { Requires.ArgumentNotNull(request, "request"); Requires.ArgumentNotNull(callback, "callback"); Requires.ArgumentNotNull(onError, "onError"); var restRequest = new RestRequest { Resource = request.Resource, Method = request.Method.ToRestSharpMethod(), RequestFormat = DataFormat.Json, JsonSerializer = new JsonSerializer() }; foreach (var p in request.Parameters) { restRequest.AddParameter(p.Name, p.Value); } #if WINDOWS_PHONE if (restRequest.Method == RestSharp.Method.GET) { // The implementation of HttpWebRequest in WP7 automatically caches all // all responses. Therefore, we add a query param with a unique value // to each request to ensure that we always GET fresh data. // see http://bit.ly/e3JNzE restRequest.AddParameter("ngithub_wp7_nocache", DateTime.UtcNow.Ticks); } #endif if (request.Body != null) { restRequest.AddBody(request.Body); } var baseUrl = (request.Version == API.v3) ? Constants.ApiV3Url : Constants.ApiV2Url; var restClient = _factory.CreateRestClient(baseUrl); restClient.Authenticator = Authenticator; var handle = restClientExecFunc( restClient, restRequest, (r, h) => { var response = responseFactory(r); GitHubException ex = null; if (_processor.TryProcessResponseErrors(response, out ex)) { onError(ex); return; } callback(response); }); return(new GitHubRequestAsyncHandle(request, handle)); }