/// <summary> /// Get request for twitter. /// </summary> /// <typeparam name="T">The return type T</typeparam> /// <param name="requestObject">The request object</param> /// <returns>The result represented as an object of type T</returns> public T TwitterGetRequest <T>(RequestUrlObject requestObject) where T : new() //Needed such that a new instance of an object can be made { T res = default(T); // First set it to its default //Then if it is a list (IEnumerable), then it creates a new instance of it. //Such that it is not null if (typeof(IEnumerable).IsAssignableFrom(typeof(T))) { res = new T(); } //Such that if it fails to get an result or deserialize it just is null T tempRes = default(T); try { string data = TwitterGetRequest(requestObject); tempRes = JsonConvert.DeserializeObject <T>(data); } catch (JsonException e) { Log.Error(e.Message); } if (tempRes != null) { res = tempRes; } return(res); }
/// <summary> /// Get request for twitter. /// </summary> /// <param name="requestObject">The request object</param> /// <returns>A string representation of the result of the request</returns> public string TwitterGetRequest(RequestUrlObject requestObject) { string res = ""; string authHeader = ""; if (auth.Type == AuthObj.AuthType.User) { authHeader = OAuthHelper.Instance.BuildAuthHeader(OAuthHelper.RequestMethod.GET, auth.Name, auth.OAuthToken, auth.OAuthTokenSecret, requestObject.BaseUrl, requestObject.Params); } else if (auth.Type == AuthObj.AuthType.App) { authHeader = auth.APIKey; } GetRequestBody(requestObject, authHeader, ref res); return(res); }
//Private helper method to return the result of an get request private bool GetRequestBody(RequestUrlObject requestObject, object auth, ref string result) { return(GetRequestBody(requestObject.Url, auth, ref result)); }