예제 #1
0
        /// <summary>
        /// Uploading a media attachment
        /// </summary>
        /// <param name="media">Media to be uploaded</param>
        /// <returns>Returns an Attachment that can be used when creating a status</returns>
        public Task <Attachment> UploadMedia(MediaDefinition media)
        {
            media.ParamName = "file";
            var list = new List <MediaDefinition>()
            {
                media
            };

            return(this.Post <Attachment>("/api/v1/media", null, list));
        }
예제 #2
0
        /// <summary>
        /// Uploading a media attachment
        /// </summary>
        /// <param name="media">Media to be uploaded</param>
        /// <param name="description">A plain-text description of the media for accessibility (max 420 chars)</param>
        /// <param name="focus">Two floating points. See <see cref="https://docs.joinmastodon.org/api/rest/media/#focal-points">focal points</see></param>
        /// <returns>Returns an Attachment that can be used when creating a status</returns>
        public Task <Attachment> UploadMedia(MediaDefinition media, string description = null, AttachmentFocusData focus = null)
        {
            media.ParamName = "file";
            var list = new List <MediaDefinition>()
            {
                media
            };
            var data = new Dictionary <string, string>();

            if (description != null)
            {
                data.Add("description", description);
            }
            if (focus != null)
            {
                data.Add("focus", $"{focus.X},{focus.Y}");
            }
            return(this.Post <Attachment>("/api/v1/media", data, list));
        }
예제 #3
0
        /// <summary>
        /// Updating the current user
        /// </summary>
        /// <param name="display_name">The name to display in the user's profile</param>
        /// <param name="note">A new biography for the user</param>
        /// <param name="avatar">A base64 encoded image to display as the user's avatar</param>
        /// <param name="header">A base64 encoded image to display as the user's header image</param>
        /// <returns>Returns the authenticated user's Account</returns>
        public Task <Account> UpdateCredentials(string display_name = null, string note = null, MediaDefinition avatar = null, MediaDefinition header = null)
        {
            var data  = new List <KeyValuePair <string, string> >();
            var media = new List <MediaDefinition>();

            if (display_name != null)
            {
                data.Add(new KeyValuePair <string, string>("display_name", display_name));
            }
            if (note != null)
            {
                data.Add(new KeyValuePair <string, string>("note", note));
            }

            if (avatar != null)
            {
                avatar.ParamName = "avatar";
                media.Add(avatar);
            }
            if (header != null)
            {
                header.ParamName = "header";
                media.Add(header);
            }

            return(Patch <Account>($"/api/v1/accounts/update_credentials", data, media));
        }
예제 #4
0
        /// <summary>
        /// Updating the current user
        /// </summary>
        /// <param name="display_name">The name to display in the user's profile</param>
        /// <param name="note">A new biography for the user</param>
        /// <param name="avatar">A base64 encoded image to display as the user's avatar</param>
        /// <param name="header">A base64 encoded image to display as the user's header image</param>
        /// <param name="locked">Whether to enable follow requests</param>
        /// <param name="source_privacy">Default post privacy preference</param>
        /// <param name="source_sensitive">Whether to mark statuses as sensitive by default</param>
        /// <param name="source_language">Override language on statuses by default (ISO6391)</param>
        /// <param name="fields_attributes">Profile metadata (max. 4)</param>
        /// <returns>Returns the authenticated user's Account</returns>
        public Task <Account> UpdateCredentials(string display_name       = null,
                                                string note               = null,
                                                MediaDefinition avatar    = null,
                                                MediaDefinition header    = null,
                                                bool?locked               = null,
                                                Visibility?source_privacy = null,
                                                bool?source_sensitive     = null,
                                                string source_language    = null,
                                                IEnumerable <AccountField> fields_attributes = null)
        {
            if (fields_attributes?.Count() > 4)
            {
                throw new ArgumentException("Number of fields must be 4 or fewer.", nameof(fields_attributes));
            }

            var data  = new List <KeyValuePair <string, string> >();
            var media = new List <MediaDefinition>();

            if (display_name != null)
            {
                data.Add(new KeyValuePair <string, string>("display_name", display_name));
            }
            if (note != null)
            {
                data.Add(new KeyValuePair <string, string>("note", note));
            }

            if (avatar != null)
            {
                avatar.ParamName = "avatar";
                media.Add(avatar);
            }
            if (header != null)
            {
                header.ParamName = "header";
                media.Add(header);
            }
            if (locked.HasValue)
            {
                data.Add(new KeyValuePair <string, string>("locked", locked.ToString().ToLowerInvariant()));
            }
            if (source_privacy.HasValue)
            {
                data.Add(new KeyValuePair <string, string>("source[privacy]", source_privacy.ToString().ToLowerInvariant()));
            }
            if (source_sensitive.HasValue)
            {
                data.Add(new KeyValuePair <string, string>("source[sensitive]", source_sensitive.ToString().ToLowerInvariant()));
            }
            if (source_language != null)
            {
                data.Add(new KeyValuePair <string, string>("source[language]", source_language));
            }
            if (fields_attributes != null)
            {
                foreach (var item in fields_attributes.Select((f, i) => new { f, i }))
                {
                    data.Add(new KeyValuePair <string, string>($"fields_attributes[{item.i}][name]", item.f.Name));
                    data.Add(new KeyValuePair <string, string>($"fields_attributes[{item.i}][value]", item.f.Value));
                }
            }

            return(Patch <Account>($"/api/v1/accounts/update_credentials", data, media));
        }