public SocialQueryString GetQueryString()
        {
            SocialQueryString qs = new SocialQueryString();

            if (Count > 0)
            {
                qs.Add("count", Count);
            }
            if (MaxTimestamp != null)
            {
                qs.Add("max_timestamp", SocialUtils.GetUnixTimeFromDateTime(MaxTimestamp.Value));
            }
            if (MinTimestamp != null)
            {
                qs.Add("min_timestamp", SocialUtils.GetUnixTimeFromDateTime(MinTimestamp.Value));
            }
            if (MinId != null)
            {
                qs.Add("min_id", MinId);
            }
            if (MaxId != null)
            {
                qs.Add("max_id", MaxId);
            }
            return(qs);
        }
Ejemplo n.º 2
0
        public SocialHttpResponse DoAuthenticatedGetRequest(string url, SocialQueryString query)
        {
            // Throw an exception if the URL is empty
            if (String.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentNullException("url");
            }

            // Append the query string to the URL
            if (query != null && !query.IsEmpty)
            {
                url += (url.Contains("?") ? "&" : "?") + query;
            }

            // Initialize a new HTTP request
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            // GitHub requires a user agent - see https://developer.github.com/v3/#user-agent-required
            request.UserAgent = "Skybrud.Social";

            // Add an authorization header with the access token
            request.Headers.Add("Authorization: token " + AccessToken);

            // Get the HTTP response
            try {
                return(SocialHttpResponse.GetFromWebResponse(request.GetResponse() as HttpWebResponse));
            } catch (WebException ex) {
                if (ex.Status != WebExceptionStatus.ProtocolError)
                {
                    throw;
                }
                return(SocialHttpResponse.GetFromWebResponse(ex.Response as HttpWebResponse));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Makes a signed request to the Twitter API based on the specified parameters.
        /// </summary>
        /// <param name="method">The HTTP method of the request.</param>
        /// <param name="url">The base URL of the request (no query string).</param>
        /// <param name="queryString">The query string.</param>
        public virtual HttpWebResponse DoHttpRequest(string method, string url, SocialQueryString queryString)
        {
            // TODO: Should this method have is own implementation instead of calling another DoHttpRequest method?

            NameValueCollection query = queryString == null ? null : queryString.NameValueCollection;

            return(DoHttpRequest(method, url, query, null));
        }
        public override SocialQueryString GetQueryString()
        {
            SocialQueryString query = base.GetQueryString();

            if (IncludeSummary)
            {
                query.Set("summary", "true");
            }
            return(query);
        }
Ejemplo n.º 5
0
        public SocialQueryString GetQueryString()
        {
            SocialQueryString qs = new SocialQueryString();

            if (Count > 0)
            {
                qs.Add("count", Count);
            }
            return(qs);
        }
        /// <summary>
        /// Gets debug information about the specified access token.
        /// </summary>
        /// <param name="accessToken">The access token to debug.</param>
        /// <returns>The raw JSON response from the API.</returns>
        public SocialHttpResponse DebugToken(string accessToken)
        {
            // Declare the query string
            SocialQueryString query = new SocialQueryString();

            query.Add("input_token", accessToken);

            // Make the call to the API
            return(Client.DoAuthenticatedGetRequest("/debug_token", query));
        }
        /// <summary>
        /// Search for tags by name. Results are ordered first as an exact match, then by popularity. Short tags will be treated as exact matches.
        /// </summary>
        /// <param name="tag">A valid tag name without a leading #. (eg. snowy, nofilter)</param>
        public SocialHttpResponse Search(string tag)
        {
            // Declare the query string
            SocialQueryString qs = new SocialQueryString();

            qs.Add("q", tag);

            // Perform the call to the API
            return(Client.DoAuthenticatedGetRequest("https://api.instagram.com/v1/tags/search/", qs));
        }
Ejemplo n.º 8
0
        public override SocialQueryString GetQueryString()
        {
            SocialQueryString query = base.GetQueryString();

            if (IncludeSummary)
            {
                query.Set("summary", "true");
            }
            // TODO: Implement the "filter" modifier
            return(query);
        }
        public SocialQueryString GetQueryString()
        {
            SocialQueryString qs = new SocialQueryString();

            qs.Add("lat", Latitude);
            qs.Add("lng", Longitude);
            if (Distance > 0)
            {
                qs.Add("distance", Distance);
            }
            return(qs);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Makes a signed POST request to the specified <code>url</code>.
        /// </summary>
        /// <param name="url">The URL to call.</param>
        /// <param name="options">The options for the call to the API.</param>
        /// <returns>Returns an instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns>
        public virtual SocialHttpResponse DoHttpPostRequest(string url, IPostOptions options)
        {
            SocialQueryString query    = (options == null ? null : options.GetQueryString());
            SocialPostData    postData = (options == null ? null : options.GetPostData());

            NameValueCollection nvcQuery    = (query == null ? null : query.NameValueCollection);
            NameValueCollection nvcPostData = (postData == null ? null : postData.ToNameValueCollection());

            // TODO: Converting the POST data to a NameValueCollection will not support multipart data

            return(DoHttpRequest("POST", url, nvcQuery, nvcPostData));
        }
Ejemplo n.º 11
0
        public string Search(string query, TwitterUsersSearchOptions options)
        {
            // Declare the query string
            SocialQueryString qs = new SocialQueryString();

            qs.Set("q", query);
            if (options != null)
            {
                qs.Set("page", options.Page, options.Page > 1);
                qs.Set("count", options.Count, options.Count != 20);
                qs.Set("include_entities", options.IncludeEntities, options.IncludeEntities != true);
            }

            // Make the call to the API
            return(Client.DoHttpRequestAsString("GET", "https://api.twitter.com/1.1/users/search.json", qs.NameValueCollection));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Makes a GET request to the Facebook API. If the <code>AccessToken</code> property has
        /// been specified, the access token will be appended to the query string.
        /// </summary>
        /// <param name="url">The URL to call.</param>
        /// <param name="query">The query string of the request.</param>
        public SocialHttpResponse DoAuthenticatedGetRequest(string url, SocialQueryString query)
        {
            // Throw an exception if the URL is empty
            if (String.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentNullException("url");
            }

            // Append the HTTP scheme and API version if not already specified.
            if (url.StartsWith("/"))
            {
                url = "https://graph.facebook.com" + (String.IsNullOrWhiteSpace(Version) ? "" : "/" + Version) + url;
            }

            // Initialize a new instance of SocialQueryString if the one specified is NULL
            if (query == null)
            {
                query = new SocialQueryString();
            }

            // Append the access token to the query string if present in the client and not already
            // specified in the query string
            if (!query.ContainsKey("access_token") && !String.IsNullOrWhiteSpace(AccessToken))
            {
                query.Add("access_token", AccessToken);
            }

            // Append the query string to the URL
            if (!query.IsEmpty)
            {
                url += (url.Contains("?") ? "&" : "?") + query;
            }

            // Initialize a new HTTP request
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            // Get the HTTP response
            try {
                return(SocialHttpResponse.GetFromWebResponse(request.GetResponse() as HttpWebResponse));
            } catch (WebException ex) {
                if (ex.Status != WebExceptionStatus.ProtocolError)
                {
                    throw;
                }
                return(SocialHttpResponse.GetFromWebResponse(ex.Response as HttpWebResponse));
            }
        }
        public virtual SocialQueryString GetQueryString()
        {
            SocialQueryString query = new SocialQueryString();

            if (Limit != null && Limit.Value >= 0)
            {
                query.Set("limit", Limit.Value);
            }
            if (Since > 0)
            {
                query.Set("since", Since);
            }
            if (Until > 0)
            {
                query.Set("until", Until);
            }
            return(query);
        }
Ejemplo n.º 14
0
        public SocialQueryString GetQueryString()
        {
            SocialQueryString qs = new SocialQueryString();

            if (Count > 0)
            {
                qs.Add("count", Count);
            }
            if (!String.IsNullOrWhiteSpace(MinTagId))
            {
                qs.Add("min_tag_id", MinTagId);
            }
            if (!String.IsNullOrWhiteSpace(MaxTagId))
            {
                qs.Add("max_tag_id", MaxTagId);
            }
            return(qs);
        }
Ejemplo n.º 15
0
        public virtual SocialQueryString GetQueryString()
        {
            SocialQueryString query = new SocialQueryString();

            if (Limit != null && Limit.Value >= 0)
            {
                query.Set("limit", Limit.Value);
            }
            if (Before != null)
            {
                query.Set("before", Before);
            }
            if (After != null)
            {
                query.Set("after", After);
            }
            return(query);
        }
        public SocialQueryString GetQueryString()
        {
            SocialQueryString query = new SocialQueryString();

            if (Count > 0)
            {
                query.Add("count", Count);
            }
            if (MinId != null)
            {
                query.Add("min_id", MinId);
            }
            if (MaxId != null)
            {
                query.Add("max_id", MaxId);
            }
            return(query);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Makes an authenticated GET request to the specified URL. If an access token has been
        /// specified for this client, that access token will be added to the query string.
        /// Similar if a client ID has been specified instead of an access token, that client ID
        /// will be added to the query string. However some endpoint methods may require an access
        /// token, and a client ID will therefore not be sufficient for such methods.
        /// </summary>
        /// <param name="url">The URL to call.</param>
        /// <param name="query">The query string for the call.</param>
        public SocialHttpResponse DoAuthenticatedGetRequest(string url, SocialQueryString query)
        {
            // Throw an exception if the URL is empty
            if (String.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentNullException("url");
            }

            // Initialize a new instance of SocialQueryString if the one specified is NULL
            if (query == null)
            {
                query = new SocialQueryString();
            }

            // Append either the access token or the client ID to the query string
            if (!String.IsNullOrWhiteSpace(AccessToken))
            {
                query.Add("access_token", AccessToken);
            }
            else if (!String.IsNullOrWhiteSpace(ClientId))
            {
                query.Add("client_id", ClientId);
            }

            // Append the query string to the URL
            if (!query.IsEmpty)
            {
                url += (url.Contains("?") ? "&" : "?") + query;
            }

            // Initialize a new HTTP request
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            // Get the HTTP response
            try {
                return(SocialHttpResponse.GetFromWebResponse(request.GetResponse() as HttpWebResponse));
            } catch (WebException ex) {
                if (ex.Status != WebExceptionStatus.ProtocolError)
                {
                    throw;
                }
                return(SocialHttpResponse.GetFromWebResponse(ex.Response as HttpWebResponse));
            }
        }
        public SocialQueryString GetQueryString()
        {
            // Declare the query string
            SocialQueryString qs = new SocialQueryString();

            qs.Add("lat", Latitude);
            qs.Add("lng", Longitude);

            // Optinal options
            if (Distance > 0)
            {
                qs.Add("distance", Distance);
            }
            if (MinTimestamp > 0)
            {
                qs.Add("min_timestamp", MinTimestamp);
            }
            if (MaxTimestamp > 0)
            {
                qs.Add("max_timestamp", MaxTimestamp);
            }

            return(qs);
        }
        public SocialQueryString GetQuery()
        {
            string resultType = ResultType.ToString().ToLower();

            SocialQueryString query = new SocialQueryString();

            if (!String.IsNullOrWhiteSpace(Query))
            {
                query.Set("q", Query);
            }
            if (resultType != "mixed")
            {
                query.Set("result_type", resultType);
            }
            if (Count > 0)
            {
                query.Set("count", Count);
            }
            if (Until != null)
            {
                query.Set("until", Until.Value.ToString("yyyy-MM-dd"));
            }
            if (SinceId > 0)
            {
                query.Set("since_id", SinceId);
            }
            if (MaxId > 0)
            {
                query.Set("max_id", MaxId);
            }
            if (!IncludeEntities)
            {
                query.Set("include_entities", "false");
            }
            return(query);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Makes a POST request to the Facebook API. If the <code>AccessToken</code> property has
        /// been specified, the access token will be appended to the query string.
        /// </summary>
        /// <param name="url">The URL to call.</param>
        /// <param name="query">The query string of the request.</param>
        /// <param name="postData">The POST data.</param>
        /// <param name="isMultipart">If <code>TRUE</code>, the content type of the request will be <code>multipart/form-data</code>, otherwise <code>application/x-www-form-urlencoded</code>.</param>
        public SocialHttpResponse DoAuthenticatedPostRequest(string url, SocialQueryString query, SocialPostData postData, bool isMultipart)
        {
            // Throw an exception if the URL is empty
            if (String.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentNullException("url");
            }

            // Append the HTTP scheme and API version if not already specified.
            if (url.StartsWith("/"))
            {
                url = "https://graph.facebook.com" + (String.IsNullOrWhiteSpace(Version) ? "" : "/" + Version) + url;
            }

            // Initialize a new instance of SocialQueryString if the one specified is NULL
            if (query == null)
            {
                query = new SocialQueryString();
            }

            // Append the access token to the query string if present in the client and not already
            // specified in the query string
            if (!query.ContainsKey("access_token") && !String.IsNullOrWhiteSpace(AccessToken))
            {
                query.Add("access_token", AccessToken);
            }

            // Append the query string to the URL
            if (!query.IsEmpty)
            {
                url += (url.Contains("?") ? "&" : "?") + query;
            }

            // Initialize a new HTTP request
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            // Set the HTTP method
            request.Method = "POST";

            // Write the POST data to the request stream
            if (postData != null && postData.Count > 0)
            {
                if (isMultipart)
                {
                    string boundary = Guid.NewGuid().ToString().Replace("-", "");
                    request.ContentType = "multipart/form-data; boundary=" + boundary;
                    using (Stream stream = request.GetRequestStream()) {
                        postData.WriteMultipartFormData(stream, boundary);
                    }
                }
                else
                {
                    string dataString = postData.ToString();
                    request.ContentType   = "application/x-www-form-urlencoded";
                    request.ContentLength = dataString.Length;
                    using (Stream stream = request.GetRequestStream()) {
                        stream.Write(Encoding.UTF8.GetBytes(dataString), 0, dataString.Length);
                    }
                }
            }

            // Get the HTTP response
            try {
                return(SocialHttpResponse.GetFromWebResponse(request.GetResponse() as HttpWebResponse));
            } catch (WebException ex) {
                if (ex.Status != WebExceptionStatus.ProtocolError)
                {
                    throw;
                }
                return(SocialHttpResponse.GetFromWebResponse(ex.Response as HttpWebResponse));
            }
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Makes a signed GET request to the specified <code>url</code>.
 /// </summary>
 /// <param name="url">The URL to call.</param>
 /// <param name="query">The query string.</param>
 /// <returns>Returns an instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns>
 public virtual SocialHttpResponse DoHttpGetRequest(string url, SocialQueryString query)
 {
     return(DoHttpRequest("GET", url, query == null ? null : query.NameValueCollection, null));
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Makes a signed request to the Twitter API based on the specified parameters.
        /// </summary>
        /// <param name="method">The HTTP method of the request.</param>
        /// <param name="url">The base URL of the request (no query string).</param>
        /// <param name="options">The options for the call to the API.</param>
        public virtual HttpWebResponse DoHttpRequest(string method, string url, IGetOptions options)
        {
            SocialQueryString queryString = options == null ? null : options.GetQueryString();

            return(DoHttpRequest(method, url, queryString));
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Makes a signed request to the underlying API based on the specified parameters.
        /// </summary>
        /// <param name="method">The HTTP method of the request.</param>
        /// <param name="url">The base URL of the request (no query string).</param>
        /// <param name="queryString">The query string.</param>
        /// <returns>Returns an instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns>
        public virtual SocialHttpResponse DoHttpRequest(string method, string url, SocialQueryString queryString)
        {
            NameValueCollection query = queryString == null ? null : queryString.NameValueCollection;

            return(DoHttpRequest(method, url, query, null));
        }