コード例 #1
0
ファイル: MastodonClient.cs プロジェクト: shinmili/Mastonet
        /// <summary>
        /// Fetching a user's notifications
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <param name="excludeTypes">Types to exclude</param>
        /// <returns>Returns a list of Notifications for the authenticated user</returns>
        public Task <MastodonList <Notification> > GetNotifications(ArrayOptions options, NotificationType excludeTypes = NotificationType.None)
        {
            var url         = "/api/v1/notifications";
            var queryParams = "";

            if (options != null)
            {
                queryParams += "?" + options.ToQueryString();
            }
            if ((excludeTypes & NotificationType.Follow) == NotificationType.Follow)
            {
                queryParams += (queryParams != "" ? "&" : "?") + "exclude_types[]=follow";
            }
            if ((excludeTypes & NotificationType.Favourite) == NotificationType.Favourite)
            {
                queryParams += (queryParams != "" ? "&" : "?") + "exclude_types[]=favourite";
            }
            if ((excludeTypes & NotificationType.Reblog) == NotificationType.Reblog)
            {
                queryParams += (queryParams != "" ? "&" : "?") + "exclude_types[]=reblog";
            }
            if ((excludeTypes & NotificationType.Mention) == NotificationType.Mention)
            {
                queryParams += (queryParams != "" ? "&" : "?") + "exclude_types[]=mention";
            }
            if ((excludeTypes & NotificationType.Poll) == NotificationType.Poll)
            {
                queryParams += (queryParams != "" ? "&" : "?") + "exclude_types[]=poll";
            }
            return(GetMastodonList <Notification>(url + queryParams));
        }
コード例 #2
0
        /// <summary>
        /// Retrieving Public timeline
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <param name="local">Only return statuses originating from this instance</param>
        /// <returns>Returns an array of Statuses, most recent ones first</returns>
        public Task <MastodonList <Status> > GetPublicTimeline(ArrayOptions options, bool local = false)
        {
            string url = "/api/v1/timelines/public";

            var queryParams = "";

            if (local)
            {
                queryParams += "?local=true";
            }
            if (options != null)
            {
                if (queryParams != "")
                {
                    queryParams += "&";
                }
                else
                {
                    queryParams += "?";
                }
                queryParams += options.ToQueryString();
            }

            return(GetList <Status>(url + queryParams));
        }
コード例 #3
0
        /// <summary>
        /// Retrieving Tag timeline
        /// </summary>
        /// <param name="hashtag">The tag to retieve</param>
        /// <param name="local">Only return statuses originating from this instance</param>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Statuses, most recent ones first</returns>
        public Task <IEnumerable <Status> > GetTagTimeline(string hashtag, ArrayOptions options, bool local = false)
        {
            string url = "/api/v1/timelines/tag/" + hashtag;

            var queryParams = "";

            if (local)
            {
                queryParams += "?local=true";
            }
            if (options != null)
            {
                if (queryParams != "")
                {
                    queryParams += "&";
                }
                else
                {
                    queryParams += "?";
                }
                queryParams += options.ToQueryString();
            }

            return(Get <IEnumerable <Status> >(url + queryParams));
        }
コード例 #4
0
        /// <summary>
        /// Fetching a user's favourites
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Statuses favourited by the authenticated user</returns>
        public Task <IEnumerable <Status> > GetFavourites(ArrayOptions options)
        {
            var url = "/api/v1/favourites";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(Get <IEnumerable <Status> >(url));
        }
コード例 #5
0
ファイル: MastodonClient.cs プロジェクト: shinmili/Mastonet
        /// <summary>
        /// Accounts that are in a given list.
        /// </summary>
        /// <param name="listId"></param>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns array of Account</returns>
        public Task <MastodonList <Account> > GetListAccounts(long listId, ArrayOptions options)
        {
            var url = $"/api/v1/lists/{listId}/accounts";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(GetMastodonList <Account>(url));
        }
コード例 #6
0
        /// <summary>
        /// Fetching a user's favourites
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Statuses favourited by the authenticated user</returns>
        public Task <MastodonList <Status> > GetFavourites(ArrayOptions options)
        {
            var url = "/api/v1/favourites";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(GetList <Status>(url));
        }
コード例 #7
0
        /// <summary>
        /// Getting who account is following
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Accounts</returns>
        public Task <MastodonList <Account> > GetAccountFollowing(long accountId, ArrayOptions options)
        {
            var url = $"/api/v1/accounts/{accountId}/following";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(GetList <Account>(url));
        }
コード例 #8
0
        /// <summary>
        /// Getting who reblogged a status
        /// </summary>
        /// <param name="statusId"></param>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Accounts</returns>
        public Task <MastodonList <Account> > GetRebloggedBy(long statusId, ArrayOptions options)
        {
            var url = $"/api/v1/statuses/{statusId}/reblogged_by";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(GetList <Account>(url));
        }
コード例 #9
0
        /// <summary>
        /// Conversations (direct messages) for an account
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns array of Conversation</returns>
        public Task <MastodonList <Conversation> > GetConversations(ArrayOptions options)
        {
            string url = "/api/v1/conversations";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(GetMastodonList <Conversation>(url));
        }
コード例 #10
0
        /// <summary>
        /// Retrieving Home timeline
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Statuses, most recent ones first</returns>
        public Task <MastodonList <Status> > GetHomeTimeline(ArrayOptions options)
        {
            string url = "/api/v1/timelines/home";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(GetMastodonList <Status>(url));
        }
コード例 #11
0
        /// <summary>
        /// Fetching a list of follow requests
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Accounts which have requested to follow the authenticated user</returns>
        public Task <IEnumerable <Account> > GetFollowRequests(ArrayOptions options)
        {
            var url = "/api/v1/follow_requests";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(this.Get <IEnumerable <Account> >(url));
        }
コード例 #12
0
        /// <summary>
        /// Getting who account is following
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Accounts</returns>
        public Task <IEnumerable <Account> > GetAccountFollowing(int accountId, ArrayOptions options)
        {
            var url = $"/api/v1/accounts/{accountId}/following";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(Get <IEnumerable <Account> >(url));
        }
コード例 #13
0
        /// <summary>
        /// Fetching a user's notifications
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns a list of Notifications for the authenticated user</returns>
        public Task <MastodonList <Notification> > GetNotifications(ArrayOptions options)
        {
            var url = "/api/v1/notifications";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(GetList <Notification>(url));
        }
コード例 #14
0
        /// <summary>
        /// Fetching a user's reports
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns a list of Reports made by the authenticated user</returns>
        public Task <MastodonList <Report> > GetReports(ArrayOptions options)
        {
            var url = "/api/v1/reports";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(GetList <Report>(url));
        }
コード例 #15
0
        /// <summary>
        /// Fetching a user's blocked domains
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of strings</returns>
        public Task <MastodonList <string> > GetDomainBlocks(ArrayOptions options)
        {
            var url = "/api/v1/domain_blocks";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(GetList <string>(url));
        }
コード例 #16
0
        /// <summary>
        /// Fetching a user's blocks
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Accounts blocked by the authenticated user</returns>
        public Task <MastodonList <Account> > GetBlocks(ArrayOptions options)
        {
            var url = "/api/v1/blocks";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(GetList <Account>(url));
        }
コード例 #17
0
        /// <summary>
        /// Retrieving Home timeline
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Statuses, most recent ones first</returns>
        public Task <IEnumerable <Status> > GetHomeTimeline(ArrayOptions options)
        {
            string url = "/api/v1/timelines/home";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(Get <IEnumerable <Status> >(url));
        }
コード例 #18
0
        /// <summary>
        /// Fetching a user's reports
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns a list of Reports made by the authenticated user</returns>
        public Task <IEnumerable <Report> > GetReports(ArrayOptions options)
        {
            var url = "/api/v1/reports";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(Get <IEnumerable <Report> >(url));
        }
コード例 #19
0
        /// <summary>
        /// Getting who favourited a status
        /// </summary>
        /// <param name="statusId"></param>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Accounts</returns>
        public Task <IEnumerable <Account> > GetFavouritedBy(int statusId, ArrayOptions options)
        {
            var url = $"/api/v1/statuses/{statusId}/favourited_by";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(Get <IEnumerable <Account> >(url));
        }
コード例 #20
0
        /// <summary>
        /// Fetching a user's notifications
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns a list of Notifications for the authenticated user</returns>
        public Task <IEnumerable <Notification> > GetNotifications(ArrayOptions options)
        {
            var url = "/api/v1/notifications";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(Get <IEnumerable <Notification> >(url));
        }
コード例 #21
0
        /// <summary>
        /// Fetching a user's mutes
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Accounts muted by the authenticated user</returns>
        public Task <IEnumerable <Account> > GetMutes(ArrayOptions options)
        {
            var url = "/api/v1/mutes";

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }
            return(Get <IEnumerable <Account> >(url));
        }
コード例 #22
0
        /// <summary>
        /// Retrieving List timeline
        /// </summary>
        /// <param name="listId"></param>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Statuses, most recent ones first</returns>
        public Task <MastodonList <Status> > GetListTimeline(long listId, ArrayOptions options)
        {
            string url = "/api/v1/timelines/list/" + listId;

            if (options != null)
            {
                url += "?" + options.ToQueryString();
            }

            return(GetMastodonList <Status>(url));
        }
コード例 #23
0
        /// <summary>
        /// Searching for accounts
        /// </summary>
        /// <param name="q">What to search for</param>
        /// <param name="options">Define the first and last items to get</param>
        /// <param name="limit">Maximum number of matching accounts to return (default: 40)</param>
        /// <returns>Returns an array of matching Accounts. Will lookup an account remotely if the search term is in the username@domain format and not yet in the database</returns>
        public Task <IEnumerable <Account> > SearchAccounts(string q, ArrayOptions options)
        {
            if (string.IsNullOrEmpty(q))
            {
                return(Task.FromResult(Enumerable.Empty <Account>()));
            }

            string url = "/api/v1/accounts/search?q=" + Uri.EscapeUriString(q);

            if (options != null)
            {
                url += "&" + options.ToQueryString();
            }

            return(Get <IEnumerable <Account> >(url));
        }
コード例 #24
0
        /// <summary>
        /// Retrieving Public timeline
        /// </summary>
        /// <param name="options">Define the first and last items to get</param>
        /// <param name="local">Only return statuses originating from this instance</param>
        /// <param name="onlyMedia">Only statuses with media attachments</param>
        /// <returns>Returns an array of Statuses, most recent ones first</returns>
        public Task <MastodonList <Status> > GetPublicTimeline(ArrayOptions options, bool local = false, bool onlyMedia = false)
        {
            string url = "/api/v1/timelines/public";

            var queryParams = "";

            if (local)
            {
                queryParams += "?local=true";
            }
            if (onlyMedia)
            {
                queryParams += (queryParams != "" ? "&" : "?") + "only_media=true";
            }
            if (options != null)
            {
                queryParams += (queryParams != "" ? "&" : "?") + options.ToQueryString();
            }

            return(GetMastodonList <Status>(url + queryParams));
        }
コード例 #25
0
        /// <summary>
        /// Getting an account's statuses
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="onlyMedia">Only return statuses that have media attachments</param>
        /// <param name="excludeReplies">Skip statuses that reply to other statuses</param>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Statuses</returns>
        public Task <IEnumerable <Status> > GetAccountStatuses(int accountId, ArrayOptions options, bool onlyMedia = false, bool excludeReplies = false)
        {
            var url = $"/api/v1/accounts/{accountId}/statuses";

            string queryParams = "";

            if (onlyMedia)
            {
                queryParams = "?only_media=true";
            }
            if (excludeReplies)
            {
                if (queryParams != "")
                {
                    queryParams += "&";
                }
                else
                {
                    queryParams += "?";
                }
                queryParams += "exclude_replies=true";
            }
            if (options != null)
            {
                if (queryParams != "")
                {
                    queryParams += "&";
                }
                else
                {
                    queryParams += "?";
                }
                queryParams += options.ToQueryString();
            }

            return(Get <IEnumerable <Status> >(url + queryParams));
        }
コード例 #26
0
        /// <summary>
        /// Getting an account's statuses
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="onlyMedia">Only return statuses that have media attachments</param>
        /// <param name="excludeReplies">Skip statuses that reply to other statuses</param>
        /// <param name="pinned">Only return statuses that have been pinned</param>
        /// <param name="excludeReblogs">Skip statuses that are reblogs of other statuses</param>
        /// <param name="options">Define the first and last items to get</param>
        /// <returns>Returns an array of Statuses</returns>
        public Task <MastodonList <Status> > GetAccountStatuses(long accountId, ArrayOptions options, bool onlyMedia = false, bool excludeReplies = false, bool pinned = false, bool excludeReblogs = false)
        {
            var url = $"/api/v1/accounts/{accountId}/statuses";

            string queryParams = "";

            if (onlyMedia)
            {
                queryParams = "?only_media=true";
            }
            if (pinned)
            {
                if (queryParams != "")
                {
                    queryParams += "&";
                }
                else
                {
                    queryParams += "?";
                }
                queryParams += "pinned=true";
            }
            if (excludeReplies)
            {
                if (queryParams != "")
                {
                    queryParams += "&";
                }
                else
                {
                    queryParams += "?";
                }
                queryParams += "exclude_replies=true";
            }
            if (excludeReblogs)
            {
                if (queryParams != "")
                {
                    queryParams += "&";
                }
                else
                {
                    queryParams += "?";
                }
                queryParams += "exclude_reblogs=true";
            }
            if (options != null)
            {
                if (queryParams != "")
                {
                    queryParams += "&";
                }
                else
                {
                    queryParams += "?";
                }
                queryParams += options.ToQueryString();
            }

            return(GetMastodonList <Status>(url + queryParams));
        }
コード例 #27
0
 public Task <List <Account> > SearchAccounts(string q, ArrayOptions options)
 {
     return(SearchAccounts(q, options?.Limit));
 }