Beispiel #1
0
        public static async Task <Tuple <long, string> > SaveSearchAsync(
            this IOAuthCredential credential, string query)
        {
            if (credential == null)
            {
                throw new ArgumentNullException("credential");
            }
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            var param = new Dictionary <string, object>
            {
                { "query", query }
            }.ParametalizeForPost();
            var client   = credential.CreateOAuthClient();
            var response = await client.PostAsync(new ApiAccess("saved_searches/create.json"), param);

            var respStr = await response.ReadAsStringAsync();

            return(await Task.Run(() =>
            {
                var json = DynamicJson.Parse(respStr);
                return Tuple.Create(Int64.Parse(json.id_str), json.query);
            }));
        }
Beispiel #2
0
 public void NotifyLimitationInfoGot(IOAuthCredential account, int trackLimit)
 {
     if (!_proxy.NotifyLimitationInfoGot(account, trackLimit) && this.Next != null)
     {
         this.Next.NotifyLimitationInfoGot(account, trackLimit);
     }
 }
Beispiel #3
0
        public static async Task <TwitterStatus> UpdateAsync(
            this IOAuthCredential credential, string status, long?inReplyToStatusId = null,
            Tuple <double, double> geoLatLong = null, string placeId  = null,
            bool?displayCoordinates           = null, long[] mediaIds = null)
        {
            if (credential == null)
            {
                throw new ArgumentNullException("credential");
            }
            if (status == null)
            {
                throw new ArgumentNullException("status");
            }
            var mediaIdStr = mediaIds != null
                ? String.Join(",", mediaIds.Select(s => s.ToString()))
                : null;

            var param = new Dictionary <string, object>
            {
                { "status", status },
                { "in_reply_to_status_id", inReplyToStatusId },
                { "lat", geoLatLong != null ? geoLatLong.Item1 : (double?)null },
                { "long", geoLatLong != null ? geoLatLong.Item2 : (double?)null },
                { "place_id", placeId },
                { "display_coordinates", displayCoordinates },
                { "media_ids", String.IsNullOrEmpty(mediaIdStr) ? null : mediaIdStr }
            }.ParametalizeForPost();
            var client   = credential.CreateOAuthClient(useGZip: false);
            var response = await client.PostAsync(new ApiAccess("statuses/update.json"), param);

            return(await response.ReadAsStatusAsync());
        }
Beispiel #4
0
        public static async Task <TwitterStatus> UpdateWithMediaAsync(
            this IOAuthCredential credential, string status, IEnumerable <byte[]> images,
            bool?possiblySensitive            = false, long?inReplyToStatusId = null,
            Tuple <double, double> geoLatLong = null, string placeId          = null, bool?displayCoordinates = null)
        {
            if (credential == null)
            {
                throw new ArgumentNullException("credential");
            }
            if (status == null)
            {
                throw new ArgumentNullException("status");
            }
            var param = new Dictionary <string, object>
            {
                { "status", status },
                { "possibly_sensitive", possiblySensitive },
                { "in_reply_to_status_id", inReplyToStatusId },
                { "lat", geoLatLong != null ? geoLatLong.Item1 : (double?)null },
                { "long", geoLatLong != null ? geoLatLong.Item2 : (double?)null },
                { "place_id", placeId },
                { "display_coordinates", displayCoordinates }
            }.Where(kvp => kvp.Value != null);
            var content = new MultipartFormDataContent();

            param.ForEach(kvp => content.Add(new StringContent(kvp.Value.ToString()), kvp.Key));
            images.ForEach((b, i) => content.Add(new ByteArrayContent(b), "media[]", "image_" + i + ".png"));
            var client   = credential.CreateOAuthClient();
            var response = await client.PostAsync(new ApiAccess("statuses/update_with_media.json"), content);

            return(await response.ReadAsStatusAsync());
        }
Beispiel #5
0
 public void NotifyLimitationInfoGot(IOAuthCredential account, int trackLimit)
 {
     if (!_proxy.NotifyLimitationInfoGot(account, trackLimit))
     {
         Next?.NotifyLimitationInfoGot(account, trackLimit);
     }
 }
Beispiel #6
0
        public static async Task <IEnumerable <TwitterUser> > GetRetweetsAsync(
            this IOAuthCredential credential, long id, int?count = null)
        {
            if (credential == null)
            {
                throw new ArgumentNullException("credential");
            }

            /*
             * for future compatibility
             * var param = new Dictionary<string, object>
             * {
             *  {"id", id},
             *  {"count", count},
             * }.ParametalizeForGet();
             * var client = credential.CreateOAuthClient();
             * var response = client.GetAsync(new ApiAccess("statuses/retweets.json", param))
             */
            var param = new Dictionary <string, object>
            {
                { "count", count },
            }.ParametalizeForGet();
            var client   = credential.CreateOAuthClient();
            var response = await client.GetAsync(new ApiAccess("statuses/retweets/" + id + ".json", param));

            return(await response.ReadAsUserCollectionAsync());
        }
Beispiel #7
0
        public static async Task <IEnumerable <TwitterStatus> > SearchAsync(
            this IOAuthCredential credential, string query,
            string geoCode = null, string lang = null, string locale = null,
            SearchResultType resultType = SearchResultType.Mixed,
            int?count    = null, DateTime?untilDate = null,
            long?sinceId = null, long?maxId         = null, bool extendedTweet = true)
        {
            if (credential == null)
            {
                throw new ArgumentNullException("credential");
            }
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            var param = new Dictionary <string, object>
            {
                { "q", query },
                { "geocode", geoCode },
                { "lang", lang },
                { "locale", locale },
                { "result_type", resultType.ToString().ToLower() },
                { "count", count },
                { "until", untilDate != null?untilDate.Value.ToString("yyyy-MM-dd") : null },
                { "since_id", sinceId },
                { "max_id", maxId },
                { "tweet_mode", extendedTweet ? "extended" : null }
            }.ParametalizeForGet();
            var client   = credential.CreateOAuthClient();
            var response = await client.GetAsync(new ApiAccess("search/tweets.json", param));

            return(await response.ReadAsStatusCollectionAsync());
        }
Beispiel #8
0
 public static Task <TwitterFriendship> UpdateFriendshipAsync(
     this IOAuthCredential credential, long userId, bool showRetweet)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     return(UpdateFriendshipCoreAsync(credential, userId, null, showRetweet));
 }
Beispiel #9
0
 public static Task <TwitterUser> ShowUserAsync(
     this IOAuthCredential credential, long userId)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     return(ShowUserCoreAsync(credential, userId, null));
 }
Beispiel #10
0
 public static Task <TwitterUser> DestroyFriendshipAsync(
     this IOAuthCredential credential, long userId)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     return(DestroyFriendshipCoreAsync(credential, userId, null));
 }
Beispiel #11
0
 public static Task <TwitterFriendship> ShowFriendshipAsync(
     this IOAuthCredential credential, long sourceId, long targetId)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     return(ShowFriendshipCoreAsync(credential, sourceId, null, targetId, null));
 }
Beispiel #12
0
 public static Task <TwitterUser> UpdateMuteAsync(this IOAuthCredential credential,
                                                  long userId, bool mute)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     return(UpdateMuteCoreAsync(credential, userId, null, mute));
 }
Beispiel #13
0
 public static Task <TwitterList> ShowListAsync(
     this IOAuthCredential credential, long listId)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     return(ShowListCoreAsync(credential, listId, null, null, null));
 }
Beispiel #14
0
 public static Task <IEnumerable <TwitterList> > GetListsAsync(
     this IOAuthCredential credential, long userId)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     return(GetListsCoreAsync(credential, userId, null));
 }
Beispiel #15
0
 public static Task <IEnumerable <TwitterStatus> > GetFavoritesAsync(
     this IOAuthCredential credential, long userId,
     int?count = null, long?sinceId = null, long?maxId = null)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     return(GetFavoritesCoreAsync(credential, userId, null, count, sinceId, maxId));
 }
Beispiel #16
0
 public ApiAccessor([NotNull] IOAuthCredential credential, [NotNull] string endpoint,
                    [CanBeNull] IWebProxy proxy, string userAgent = null, bool useGzip = true)
 {
     Credential = credential ?? throw new ArgumentNullException(nameof(credential));
     Endpoint   = endpoint ?? throw new ArgumentNullException(nameof(endpoint));
     Proxy      = proxy;
     UserAgent  = userAgent ?? DefaultUserAgent;
     _client    = new Lazy <HttpClient>(() => new TwitterApiHttpClient(credential, proxy, UserAgent, useGzip),
                                        LazyThreadSafetyMode.ExecutionAndPublication);
 }
Beispiel #17
0
 public TwitterApiHttpClient([NotNull] IOAuthCredential credential,
                             [CanBeNull] IWebProxy proxy, [CanBeNull] string userAgent, bool useGZip)
     : base(GetInnerHandler(credential, proxy, useGZip))
 {
     if (!String.IsNullOrEmpty(userAgent))
     {
         DefaultRequestHeaders.Remove(UserAgentHeader);
         DefaultRequestHeaders.Add(UserAgentHeader, userAgent);
     }
 }
Beispiel #18
0
        public void NotifyLimitationInfoGot(IOAuthCredential account, int trackLimit)
        {
            var acc = account as TwitterAccount;

            if (acc == null)
            {
                return;
            }
            BackstageModel.RegisterEvent(new TrackLimitEvent(acc, trackLimit));
        }
Beispiel #19
0
 public static Task <ICursorResult <IEnumerable <long> > > GetFollowersIdsAsync(
     this IOAuthCredential credential, long userId,
     long cursor = -1, int?count = null)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     return(GetFollowersIdsCoreAsync(credential, userId, null, cursor, count));
 }
Beispiel #20
0
 public static Task <IEnumerable <TwitterStatus> > GetUserTimelineAsync(
     this IOAuthCredential credential, long userId,
     int?count           = null, long?sinceId = null, long?maxId = null,
     bool?excludeReplies = null, bool?includeRetweets = null)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     return(GetUserTimelineCoreAsync(credential, userId, null, count, sinceId, maxId, excludeReplies, includeRetweets));
 }
Beispiel #21
0
        public static async Task <TwitterConfiguration> GetConfigurationAsync(this IOAuthCredential credential)
        {
            if (credential == null)
            {
                throw new ArgumentNullException("credential");
            }
            var client = credential.CreateOAuthClient();
            var json   = await client.GetStringAsync(new ApiAccess("help/configuration.json"));

            return(new TwitterConfiguration(DynamicJson.Parse(json)));
        }
Beispiel #22
0
 public static Task <IEnumerable <TwitterStatus> > GetListTimelineAsync(
     this IOAuthCredential credential, long listId,
     long?sinceId = null, long?maxId = null, int?count = null, bool?includeRts = null)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     return(GetListTimelineCoreAsync(
                credential, listId, null, null, null, sinceId, maxId, count, includeRts));
 }
Beispiel #23
0
 public static Task <ICursorResult <IEnumerable <TwitterUser> > > GetListMembersAsync(
     this IOAuthCredential credential, long listId,
     long?cursor = null)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     return(GetListMembersCoreAsync(
                credential, listId, null, null, null, cursor));
 }
Beispiel #24
0
 private static async Task<TwitterUser> ShowUserCoreAsync(
     IOAuthCredential credential, long? userId, string screenName)
 {
     var param = new Dictionary<string, object>
     {
         {"user_id", userId},
         {"screen_name", screenName},
     }.ParametalizeForGet();
     var client = credential.CreateOAuthClient();
     var response = await client.GetAsync(new ApiAccess("users/show.json", param));
     return await response.ReadAsUserAsync();
 }
Beispiel #25
0
 private static async Task<IEnumerable<TwitterList>> GetListsCoreAsync(
     IOAuthCredential credential, long? userId, string screenName)
 {
     var param = new Dictionary<string, object>
     {
         {"user_id", userId},
         {"screen_name", screenName},
     }.ParametalizeForGet();
     var client = credential.CreateOAuthClient();
     var response = await client.GetAsync(new ApiAccess("lists/list.json", param));
     return await response.ReadAsListCollectionAsync();
 }
Beispiel #26
0
        public static async Task <ICursorResult <IEnumerable <long> > > GetBlockingsIdsAsync(
            this IOAuthCredential credential, long cursor = -1)
        {
            var param = new Dictionary <string, object>
            {
                { "cursor", cursor },
            }.ParametalizeForGet();
            var client   = credential.CreateOAuthClient();
            var response = await client.GetAsync(new ApiAccess("blocks/ids.json", param));

            return(await response.ReadAsCursoredIdsAsync());
        }
Beispiel #27
0
        public static async Task <IEnumerable <long> > GetNoRetweetsIdsAsync(
            this IOAuthCredential credential)
        {
            if (credential == null)
            {
                throw new ArgumentNullException("credential");
            }
            var client  = credential.CreateOAuthClient();
            var respStr = await client.GetStringAsync(new ApiAccess("friendships/no_retweets/ids.json"));

            return(await Task.Run(() => ((dynamic[])DynamicJson.Parse(respStr)).Select(d => (long)d)));
        }
Beispiel #28
0
 public static Task <IEnumerable <TwitterList> > GetListsAsync(
     this IOAuthCredential credential, string screenName)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     if (screenName == null)
     {
         throw new ArgumentNullException("screenName");
     }
     return(GetListsCoreAsync(credential, null, screenName));
 }
Beispiel #29
0
 private static async Task<TwitterStatus> SendDirectMessageCoreAsync(
     IOAuthCredential credential, long? recipientUserId, string recipientScreenName, string text)
 {
     var param = new Dictionary<string, object>
     {
         {"user_id", recipientUserId},
         {"screen_name", recipientScreenName},
         {"text", text}
     }.ParametalizeForPost();
     var client = credential.CreateOAuthClient();
     var response = await client.PostAsync(new ApiAccess("direct_messages/new.json"), param);
     return await response.ReadAsStatusAsync();
 }
Beispiel #30
0
 public static Task <TwitterList> ShowListAsync(
     this IOAuthCredential credential, long userId, string slug)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     if (slug == null)
     {
         throw new ArgumentNullException("slug");
     }
     return(ShowListCoreAsync(credential, null, userId, null, slug));
 }
Beispiel #31
0
        private static async Task <TwitterUser> DestroyFriendshipCoreAsync(
            IOAuthCredential credential, long?userId, string screenName)
        {
            var param = new Dictionary <string, object>
            {
                { "user_id", userId },
                { "screen_name", screenName },
            }.ParametalizeForPost();
            var client   = credential.CreateOAuthClient();
            var response = await client.PostAsync(new ApiAccess("friendships/destroy.json"), param);

            return(await response.ReadAsUserAsync());
        }
Beispiel #32
0
 public static Task <TwitterUser> UpdateMuteAsync(
     this IOAuthCredential credential, string screenName, bool mute)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     if (screenName == null)
     {
         throw new ArgumentNullException("screenName");
     }
     return(UpdateMuteCoreAsync(credential, null, screenName, mute));
 }
Beispiel #33
0
        private static async Task <IEnumerable <TwitterList> > GetListsCoreAsync(
            IOAuthCredential credential, long?userId, string screenName)
        {
            var param = new Dictionary <string, object>
            {
                { "user_id", userId },
                { "screen_name", screenName },
            }.ParametalizeForGet();
            var client   = credential.CreateOAuthClient();
            var response = await client.GetAsync(new ApiAccess("lists/list.json", param));

            return(await response.ReadAsListCollectionAsync());
        }
Beispiel #34
0
 private static async Task<TwitterList> ShowListCoreAsync(
     IOAuthCredential credential, long? listId, long? userId, string screenName, string slug)
 {
     var param = new Dictionary<string, object>
     {
         {"list_id", listId},
         {"owner_id", userId},
         {"owner_screen_name", screenName},
         {"slug", slug},
     }.ParametalizeForGet();
     var client = credential.CreateOAuthClient();
     var response = await client.GetAsync(new ApiAccess("lists/show.json", param));
     return await response.ReadAsListAsync();
 }
Beispiel #35
0
 private static async Task<ICursorResult<IEnumerable<long>>> GetFollowersIdsCoreAsync(
     IOAuthCredential credential, long? userId, string screenName,
     long cursor, int? count)
 {
     var param = new Dictionary<string, object>
     {
         {"user_id", userId},
         {"screen_name", screenName},
         {"cursor", cursor},
         {"count", count}
     }.ParametalizeForGet();
     var client = credential.CreateOAuthClient();
     var response = await client.GetAsync(new ApiAccess("followers/ids.json", param));
     return await response.ReadAsCursoredIdsAsync();
 }
Beispiel #36
0
 private static async Task<IEnumerable<TwitterStatus>> GetFavoritesCoreAsync(
     IOAuthCredential credential, long? userId, string screenName,
     int? count, long? sinceId, long? maxId)
 {
     var param = new Dictionary<string, object>
     {
         {"user_id", userId},
         {"screen_name", screenName},
         {"count", count},
         {"since_id", sinceId},
         {"max_id", maxId},
     }.ParametalizeForGet();
     var client = credential.CreateOAuthClient();
     var response = await client.GetAsync(new ApiAccess("favorites/list.json", param));
     return await response.ReadAsStatusCollectionAsync();
 }
Beispiel #37
0
 private static async Task<IEnumerable<TwitterStatus>> GetUserTimelineCoreAsync(
     IOAuthCredential credential, long? userId, string screenName,
     int? count, long? sinceId, long? maxId, bool? excludeReplies, bool? includeRetweets)
 {
     var param = new Dictionary<string, object>
     {
         {"user_id", userId},
         {"screen_name", screenName},
         {"since_id", sinceId},
         {"max_id", maxId},
         {"count", count},
         {"exclude_replies", excludeReplies},
         {"include_rts", includeRetweets},
     }.ParametalizeForGet();
     var client = credential.CreateOAuthClient();
     var response = await client.GetAsync(new ApiAccess("statuses/user_timeline.json", param));
     return await response.ReadAsStatusCollectionAsync();
 }
Beispiel #38
0
 private static async Task<IEnumerable<TwitterUser>> LookupUserCoreAsync(
     IOAuthCredential credential, IEnumerable<long> userIds, IEnumerable<string> screenNames)
 {
     var param = new Dictionary<string, object>
     {
         {
             "user_id",
             userIds == null
                 ? null
                 : userIds.Select(s => s.ToString(CultureInfo.InvariantCulture))
                          .JoinString(",")
         },
         {"screen_name", screenNames == null ? null : screenNames.JoinString(",")},
     }.ParametalizeForGet();
     var client = credential.CreateOAuthClient();
     var response = await client.GetAsync(new ApiAccess("users/lookup.json", param));
     return await response.ReadAsUserCollectionAsync();
 }
Beispiel #39
0
 public static async Task<IEnumerable<TwitterStatus>> GetListTimelineCoreAsync(
     IOAuthCredential credential, long? listId, string slug, long? userId, string screenName,
     long? sinceId, long? maxId, int? count, bool? includeRts)
 {
     var param = new Dictionary<string, object>()
     {
         {"list_id", listId},
         {"slug", slug},
         {"owner_id", userId},
         {"owner_screen_name", screenName},
         {"since_id", sinceId},
         {"max_id", maxId},
         {"count", count},
         {"include_rts", includeRts},
     }.ParametalizeForGet();
     var client = credential.CreateOAuthClient();
     var response = await client.GetAsync(new ApiAccess("lists/statuses.json", param));
     return await response.ReadAsStatusCollectionAsync();
 }
Beispiel #40
0
 private static async Task<ICursorResult<IEnumerable<TwitterUser>>> GetListMembersCoreAsync(
     IOAuthCredential credential, long? listId, string slug, long? userId, string screenName,
     long? cursor = null)
 {
     var param = new Dictionary<string, object>()
     {
         {"list_id", listId},
         {"slug", slug},
         {"owner_id", userId},
         {"owner_screen_name", screenName},
         {"cursor", cursor},
         {"skip_status", true},
     }.ParametalizeForGet();
     var client = credential.CreateOAuthClient();
     var response = await client.GetAsync(new ApiAccess("lists/members.json", param));
     return await response.ReadAsCursoredUsersAsync();
 }
Beispiel #41
0
 public void NotifyLimitationInfoGot(IOAuthCredential account, int trackLimit)
 {
     var acc = account as TwitterAccount;
     if (acc == null) return;
     BackstageModel.RegisterEvent(new TrackLimitEvent(acc, trackLimit));
 }
Beispiel #42
0
 private static async Task<TwitterFriendship> UpdateFriendshipCoreAsync(
     IOAuthCredential credential, long? userId, string screenName, bool showRetweet)
 {
     var param = new Dictionary<string, object>
     {
         {"user_id", userId},
         {"screen_name", screenName},
         {"retweets", showRetweet},
     }.ParametalizeForPost();
     var client = credential.CreateOAuthClient();
     var response = await client.PostAsync(new ApiAccess("friendships/update.json"), param);
     return await response.ReadAsFriendshipAsync();
 }
 public void NotifyLimitationInfoGot(IOAuthCredential account, int trackLimit)
 {
     if (!_proxy.NotifyLimitationInfoGot(account, trackLimit) && this.Next != null)
     {
         this.Next.NotifyLimitationInfoGot(account, trackLimit);
     }
 }
 public void NotifyLimitationInfoGot(IOAuthCredential account, int trackLimit)
 {
     if (!_proxy.NotifyLimitationInfoGot(account, trackLimit))
     {
         Next?.NotifyLimitationInfoGot(account, trackLimit);
     }
 }
Beispiel #45
0
 private static async Task<TwitterUser> DestroyFriendshipCoreAsync(
     IOAuthCredential credential, long? userId, string screenName)
 {
     var param = new Dictionary<string, object>
     {
         {"user_id", userId},
         {"screen_name", screenName},
     }.ParametalizeForPost();
     var client = credential.CreateOAuthClient();
     var response = await client.PostAsync(new ApiAccess("friendships/destroy.json"), param);
     return await response.ReadAsUserAsync();
 }
 public bool NotifyLimitationInfoGot(IOAuthCredential account, int trackLimit)
 {
     return false;
 }
Beispiel #47
0
 public static async Task<TwitterFriendship> ShowFriendshipCoreAsync(
     IOAuthCredential credential, long? sourceId, string sourceScreenName,
         long? targetId, string targetScreenName)
 {
     var param = new Dictionary<string, object>
     {
         {"source_id", sourceId},
         {"source_screen_name", sourceScreenName},
         {"target_id", targetId},
         {"target_screen_name", targetScreenName},
     }.ParametalizeForGet();
     var client = credential.CreateOAuthClient();
     var response = await client.GetAsync(new ApiAccess("friendships/show.json", param));
     return await response.ReadAsFriendshipAsync();
 }
Beispiel #48
0
 private static async Task<TwitterUser> UpdateMuteCoreAsync(
     IOAuthCredential credential, long? userId, string screenName, bool mute)
 {
     var param = new Dictionary<string, object>
     {
         {"user_id", userId},
         {"screen_name", screenName},
     }.ParametalizeForPost();
     var endpoint = mute ? "mutes/users/create" : "mutes/users/destroy";
     var client = credential.CreateOAuthClient();
     var response = await client.PostAsync(new ApiAccess(endpoint), param);
     return await response.ReadAsUserAsync();
 }