/// <summary> /// Gets the account info of the current logged in user /// </summary> /// <returns></returns> public async Task<AccountInfo> AccountInfo() { var requestUrl = MakeRequestString("1/account/info", ApiType.Base); var request = new HttpRequest(HttpMethod.Get, requestUrl); var response = await SendAsync<AccountInfo>(request); return response; }
/// <summary> /// Auth Step 3. Once a Request Token has been authorized convert it to an access token for API usage. /// </summary> /// <returns></returns> public async Task<UserLogin> GetAccessToken() { var requestUrl = MakeRequestString("1/oauth/access_token", ApiType.Base); var request = new HttpRequest(HttpMethod.Get, requestUrl); _oauthHandler.Authenticate(request); var response = await _httpClient.SendAsync(request); string responseBody = await response.Content.ReadAsStringAsync(); UserLogin = GetUserLoginFromParams(responseBody); SetUserToken(UserLogin); return UserLogin; }
/// <summary> /// Builds up the oauth parameters and updated the request Uri /// </summary> /// <param name="request"></param> /// <returns></returns> public HttpRequest Authenticate(HttpRequest request) { request.AddParameter("oauth_version", "1.0"); request.AddParameter("oauth_nonce", GenerateNonce()); request.AddParameter("oauth_timestamp", GenerateTimeStamp()); request.AddParameter("oauth_signature_method", SignatureMethod); request.AddParameter("oauth_consumer_key", ApiKey); if (!string.IsNullOrEmpty(UserToken)) { request.AddParameter("oauth_token", UserToken); } request.Parameters.Sort(new QueryParameterComparer()); request.AddParameter("oauth_signature", GenerateSignature(request)); //Now build the real Url var data = EncodeParameters(request); var url = string.Format("{0}?{1}", request.RequestUri, data); request.RequestUri = new Uri(url); //Does it need to do this? return request; }
private string GenerateSignature(HttpRequest request) { return ApiSecret + "&" + UserSecret; }
private static object EncodeParameters(HttpRequest request) { var querystring = new StringBuilder(); foreach (var p in request.Parameters) { if (querystring.Length > 1) { querystring.Append("&"); } querystring.AppendFormat("{0}={1}", p.Name.UrlEncode(), (p.Value.ToString()).UrlEncode()); } return querystring.ToString(); }