/// <summary>
        /// Gets an instance of <see cref="IHttpPostData"/> representing the POST parameters.
        /// </summary>
        public IHttpPostData GetPostData()
        {
            IHttpPostData postData = new HttpPostData {
                IsMultipart = !String.IsNullOrWhiteSpace(Source)
            };

            if (!String.IsNullOrWhiteSpace(Source))
            {
                postData.AddFile("source", Source);
            }
            if (!String.IsNullOrWhiteSpace(Url))
            {
                postData.Add("url", Url);
            }
            if (!String.IsNullOrWhiteSpace(Message))
            {
                postData.Add("message", Message);
            }
            if (!String.IsNullOrWhiteSpace(Place))
            {
                postData.Add("place", Place);
            }
            if (NoStory)
            {
                postData.Add("no_story", "true");
            }
            return(postData);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpPostData"/> representing the POST parameters.
        /// </summary>
        /// <returns>An instance of <see cref="IHttpPostData"/>.</returns>
        public IHttpPostData GetPostData()
        {
            if (ListId == 0)
            {
                throw new PropertyNotSetException(nameof(ListId));
            }
            if (UserId == 0 && String.IsNullOrWhiteSpace(ScreenName))
            {
                throw new PropertyNotSetException(nameof(UserId));
            }

            IHttpPostData data = new HttpPostData {
                { "list_id", ListId }
            };

            if (UserId > 0)
            {
                data.Add("user_id", UserId);
            }
            if (!String.IsNullOrWhiteSpace(ScreenName))
            {
                data.Add("screen_name", ScreenName);
            }

            return(data);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpPostData GetPostData()
        {
            // Both "Title" or "Description" should be specified
            if (string.IsNullOrWhiteSpace(Title))
            {
                throw new PropertyNotSetException("Title");
            }
            if (string.IsNullOrWhiteSpace(Description))
            {
                throw new PropertyNotSetException("Description");
            }

            // Append the options to the POST data (if specified)
            HttpPostData data = new HttpPostData();

            data.Add("title", Title);
            data.Add("description", Description);
            if (!string.IsNullOrWhiteSpace(PrimaryPhotoId))
            {
                data.Add("primary_photo_id ", PrimaryPhotoId);
            }

            // TODO: The "full_result" parameter should be supported as well, but the Flickr API documentation doesn't specify it's type

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

            // Initialize the POST data
            IHttpPostData data = new HttpPostData();

            data.Add("grant_type", "authorization_code");
            data.Add("code", authCode);
            data.Add("redirect_uri", RedirectUri);

            // Initialize the request
            IHttpRequest request = new HttpRequest {
                Method        = HttpMethod.Post,
                Url           = "https://api.vimeo.com/oauth/access_token",
                PostData      = data,
                Authorization = "basic " + SecurityUtils.Base64Encode(ClientId + ":" + ClientSecret)
            };

            // Make the call to the API
            IHttpResponse response = request.GetResponse();

            // Parse the response
            return(new VimeoTokenResponse(response));
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpPostData"/> representing the POST parameters.
        /// </summary>
        public IHttpPostData GetPostData()
        {
            IHttpPostData postData = new HttpPostData();

            if (IsDefault)
            {
                postData.Add("is_default", "true");
            }
            if (string.IsNullOrWhiteSpace(Location) == false)
            {
                postData.Add("location", Location);
            }
            if (string.IsNullOrWhiteSpace(Message) == false)
            {
                postData.Add("message", Message);
            }
            if (string.IsNullOrWhiteSpace(Name) == false)
            {
                postData.Add("name", Name);
            }
            if (string.IsNullOrWhiteSpace(Place) == false)
            {
                postData.Add("place", Place);
            }
            if (Privacy != null && Privacy.Value != FacebookPrivacy.Default)
            {
                postData.Add("privacy", Privacy.ToString());
            }
            return(postData);
        }
Example #6
0
        /// <returns>An instance of <see cref="HttpResponse"/> representing the raw response.</returns>
        protected virtual IHttpResponse GetAccessTokenResponse(string verifier)
        {
            // Some error checking
            if (string.IsNullOrWhiteSpace(AccessTokenUrl))
            {
                throw new PropertyNotSetException(nameof(AccessTokenUrl));
            }

            // Initialize the POST data
            IHttpPostData postData = new HttpPostData();

            postData.Add("oauth_verifier", verifier);

            // Make the call to the API/provider
            return(Post(AccessTokenUrl, null, postData));
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpPostData"/> representing the POST parameters.
        /// </summary>
        /// <returns>An instance of <see cref="IHttpPostData"/>.</returns>
        public IHttpPostData GetPostData()
        {
            if (String.IsNullOrWhiteSpace(Name))
            {
                throw new ArgumentNullException(nameof(Name));
            }

            IHttpPostData data = new HttpPostData();

            data.Set("name", Name);
            data.Set("mode", StringUtils.ToCamelCase(Mode));
            if (!String.IsNullOrWhiteSpace(Description))
            {
                data.Add("description", Description);
            }

            return(data);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpPostData"/> representing the POST parameters.
        /// </summary>
        public IHttpPostData GetPostData()
        {
            IHttpPostData postData = new HttpPostData();

            if (string.IsNullOrWhiteSpace(Message) == false)
            {
                postData.Add("message", Message);
            }
            if (string.IsNullOrWhiteSpace(Link) == false)
            {
                postData.Add("link", Link);
            }
            if (string.IsNullOrWhiteSpace(Picture) == false)
            {
                postData.Add("picture", Picture);
            }
            if (string.IsNullOrWhiteSpace(Name) == false)
            {
                postData.Add("name", Name);
            }
            if (string.IsNullOrWhiteSpace(Caption) == false)
            {
                postData.Add("caption", Caption);
            }
            if (string.IsNullOrWhiteSpace(Description) == false)
            {
                postData.Add("description", Description);
            }
            if (string.IsNullOrWhiteSpace(Place) == false)
            {
                postData.Add("place", Place);
            }
            if (Tags != null && Tags.Length > 0)
            {
                postData.Add("tags", string.Join(",", Tags));
            }
            return(postData);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpPostData"/> representing the POST parameters.
        /// </summary>
        /// <returns>An instance of <see cref="IHttpPostData"/>.</returns>
        public IHttpPostData GetPostData()
        {
            // Validate required properties
            if (String.IsNullOrWhiteSpace(Status))
            {
                throw new PropertyNotSetException(nameof(Status));
            }

            // Initialize a new instance with required parameters
            IHttpPostData data = new HttpPostData();

            data.Set("status", Status);

            // Append optional parameters to be POST data
            if (ReplyTo > 0)
            {
                data.Add("in_reply_to_status_id", ReplyTo);
            }
            if (IsPossiblySensitive)
            {
                data.Add("possibly_sensitive", "true");
            }
            if (Math.Abs(Latitude) > Double.Epsilon && Math.Abs(Longitude) > Double.Epsilon)
            {
                data.Add("lat", Latitude);
                data.Add("long", Longitude);
            }
            if (PlaceId != null)
            {
                data.Add("place_id", PlaceId);
            }
            if (DisplayCoordinates)
            {
                data.Add("display_coordinates", "true");
            }

            return(data);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpPostData"/> representing the POST parameters.
        /// </summary>
        public IHttpPostData GetPostData()
        {
            // Check wether a photo was specified
            if (string.IsNullOrWhiteSpace(Photo))
            {
                throw new PropertyNotSetException("Photo");
            }

            HttpPostData data = new HttpPostData {
                IsMultipart = true
            };

            data.AddFile("photo", Photo);
            if (!string.IsNullOrWhiteSpace(Title))
            {
                data.Add("title", Title);
            }
            if (!string.IsNullOrWhiteSpace(Description))
            {
                data.Add("description", Description);
            }
            if (Tags != null && Tags.Length > 0)
            {
                data.Add("tags", string.Join(" ", Tags));
            }

            // Append the visiblity (if not private)
            switch (Visibility)
            {
            case FlickrPhotoSafetyVisibility.Public: {
                data.Add("is_public", "1");
                break;
            }

            case FlickrPhotoSafetyVisibility.Friends: {
                data.Add("is_friend", "1");
                break;
            }

            case FlickrPhotoSafetyVisibility.Family: {
                data.Add("is_family", "1");
                break;
            }

            case FlickrPhotoSafetyVisibility.FriendsAndFamily: {
                data.Add("is_friend", "1");
                data.Add("is_public", "1");
                break;
            }
            }

            // Append the safety level (if specified)
            switch (SafetyLevel)
            {
            case FlickrPhotoSafetyLevel.Safe: data.Add("safety_level", "1"); break;

            case FlickrPhotoSafetyLevel.Moderate: data.Add("safety_level", "2"); break;

            case FlickrPhotoSafetyLevel.Restricted: data.Add("safety_level", "3"); break;
            }

            if (ContentType != FlickrPhotoContentType.NotSpecified)
            {
                data.Add("content_type", (int)ContentType);
            }

            if (IsHidden)
            {
                data.Add("hidden", "2");
            }

            return(data);
        }