public void SetStandardHeaders(WebRequest request, IApiConfiguration configuration, ICompanyFileCredentials credentials, OAuthTokens oauth = null)
 {
     request.Headers[HttpRequestHeader.Authorization] = string.Format("Bearer {0}", oauth.Maybe(_ => _.AccessToken, string.Empty));
     request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip";
     request.Headers["x-myobapi-key"] = configuration.ClientId;
     request.Headers["x-myobapi-version"] = "v2";
     request.Headers["x-myobapi-cftoken"] = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", 
         credentials.Maybe(_ => _.Username).Maybe(_ => _, string.Empty), credentials.Maybe(_ => _.Password).Maybe(_ => _, string.Empty))));
 }
Esempio n. 2
0
 public void Get <T>(WebRequest request, Action <HttpStatusCode, T> onComplete, Action <Uri, Exception> onError) where T : class
 {
     SetStandardHeaders(request, _credentials.Maybe(_ => _.Username), _credentials.Maybe(_ => _.Password));
     request.BeginGetResponse(HandleResponseCallback <RequestContext <string, T>, string, T>,
                              new RequestContext <string, T>
     {
         Request    = request,
         OnComplete = (code, s, entity) => onComplete(code, entity),
         OnError    = onError,
     });
 }
Esempio n. 3
0
 public void SetStandardHeaders(WebRequest request, IApiConfiguration configuration, ICompanyFileCredentials credentials, OAuthTokens oauth = null)
 {
     request.Headers[HttpRequestHeader.Authorization]  = string.Format("Bearer {0}", oauth.Maybe(_ => _.AccessToken, string.Empty));
     request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip";
     request.Headers["x-myobapi-key"]     = configuration.ClientId;
     request.Headers["x-myobapi-version"] = "v2";
     request.Headers["x-myobapi-cftoken"] = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}",
                                                                                                        credentials.Maybe(_ => _.Username).Maybe(_ => _, string.Empty), credentials.Maybe(_ => _.Password).Maybe(_ => _, string.Empty))));
 }