Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
 //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));
 }