/// <summary> /// Updates user's account settings /// </summary> /// <param name="trendLocationWeoid">WEOID for Trend Location the user is interested in.</param> /// <param name="sleepTimeEnabled">Turn on time periods when notifications won't be sent.</param> /// <param name="startSleepTime">Don't send notifications at this time or later this time. (hour from 00 to 23)</param> /// <param name="endSleepTime">Start sending notifications again after this time. (hour from 00 to 23)</param> /// <param name="timeZone">User's time zone.</param> /// <param name="lang">User's language.</param> /// <returns>Account information with Settings property populated.</returns> public async Task <Account> UpdateAccountSettingsAsync(int?trendLocationWoeid, bool?sleepTimeEnabled, int?startSleepTime, int?endSleepTime, string timeZone, string lang, CancellationToken cancelToken = default(CancellationToken)) { var accountUrl = BaseUrl + "account/settings.json"; if (trendLocationWoeid == null && sleepTimeEnabled == null && startSleepTime == null && endSleepTime == null && string.IsNullOrWhiteSpace(timeZone) && string.IsNullOrWhiteSpace(lang)) { throw new ArgumentException("At least one parameter must be provided as arguments, but none are specified.", NoInputParam); } var reqProc = new AccountRequestProcessor <Account>(); var parameters = new Dictionary <string, string> { { "time_zone", timeZone }, { "lang", lang } }; if (trendLocationWoeid != null) { parameters.Add("trend_location_woeid", trendLocationWoeid.ToString()); } if (sleepTimeEnabled != null) { parameters.Add("sleep_time_enabled", sleepTimeEnabled.ToString().ToLower()); } if (startSleepTime != null) { parameters.Add("start_sleep_time", startSleepTime.ToString()); } if (endSleepTime != null) { parameters.Add("end_sleep_time", endSleepTime.ToString()); } RawResult = await TwitterExecutor.PostFormUrlEncodedToTwitterAsync <Account>( HttpMethod.Post.ToString(), accountUrl, parameters, cancelToken) .ConfigureAwait(false); return(reqProc.ProcessActionResult(RawResult, AccountAction.Settings)); }
/// <summary> /// Modify device information /// </summary> /// <param name="device">Which device to use.</param> /// <param name="includeEntitites">Set this to false to not add entitites to response. (default: true)</param> /// <param name="callback">Async Callback.</param> /// <returns></returns> public static Account UpdateDeliveryDevice(this TwitterContext ctx, DeviceType device, bool includeEntitites, Action <TwitterAsyncResponse <User> > callback) { var accountUrl = ctx.BaseUrl + "account/update_delivery_device.json"; var reqProc = new AccountRequestProcessor <Account>(); ITwitterExecute exec = ctx.TwitterExecutor; exec.AsyncCallback = callback; var resultsJson = exec.PostToTwitter( accountUrl, new Dictionary <string, string> { { "device", device.ToString().ToLower() }, { "include_entities", includeEntitites.ToString().ToLower() } }, response => reqProc.ProcessActionResult(response, AccountAction.Settings)); Account acct = reqProc.ProcessActionResult(resultsJson, AccountAction.Settings); return(acct); }
/// <summary> /// Updates user's account settings /// </summary> /// <param name="trendLocationWeoid">WEOID for Trend Location the user is interested in.</param> /// <param name="sleepTimeEnabled">Turn on time periods when notifications won't be sent.</param> /// <param name="startSleepTime">Don't send notifications at this time or later this time. (hour from 00 to 23)</param> /// <param name="endSleepTime">Start sending notifications again after this time. (hour from 00 to 23)</param> /// <param name="timeZone">User's time zone.</param> /// <param name="lang">User's language.</param> /// <param name="callback">Async Callback.</param> /// <returns>Account information with Settings property populated.</returns> public static Account UpdateAccountSettings(this TwitterContext ctx, int?trendLocationWoeid, bool?sleepTimeEnabled, int?startSleepTime, int?endSleepTime, string timeZone, string lang, Action <TwitterAsyncResponse <User> > callback) { var accountUrl = ctx.BaseUrl + "account/settings.json"; if (trendLocationWoeid == null && sleepTimeEnabled == null && startSleepTime == null && endSleepTime == null && string.IsNullOrEmpty(timeZone) && string.IsNullOrEmpty(lang)) { throw new ArgumentException("At least one parameter must be provided as arguments, but none are specified.", NoInputParam); } var reqProc = new AccountRequestProcessor <Account>(); ITwitterExecute exec = ctx.TwitterExecutor; exec.AsyncCallback = callback; var resultsJson = exec.PostToTwitter( accountUrl, new Dictionary <string, string> { { "trend_location_woeid", trendLocationWoeid.ToString() }, { "sleep_time_enabled", sleepTimeEnabled.ToString() }, { "start_sleep_time", startSleepTime.ToString() }, { "end_sleep_time", endSleepTime.ToString() }, { "time_zone", timeZone }, { "lang", lang } }, response => reqProc.ProcessActionResult(response, AccountAction.Settings)); Account acct = reqProc.ProcessActionResult(resultsJson, AccountAction.Settings); return(acct); }
protected internal IRequestProcessor <T> CreateRequestProcessor <T>(string requestType) where T : class { var baseUrl = BaseUrl; IRequestProcessor <T> req; switch (requestType) { case "Account": req = new AccountRequestProcessor <T>(); break; case "Blocks": req = new BlocksRequestProcessor <T>(); break; case "ControlStream": req = new ControlStreamRequestProcessor <T> { SiteStreamUrl = SiteStreamUrl }; break; case "DirectMessage": req = new DirectMessageRequestProcessor <T>(); break; case "Favorites": req = new FavoritesRequestProcessor <T>(); break; case "Friendship": req = new FriendshipRequestProcessor <T>(); break; case "Geo": req = new GeoRequestProcessor <T>(); break; case "Help": req = new HelpRequestProcessor <T>(); break; case "List": req = new ListRequestProcessor <T>(); break; case "Mute": req = new MuteRequestProcessor <T>(); break; case "Raw": req = new RawRequestProcessor <T>(); break; case "SavedSearch": req = new SavedSearchRequestProcessor <T>(); break; case "Search": req = new SearchRequestProcessor <T>(); break; case "Status": req = new StatusRequestProcessor <T>(); break; case "Streaming": baseUrl = StreamingUrl; req = new StreamingRequestProcessor <T> { UserStreamUrl = UserStreamUrl, SiteStreamUrl = SiteStreamUrl, TwitterExecutor = TwitterExecutor }; break; case "Trend": req = new TrendRequestProcessor <T>(); break; case "User": req = new UserRequestProcessor <T>(); break; case "Vine": req = new VineRequestProcessor <T> { VineUrl = VineUrl }; break; default: throw new ArgumentException("Type, " + requestType + " isn't a supported LINQ to Twitter entity.", "requestType"); } if (baseUrl != null) { req.BaseUrl = baseUrl; } return(req); }
protected internal IRequestProcessor <T> CreateRequestProcessor <T>(string requestType) where T : class { string baseUrl = BaseUrl; IRequestProcessor <T> req; switch (requestType) { case nameof(Account): req = new AccountRequestProcessor <T>(); break; case nameof(AccountActivity): req = new AccountActivityRequestProcessor <T>(); break; case nameof(Blocks): req = new BlocksRequestProcessor <T>(); break; case nameof(ControlStream): req = new ControlStreamRequestProcessor <T> { SiteStreamUrl = SiteStreamUrl }; break; case nameof(DirectMessage): req = new DirectMessageRequestProcessor <T>(); break; case nameof(DirectMessageEvents): req = new DirectMessageEventsRequestProcessor <T>(); break; case nameof(Favorites): req = new FavoritesRequestProcessor <T>(); break; case nameof(Friendship): req = new FriendshipRequestProcessor <T>(); break; case nameof(Geo): req = new GeoRequestProcessor <T>(); break; case nameof(Help): req = new HelpRequestProcessor <T>(); break; case nameof(List): req = new ListRequestProcessor <T>(); break; case nameof(Media): req = new MediaRequestProcessor <T> { UploadUrl = UploadUrl }; break; case nameof(Mute): req = new MuteRequestProcessor <T>(); break; case nameof(Raw): req = new RawRequestProcessor <T>(); break; case nameof(SavedSearch): req = new SavedSearchRequestProcessor <T>(); break; case nameof(Search): req = new SearchRequestProcessor <T>(); break; case nameof(Status): req = new StatusRequestProcessor <T>(); break; case nameof(Streaming): baseUrl = StreamingUrl; req = new StreamingRequestProcessor <T> { UserStreamUrl = UserStreamUrl, SiteStreamUrl = SiteStreamUrl, TwitterExecutor = TwitterExecutor }; break; case nameof(Trend): req = new TrendRequestProcessor <T>(); break; case nameof(User): req = new UserRequestProcessor <T>(); break; case nameof(Vine): req = new VineRequestProcessor <T> { VineUrl = VineUrl }; break; case nameof(WelcomeMessage): req = new WelcomeMessageRequestProcessor <T>(); break; default: throw new ArgumentException($"Type, {requestType} isn't a supported LINQ to Twitter entity.", nameof(requestType)); } if (baseUrl != null) { req.BaseUrl = baseUrl; } return(req); }
/// <summary> /// factory method for returning a request processor /// </summary> /// <typeparam name="T">type of request</typeparam> /// <returns>request processor matching type parameter</returns> private IRequestProcessor CreateRequestProcessor(Expression expression, bool isEnumerable) { string requestType = string.Empty; if (expression != null) { if (isEnumerable) { requestType = expression.Type.GetGenericArguments()[0].Name; } else { requestType = expression.Type.Name; } } IRequestProcessor req; switch (requestType) { case "Account": req = new AccountRequestProcessor() { BaseUrl = BaseUrl }; break; case "Blocks": req = new BlocksRequestProcessor() { BaseUrl = BaseUrl }; break; case "DirectMessage": req = new DirectMessageRequestProcessor() { BaseUrl = BaseUrl }; break; case "Favorites": req = new FavoritesRequestProcessor() { BaseUrl = BaseUrl }; break; case "Friendship": req = new FriendshipRequestProcessor() { BaseUrl = BaseUrl }; break; case "SocialGraph": req = new SocialGraphRequestProcessor() { BaseUrl = BaseUrl }; break; case "Search": req = new SearchRequestProcessor() { BaseUrl = SearchUrl }; break; case "Status": req = new StatusRequestProcessor() { BaseUrl = BaseUrl }; break; case "Trend": req = new TrendRequestProcessor() { BaseUrl = SearchUrl }; break; case "User": req = new UserRequestProcessor() { BaseUrl = BaseUrl }; break; default: req = new StatusRequestProcessor() { BaseUrl = BaseUrl }; break; } Debug.Assert(req != null, "You you must assign a value to req."); return(req); }