Ejemplo n.º 1
0
        /// <summary>
        /// Gets an authorization URL using the specified <paramref name="state"/> and request the specified
        /// <paramref name="scope"/>.
        /// </summary>
        /// <param name="state">A unique state for the request.</param>
        /// <param name="scope">The scope of your application.</param>
        /// <returns>The authorization URL.</returns>
        public virtual string GetAuthorizationUrl(string state, params string[] scope)
        {
            // Some validation
            if (String.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException("ClientId");
            }
            if (String.IsNullOrWhiteSpace(RedirectUri))
            {
                throw new PropertyNotSetException("RedirectUri");
            }

            // Do we have a valid "state" ?
            if (String.IsNullOrWhiteSpace(state))
            {
                throw new ArgumentNullException("state", "A valid state should be specified as it is part of the security of OAuth 2.0.");
            }

            // Construct the query string
            IHttpQueryString query = new SocialHttpQueryString();

            query.Add("client_id", ClientId);
            query.Add("redirect_uri", RedirectUri);
            query.Add("response_type", "code");
            query.Add("state", state);

            // Append the scope (if specified)
            if (scope != null && scope.Length > 0)
            {
                query.Add("scope", String.Join(" ", scope));
            }

            // Construct the authorization URL
            return("https://api.instagram.com/oauth/authorize/?" + query.ToString());
        }
        /// <summary>
        /// Generates the authorization URL using the specified <paramref name="state"/> and <paramref name="scope"/>.
        /// </summary>
        /// <param name="state">The state to send to the Spotify OAuth login page.</param>
        /// <param name="scope">The scope of the application.</param>
        /// <returns>An authorization URL based on <paramref name="state"/> and <paramref name="scope"/>.</returns>
        public string GetAuthorizationUrl(string state, params string[] scope)
        {
            // Input validation
            if (String.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException(nameof(ClientId));
            }
            if (String.IsNullOrWhiteSpace(RedirectUri))
            {
                throw new PropertyNotSetException(nameof(RedirectUri));
            }

            // Do we have a valid "state" ?
            if (String.IsNullOrWhiteSpace(state))
            {
                throw new ArgumentNullException(nameof(state), "A valid state should be specified as it is part of the security of OAuth 2.0.");
            }

            // Construct the query string
            IHttpQueryString query = new SocialHttpQueryString();

            query.Add("client_id", ClientId);
            query.Add("response_type", "code");
            query.Add("redirect_uri", RedirectUri);
            query.Add("state", state);
            query.Add("scope", String.Join(" ", scope ?? new string[0]));

            // Construct the authorization URL
            return("https://accounts.spotify.com/authorize?" + query);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            SocialHttpQueryString qs = new SocialHttpQueryString();

            if (Count > 0)
            {
                qs.Add("count", Count);
            }
            if (MaxTimestamp != null)
            {
                qs.Add("max_timestamp", MaxTimestamp.UnixTimestamp);
            }
            if (MinTimestamp != null)
            {
                qs.Add("min_timestamp", MinTimestamp.UnixTimestamp);
            }
            if (MinId != null)
            {
                qs.Add("min_id", MinId);
            }
            if (MaxId != null)
            {
                qs.Add("max_id", MaxId);
            }
            return(qs);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Generates the authorization URL using the specified <paramref name="state"/> and <paramref name="scope"/>.
        /// </summary>
        /// <param name="state">The state to send to Vimeo's OAuth login page.</param>
        /// <param name="scope">The scope of the application.</param>
        /// <returns>An authorization URL based on <see cref="ClientId"/>, <see cref="RedirectUri"/>,
        /// <paramref name="state"/> and <paramref name="scope"/>.</returns>
        public string GetAuthorizationUrl(string state, string scope = null)
        {
            // Validate the input
            if (String.IsNullOrWhiteSpace(state))
            {
                throw new ArgumentNullException(nameof(state));
            }
            if (String.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException(nameof(ClientId));
            }
            if (String.IsNullOrWhiteSpace(RedirectUri))
            {
                throw new PropertyNotSetException(nameof(RedirectUri));
            }

            // Construct the query string
            IHttpQueryString query = new SocialHttpQueryString();

            query.Add("response_type", "code");
            query.Add("client_id", ClientId);
            query.Add("redirect_uri", RedirectUri);
            query.Add("scope", scope + "");
            query.Add("state", state);

            // Construct the full URL
            return("https://api.vimeo.com/oauth/authorize?" + query);
        }
        /// <summary>
        /// Gets an app access token for for the application. The <see cref="ClientId"/> and <see cref="ClientSecret"/>
        /// properties must be specified for the OAuth client.
        /// </summary>
        /// <returns>Returns an instance of <see cref="FacebookTokenResponse"/> representing the response.</returns>
        public FacebookTokenResponse GetAppAccessToken()
        {
            // Some validation
            if (String.IsNullOrWhiteSpace(Version))
            {
                throw new PropertyNotSetException("Version");
            }
            if (String.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException("ClientId");
            }
            if (String.IsNullOrWhiteSpace(ClientSecret))
            {
                throw new PropertyNotSetException("ClientSecret");
            }

            // Initialize the query string
            IHttpQueryString query = new SocialHttpQueryString();

            query.Add("client_id", ClientId);
            query.Add("client_secret", ClientSecret);
            query.Add("grant_type", "client_credentials");

            // Make the call to the API
            SocialHttpResponse response = SocialUtils.Http.DoHttpGetRequest("https://graph.facebook.com/" + Version + "/oauth/access_token", query);

            // Parse the response
            return(FacebookTokenResponse.ParseResponse(response));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        /// <returns>An instance of <see cref="IHttpQueryString"/>.</returns>
        public IHttpQueryString GetQueryString()
        {
            if (Id == 0)
            {
                throw new PropertyNotSetException(nameof(Id));
            }

            SocialHttpQueryString query = new SocialHttpQueryString();

            query.Set("id", Id);
            if (TrimUser)
            {
                query.Add("trim_user", "true");
            }
            if (IncludeMyRetweet)
            {
                query.Add("include_my_retweet", "true");
            }
            if (IncludeEntities)
            {
                query.Add("include_entities", "true");
            }
            if (TweetMode != TwitterTweetMode.Compatibility)
            {
                query.Add("tweet_mode", StringUtils.ToCamelCase(TweetMode));
            }
            return(query);
        }
Ejemplo n.º 7
0
        public IHttpQueryString GetQueryString()
        {
            IHttpQueryString query = new SocialHttpQueryString();

            query.Add("state", State ? "true" : "false");
            if (!String.IsNullOrWhiteSpace(DeviceId))
            {
                query.Add("device_id", DeviceId);
            }
            return(query);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            SocialHttpQueryString qs = new SocialHttpQueryString();

            qs.Add("q", Query);
            if (Count > 0)
            {
                qs.Add("count", Count);
            }
            return(qs);
        }
Ejemplo n.º 9
0
        public IHttpQueryString GetQueryString()
        {
            IHttpQueryString query = new SocialHttpQueryString();

            query.Add("position", Position.TotalMilliseconds);
            if (!String.IsNullOrWhiteSpace(DeviceId))
            {
                query.Add("device_id", DeviceId);
            }
            return(query);
        }
Ejemplo n.º 10
0
        public IHttpQueryString GetQueryString()
        {
            IHttpQueryString query = new SocialHttpQueryString();

            query.Add("state", StringUtils.ToLower(State));
            if (!String.IsNullOrWhiteSpace(DeviceId))
            {
                query.Add("device_id", DeviceId);
            }
            return(query);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            SocialHttpQueryString qs = new SocialHttpQueryString();

            qs.Add("lat", Latitude);
            qs.Add("lng", Longitude);
            if (Distance > 0)
            {
                qs.Add("distance", Distance);
            }
            return(qs);
        }
Ejemplo n.º 12
0
        public virtual IHttpQueryString GetQueryString()
        {
            SocialHttpQueryString query = new SocialHttpQueryString();

            if (Page > 0)
            {
                query.Add("page", Page);
            }
            if (PerPage > 0)
            {
                query.Add("per_page", PerPage);
            }
            return(query);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            SocialHttpQueryString query = new SocialHttpQueryString();

            if (Limit > 0)
            {
                query.Add("limit", Limit);
            }
            if (Offset > 0)
            {
                query.Add("offset", Offset);
            }
            return(query);
        }
        public IHttpQueryString GetQueryString()
        {
            SocialHttpQueryString qs = new SocialHttpQueryString();

            if (Page > 0)
            {
                qs.Add("page", Page);
            }
            if (PageLength > 0)
            {
                qs.Add("pagelen", PageLength);
            }
            return(qs);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            SocialHttpQueryString qs = new SocialHttpQueryString();

            if (Count > 0)
            {
                qs.Add("count", Count);
            }
            if (MaxLikeId != null)
            {
                qs.Add("max_like_id", MaxLikeId);
            }
            return(qs);
        }
        /// <summary>
        /// Gets a list of email addresses of the authenticated user.
        /// </summary>
        /// <param name="page">The page to be returned.</param>
        /// <param name="pageLength">The maximum amount of email addresses to be returned by each page.</param>
        /// <returns>Returns an instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns>
        /// <see>
        ///     <cref>https://confluence.atlassian.com/bitbucket/user-endpoint-2-0-744527199.html#userendpoint2.0-GETemailforauser</cref>
        /// </see>
        public SocialHttpResponse GetEmails(int page, int pageLength)
        {
            SocialHttpQueryString query = new SocialHttpQueryString();

            if (page > 0)
            {
                query.Add("page", page);
            }
            if (pageLength > 0)
            {
                query.Add("pagelen", pageLength);
            }
            return(Client.DoHttpGetRequest("https://api.bitbucket.org/2.0/user/emails", query));
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        /// <returns>An instance of <see cref="IHttpQueryString"/>.</returns>
        public IHttpQueryString GetQueryString()
        {
            // Since the name is mandatory, we throw an exception if no specified
            if (String.IsNullOrWhiteSpace(Name))
            {
                throw new PropertyNotSetException("Name");
            }

            // Convert the collection of fields to a string
            string fields = (Fields == null ? "" : Fields.ToString()).Trim();

            // Construct the query string
            SocialHttpQueryString query = new SocialHttpQueryString();

            query.Set("name", Name);
            if (!String.IsNullOrWhiteSpace(Description))
            {
                query.Add("description", Description);
            }
            if (!String.IsNullOrWhiteSpace(fields))
            {
                query.Set("fields", fields);
            }

            return(query);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            SocialHttpQueryString qs = new SocialHttpQueryString();

            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);
        }
        public IHttpQueryString GetQueryString()
        {
            SocialHttpQueryString query = new SocialHttpQueryString();

            if (!IncludeEntities)
            {
                query.Add("include_entities", "false");
            }
            if (SkipStatus)
            {
                query.Add("skip_status", "true");
            }
            if (IncludeEmail)
            {
                query.Add("include_email", "true");
            }
            return(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 <code>#</code> (eg. <code>snowy</code>, <code>nofilter</code>).</param>
        /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the raw response from the Instagram API.</returns>
        public SocialHttpResponse Search(string tag)
        {
            // Declare the query string
            SocialHttpQueryString qs = new SocialHttpQueryString();

            qs.Add("q", tag);

            // Perform the call to the API
            return(Client.DoHttpGetRequest("https://api.instagram.com/v1/tags/search", qs));
        }
        public IHttpQueryString GetQueryString()
        {
            IHttpQueryString query = new SocialHttpQueryString();

            if (Limit > 0)
            {
                query.Add("limit", Limit);
            }
            if (After != null)
            {
                query.Add("after", After.UnixTimestamp);
            }
            if (Before != null)
            {
                query.Add("before", Before.UnixTimestamp);
            }

            return(query);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Gets debug information about the specified access token.
        /// </summary>
        /// <param name="accessToken">The access token to debug.</param>
        /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns>
        public SocialHttpResponse DebugToken(string accessToken)
        {
            // Declare the query string
            SocialHttpQueryString query = new SocialHttpQueryString();

            query.Add("input_token", accessToken);

            // Make the call to the API
            return(Client.DoHttpGetRequest("/debug_token", query));
        }
        public IHttpQueryString GetQueryString()
        {
            SocialHttpQueryString query = new SocialHttpQueryString();

            query.Set("id", Id);
            if (TrimUser)
            {
                query.Add("trim_user", "true");
            }
            if (IncludeMyRetweet)
            {
                query.Add("include_my_retweet", "true");
            }
            if (IncludeEntities)
            {
                query.Add("include_entities", "true");
            }
            return(query);
        }
        /// <summary>
        /// Favorites the status message with the specified <code>statusId</code> as the authenticating user.
        /// </summary>
        /// <param name="statusId">The ID of the status message.</param>
        /// <returns>Returns an instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns>
        /// <see>
        ///     <cref>https://dev.twitter.com/rest/reference/post/favorites/create</cref>
        /// </see>
        public SocialHttpResponse Create(long statusId)
        {
            // Declare the query string
            SocialHttpQueryString query = new SocialHttpQueryString();

            query.Add("id", statusId);

            // Make the call to the API
            return(Client.DoHttpGetRequest("https://api.twitter.com/1.1/favorites/create.json", query));
        }
        public IHttpQueryString GetQueryString()
        {
            SocialHttpQueryString qs = new SocialHttpQueryString();

            if (Page > 0)
            {
                qs.Add("page", Page);
            }
            if (PageLength > 0)
            {
                qs.Add("pagelen", PageLength);
            }

            if (SortField != BitBucketRepositoryField.Unspecified)
            {
                string name = StringUtils.ToUnderscore(SortField);
                qs.Add("sort", (SortOrder == BitBucketSortOrder.Descending ? "-" : "") + name);
            }

            return(qs);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            // Declare the query string
            SocialHttpQueryString qs = new SocialHttpQueryString();

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

            // Optinal options
            if (Distance > 0)
            {
                qs.Add("distance", Distance);
            }
            if (Count > 0)
            {
                qs.Add("count", Count);
            }
            if (MinTimestamp != null)
            {
                qs.Add("min_timestamp", MinTimestamp.UnixTimestamp);
            }
            if (MaxTimestamp != null)
            {
                qs.Add("max_timestamp", MaxTimestamp.UnixTimestamp);
            }

            return(qs);
        }
        /// <summary>
        /// Exchanges the specified authorization code for an access token.
        /// </summary>
        /// <param name="authCode">The authorization code received from the Facebook OAuth dialog.</param>
        /// <returns>Returns an instance of <see cref="FacebookTokenResponse"/> representing the response.</returns>
        public FacebookTokenResponse GetAccessTokenFromAuthCode(string authCode)
        {
            // Some validation
            if (String.IsNullOrWhiteSpace(Version))
            {
                throw new PropertyNotSetException("Version");
            }
            if (String.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException("ClientId");
            }
            if (String.IsNullOrWhiteSpace(ClientSecret))
            {
                throw new PropertyNotSetException("ClientSecret");
            }
            if (String.IsNullOrWhiteSpace(RedirectUri))
            {
                throw new PropertyNotSetException("RedirectUri");
            }
            if (String.IsNullOrWhiteSpace(authCode))
            {
                throw new ArgumentNullException("authCode");
            }

            // Initialize the query string
            IHttpQueryString query = new SocialHttpQueryString();

            query.Add("client_id", ClientId);
            query.Add("redirect_uri", RedirectUri);
            query.Add("client_secret", ClientSecret);
            query.Add("code", authCode);

            // Make the call to the API
            SocialHttpResponse response = SocialUtils.Http.DoHttpGetRequest("https://graph.facebook.com/" + Version + "/oauth/access_token", query);

            // Parse the response
            return(FacebookTokenResponse.ParseResponse(response));
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpQueryString GetQueryString()
        {
            SocialHttpQueryString query = new SocialHttpQueryString();

            if (AlbumType != null && AlbumType.Count > 0)
            {
                query.Add("album_type", AlbumType);
            }
            if (!String.IsNullOrWhiteSpace(Market))
            {
                query.Add("market", Market);
            }
            if (Limit > 0)
            {
                query.Add("limit", Limit);
            }
            if (Offset > 0)
            {
                query.Add("offset", Offset);
            }

            return(query);
        }
        /// <summary>
        /// Skips the user's playback to the previous track.
        /// </summary>
        /// <param name="deviceId">The ID of the device this command is targeting. If not supplied, the user’s currently active device is the target.</param>
        /// <returns>An instance of <see cref="SocialHttpResponse"/> representing the raw response.</returns>
        /// <see>
        ///     <cref>https://developer.spotify.com/documentation/web-api/reference/player/skip-users-playback-to-previous-track/</cref>
        /// </see>
        public SocialHttpResponse Previous(string deviceId)
        {
            // Initialize the query string
            SocialHttpQueryString query = new SocialHttpQueryString();

            // Append the device ID (if present)
            if (!String.IsNullOrWhiteSpace(deviceId))
            {
                query.Add("device_id", deviceId);
            }

            // Make the request to the API
            return(Client.DoHttpPostRequest("/v1/me/player/previous", query));
        }
Ejemplo n.º 30
0
        public IHttpQueryString GetQueryString()
        {
            // Define the query string
            SocialHttpQueryString qs = new SocialHttpQueryString();

            // Add optional parameters
            if (UserId > 0)
            {
                qs.Set("user_id", UserId);
            }
            if (!String.IsNullOrWhiteSpace(ScreenName))
            {
                qs.Set("screen_name", ScreenName);
            }
            if (SinceId > 0)
            {
                qs.Set("since_id", SinceId);
            }
            if (Count > 0)
            {
                qs.Set("count", Count);
            }
            if (MaxId > 0)
            {
                qs.Set("max_id", MaxId);
            }
            if (TrimUser)
            {
                qs.Set("trim_user", "true");
            }
            if (ExcludeReplies)
            {
                qs.Set("exclude_replies", "true");
            }
            if (ContributorDetails)
            {
                qs.Set("contributor_details", "true");
            }
            if (!IncludeRetweets)
            {
                qs.Set("include_rts", "false");
            }
            if (TweetMode != TwitterTweetMode.Compatibility)
            {
                qs.Add("tweet_mode", StringUtils.ToCamelCase(TweetMode));
            }

            return(qs);
        }