/// <summary> /// <para>Gets the list of public Templates to which the user has access.</para> /// <remarks>This operation supports pagination of results. For more information, see Paging.</remarks> /// <para>It mirrors To the following Smartsheet REST API method: GET /templates/public</para> /// </summary> /// <returns> the list of Templates (note that an empty list will be returned if there are none). </returns> /// <exception cref="System.InvalidOperationException"> if any argument is null or empty string </exception> /// <exception cref="InvalidRequestException"> if there is any problem with the REST API request </exception> /// <exception cref="AuthorizationException"> if there is any problem with the REST API authorization (access token) </exception> /// <exception cref="ResourceNotFoundException"> if the resource cannot be found </exception> /// <exception cref="ServiceUnavailableException"> if the REST API service is not available (possibly due To rate limiting) </exception> /// <exception cref="SmartsheetException"> if there is any other error during the operation </exception> public virtual PaginatedResult<Template> ListPublicTemplates(PaginationParameters paging) { StringBuilder path = new StringBuilder("templates/public"); if (paging != null) { path.Append(paging.ToQueryString()); } return this.ListResourcesWithWrapper<Template>(path.ToString()); }
/// <summary> /// <para>List of all Sheets owned by the members of the account (organization).</para> /// <para>It mirrors To the following Smartsheet REST API method: GET /users/sheets</para> /// </summary> /// <returns> the list of all Sheets owned by the members of the account (organization). </returns> /// <exception cref="System.InvalidOperationException"> if any argument is null or empty string </exception> /// <exception cref="InvalidRequestException"> if there is any problem with the REST API request </exception> /// <exception cref="AuthorizationException"> if there is any problem with the REST API authorization (access token) </exception> /// <exception cref="ResourceNotFoundException"> if the resource cannot be found </exception> /// <exception cref="ServiceUnavailableException"> if the REST API service is not available (possibly due To rate limiting) </exception> /// <exception cref="SmartsheetException"> if there is any other error during the operation </exception> public virtual PaginatedResult<Sheet> ListOrgSheets(PaginationParameters paging, DateTime? modifiedSince) { IDictionary<string, string> parameters = new Dictionary<string, string>(); if (paging != null) { parameters = paging.toDictionary(); } if (modifiedSince != null) { parameters.Add("modifiedSince", ((DateTime)modifiedSince).ToUniversalTime().ToString("o")); } return this.ListResourcesWithWrapper<Sheet>("users/sheets" + QueryUtil.GenerateUrl(null, parameters)); }
public void ResetCache() { Hashtag = null; PageCount = 1; Pagination = PaginationParameters.MaxPagesToLoad(1); IsLoading = true; Channel = null; HasMoreItems = true; Items.Clear(); ItemsX.Clear(); FirstRun = true; IsMine = false; RelatedHashtags.Clear(); }
public async void GetUserTagFeedTest(string username) { Assert.True(_authInfo.ApiInstance.IsUserAuthenticated); var result = await _authInfo.ApiInstance.GetUserTagsAsync(username, PaginationParameters.MaxPagesToLoad(5)); var tagFeed = result.Value; var anyMediaDuplicate = tagFeed.GroupBy(x => x.Code).Any(g => g.Count() > 1); //assert Assert.True(result.Succeeded); Assert.NotNull(tagFeed); Assert.False(anyMediaDuplicate); }
public async void GetFollowingRecentActivityFeedTest() { Assert.True(_authInfo.ApiInstance.IsUserAuthenticated); var getFeedResult = await _authInfo.ApiInstance.GetFollowingRecentActivityAsync(PaginationParameters.MaxPagesToLoad(5)); var folloowingRecentFeed = getFeedResult.Value; //assert Assert.True(getFeedResult.Succeeded); Assert.NotNull(folloowingRecentFeed); Assert.True(!folloowingRecentFeed.IsOwnActivity); }
public async void Comentarios(string username, IInstaApi api) { List <MaisCurtidas> MaisCurtidas = new List <MaisCurtidas>(); List <MaisCurtidas> MaisCurtidasAuxiliar = new List <MaisCurtidas>(); var publicacoes = await api.GetUserMediaAsync(username, PaginationParameters.MaxPagesToLoad(8)); foreach (var publicacao in publicacoes.Value.ToList()) { var chaveprimaria = publicacao.Pk; var foto = await api.GetMediaLikersAsync(chaveprimaria); foreach (var curtida in foto.Value.ToList()) { if (MaisCurtidas?.Any() != false) { //var teucu = MaisCurtidas.Where(q => q.nome == curtida.FullName); armazena a variavel no teucu if (MaisCurtidas.Any(q => q.nome == curtida.UserName)) { MaisCurtidas.FindAll(q => q.nome == curtida.UserName).ForEach(q => q.curtidas = q.curtidas + 1); } else { MaisCurtidas c1 = new MaisCurtidas(); c1.curtidas++; c1.nome = curtida.UserName; MaisCurtidasAuxiliar.Add(c1); } } else { MaisCurtidas c = new MaisCurtidas(); c.nome = curtida.UserName; c.curtidas = 1; MaisCurtidas.Add(c); } } foreach (var item in MaisCurtidasAuxiliar) { MaisCurtidas.Add(item); } MaisCurtidasAuxiliar.Clear(); } var maisCurtidasOrdenado = MaisCurtidas.OrderByDescending(q => q.curtidas); foreach (var item in maisCurtidasOrdenado) { Console.WriteLine("{0} --- {1}", item.nome, item.curtidas); } }
public async void GetUserLikeFeedTest() { Assert.True(_authInfo.ApiInstance.IsUserAuthenticated); var getFeedResult = await _authInfo.ApiInstance.GetLikeFeedAsync(PaginationParameters.MaxPagesToLoad(5)); var feed = getFeedResult.Value; var anyDuplicate = feed.GroupBy(x => x.Code).Any(g => g.Count() > 1); //assert Assert.True(getFeedResult.Succeeded); Assert.NotNull(feed); Assert.False(anyDuplicate); }
/// <summary> /// Get all user shoppable media by username /// </summary> /// <param name="username">Username</param> /// <param name="paginationParameters">Pagination parameters: next id and max amount of pages to load</param> /// <returns> /// <see cref="InstaMediaList" /> /// </returns> public async Task <IResult <InstaMediaList> > GetUserShoppableMediaAsync( string username, PaginationParameters paginationParameters) { InstaUserAuthValidator.Validate(userAuthValidate); var user = await instaApi.UserProcessor.GetUserAsync(username).ConfigureAwait(false); if (!user.Succeeded) { return(Result.Fail <InstaMediaList>("Unable to get user to load shoppable media")); } return(await GetUserShoppableMedia(user.Value.Pk, paginationParameters).ConfigureAwait(false)); }
public IActionResult GetOrganisation([FromRoute] string organisationUserId, [FromQuery] PaginationParameters paginationParameters) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = new JobApplicationManager(context, userManager).GetJobApplicationByOrganisationUserId(organisationUserId, hostingEnvironment.WebRootPath, paginationParameters.Skip, paginationParameters.Take); if (result.Data == null) { return(NoContent()); } return(Ok(new { success = result.Success, message = result.Message, data = result.Data })); }
public async Task DoShow() { var tagFeed = await _instaApi.GetTagFeedAsync("quadcopter", PaginationParameters.MaxPagesToLoad(5)); if (tagFeed.Succeeded) { Console.WriteLine( $"Tag feed items (in {tagFeed.Value.MediaItemsCount} pages) [{currentUser.Value.UserName}]: {tagFeed.Value.Medias.Count}"); foreach (var media in tagFeed.Value.Medias) { ConsoleUtils.PrintMedia("Tag feed", media, _maxDescriptionLength); } } }
/// <summary> /// Get user timeline feed (feed of recent posts from users you follow) asynchronously. /// </summary> /// <param name="paginationParameters">Pagination parameters: next id and max amount of pages to load</param> /// <returns> /// <see cref="InstaFeed" /> /// </returns> public async Task <IResult <InstaFeed> > GetUserTimelineFeedAsync(PaginationParameters paginationParameters) { UserAuthValidator.Validate(_userAuthValidate); var feed = new InstaFeed(); try { var userFeedUri = UriCreator.GetUserFeedUri(paginationParameters.NextId); var request = HttpHelper.GetDefaultRequest(HttpMethod.Get, userFeedUri, _deviceInfo); var response = await _httpRequestProcessor.SendAsync(request); var json = await response.Content.ReadAsStringAsync(); if (response.StatusCode != HttpStatusCode.OK) { return(Result.UnExpectedResponse <InstaFeed>(response, json)); } var feedResponse = JsonConvert.DeserializeObject <InstaFeedResponse>(json, new InstaFeedResponseDataConverter()); feed = ConvertersFabric.Instance.GetFeedConverter(feedResponse).Convert(); paginationParameters.NextId = feed.NextMaxId; paginationParameters.PagesLoaded++; while (feedResponse.MoreAvailable && !string.IsNullOrEmpty(paginationParameters.NextId) && paginationParameters.PagesLoaded < paginationParameters.MaximumPagesToLoad) { var nextFeed = await GetUserTimelineFeedAsync(paginationParameters); if (!nextFeed.Succeeded) { return(Result.Fail(nextFeed.Info, feed)); } feed.Medias.AddRange(nextFeed.Value.Medias); feed.Stories.AddRange(nextFeed.Value.Stories); paginationParameters.NextId = nextFeed.Value.NextMaxId; paginationParameters.PagesLoaded++; } return(Result.Success(feed)); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail(exception, feed)); } }
/// <summary> /// <para>Lists all user alternate emails.</para> /// <para>Mirrors to the following Smartsheet REST API method: GET /users/{userId}/alternateemails</para> /// </summary> /// <param name="userId"> the Id of the user </param> /// <param name="pagination"> the pagination</param> /// <returns> the list of all AlternateEmails </returns> /// <exception cref="System.InvalidOperationException"> if any argument is null or an empty string </exception> /// <exception cref="InvalidRequestException"> if there is any problem with the REST API request </exception> /// <exception cref="AuthorizationException"> if there is any problem with the REST API authorization (access token) </exception> /// <exception cref="ResourceNotFoundException"> if the resource cannot be found </exception> /// <exception cref="ServiceUnavailableException"> if the REST API service is not available (possibly due to rate limiting) </exception> /// <exception cref="SmartsheetException"> if there is any other error during the operation </exception> public PaginatedResult <AlternateEmail> ListAlternateEmails(long userId, PaginationParameters pagination) { StringBuilder path = new StringBuilder("users/" + userId + "/alternateemails"); IDictionary <string, string> parameters = new Dictionary <string, string>(); if (pagination != null) { parameters = pagination.toDictionary(); } path.Append(QueryUtil.GenerateUrl(null, parameters)); return(this.ListResourcesWithWrapper <AlternateEmail>(path.ToString())); }
/// <summary> /// <para>List of all Sheets owned by the members of the account (organization).</para> /// <para>It mirrors to the following Smartsheet REST API method: GET /users/sheets</para> /// </summary> /// <returns> the list of all Sheets owned by the members of the account (organization). </returns> /// <exception cref="System.InvalidOperationException"> if any argument is null or empty string </exception> /// <exception cref="InvalidRequestException"> if there is any problem with the REST API request </exception> /// <exception cref="AuthorizationException"> if there is any problem with the REST API authorization (access token) </exception> /// <exception cref="ResourceNotFoundException"> if the resource cannot be found </exception> /// <exception cref="ServiceUnavailableException"> if the REST API service is not available (possibly due to rate limiting) </exception> /// <exception cref="SmartsheetException"> if there is any other error during the operation </exception> public virtual PaginatedResult <Sheet> ListOrgSheets(PaginationParameters paging, DateTime?modifiedSince) { IDictionary <string, string> parameters = new Dictionary <string, string>(); if (paging != null) { parameters = paging.toDictionary(); } if (modifiedSince != null) { parameters.Add("modifiedSince", ((DateTime)modifiedSince).ToUniversalTime().ToString("o")); } return(this.ListResourcesWithWrapper <Sheet>("users/sheets" + QueryUtil.GenerateUrl(null, parameters))); }
public async void GetUserMediaListTest(string userToFetch) { Assert.True(_authInfo.ApiInstance.IsUserAuthenticated); var random = new Random(DateTime.Now.Millisecond); var posts = await _authInfo.ApiInstance.GetUserMediaAsync(userToFetch, PaginationParameters.MaxPagesToLoad(3)); var anyDuplicate = posts.Value.GroupBy(x => x.Code).Any(g => g.Count() > 1); Assert.NotNull(posts); Assert.Equal(userToFetch, posts.Value[random.Next(0, posts.Value.Count)].User.UserName); Assert.False(anyDuplicate); }
public void SetLV(/*PullToRefreshListView listView*/ ScrollViewer scrollViewer /*Controls.PullToRefreshPanel pullToRefreshPanel*/) { //LV = listView; Scroll = scrollViewer; //Scroll = listView.FindScrollViewer(); //Scroll = pullToRefreshPanel.FindScrollViewer(); if (Scroll != null) { Scroll.ViewChanging += Scroll_ViewChanging; } HasMoreItems = true; IsLoading = true; Pagination = PaginationParameters.MaxPagesToLoad(1); }
/// <summary> /// Get following list by username asynchronously /// </summary> /// <param name="username">Username</param> /// <param name="paginationParameters">Pagination parameters: next id and max amount of pages to load</param> /// <param name="searchQuery">Search string to locate specific followings</param> /// <returns> /// <see cref="InstaUserShortList" /> /// </returns> public async Task <IResult <InstaUserShortList> > GetUserFollowingAsync(string username, PaginationParameters paginationParameters, string searchQuery) { UserAuthValidator.Validate(_userAuthValidate); var following = new InstaUserShortList(); try { var user = await GetUserAsync(username); var uri = UriCreator.GetUserFollowingUri(user.Value.Pk, _user.RankToken, searchQuery, paginationParameters.NextId); var userListResponse = await GetUserListByUriAsync(uri); if (!userListResponse.Succeeded) { return(Result.Fail(userListResponse.Info, (InstaUserShortList)null)); } following.AddRange( userListResponse.Value.Items.Select(ConvertersFabric.Instance.GetUserShortConverter) .Select(converter => converter.Convert())); following.NextId = userListResponse.Value.NextMaxId; var pages = 1; while (!string.IsNullOrEmpty(following.NextId) && pages < paginationParameters.MaximumPagesToLoad) { var nextUri = UriCreator.GetUserFollowingUri(user.Value.Pk, _user.RankToken, searchQuery, userListResponse.Value.NextMaxId); userListResponse = await GetUserListByUriAsync(nextUri); if (!userListResponse.Succeeded) { return(Result.Fail(userListResponse.Info, following)); } following.AddRange( userListResponse.Value.Items.Select(ConvertersFabric.Instance.GetUserShortConverter) .Select(converter => converter.Convert())); pages++; following.NextId = userListResponse.Value.NextMaxId; } return(Result.Success(following)); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail(exception, following)); } }
public async Task <T> GetByPojas <T>(PaginationParameters obj = null, int PojasId = 0) { if (obj != null) { var result = await $"{Properties.Settings.Default.ApiUrl}{_ApiRoute}/bypojas/{PojasId}?PageNumber={obj.PageNumber}&PageSize={obj.PageSize}" .WithOAuthBearerToken("eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxIiwidW5pcXVlX25hbWUiOiJ1bWFfbG92ZSIsIm5iZiI6MTYxMDY1OTQ5MSwiZXhwIjoxNjQyMTk1NDg5LCJpYXQiOjE2MTA2NTk0OTF9._jHrgQkCHjJsp3vbSeIdP7LYGYrlg0FM_4TbFPNyMAymF5FkK_zAkxltei9QRB-Hk5p2UXs68JHjgU2b7VjO8g") .GetJsonAsync <T>(); return(result); } else { return(await $"{Properties.Settings.Default.ApiUrl}{_ApiRoute}".GetJsonAsync <T>()); } }
public void testToQueryString() { PaginationParameters parameters1 = new PaginationParameters(true, null, null); Assert.AreEqual("?includeAll=true", parameters1.ToQueryString()); PaginationParameters parameters2 = new PaginationParameters(true, 1, 1); Assert.AreEqual("?includeAll=true", parameters2.ToQueryString()); PaginationParameters parameters3 = new PaginationParameters(false, 1, 1); Assert.AreEqual("?includeAll=false&pageSize=1&page=1", parameters3.ToQueryString()); }
public async Task <IResult <InstaExploreFeed> > GetExploreFeedAsync(PaginationParameters paginationParameters) { var exploreFeed = new InstaExploreFeed(); try { var exploreUri = UriCreator.GetExploreUri(paginationParameters.NextId); var request = HttpHelper.GetDefaultRequest(HttpMethod.Get, exploreUri, _deviceInfo); var response = await _httpRequestProcessor.SendAsync(request); var json = await response.Content.ReadAsStringAsync(); if (response.StatusCode != HttpStatusCode.OK) { return(Result.UnExpectedResponse <InstaExploreFeed>(response, json)); } var feedResponse = JsonConvert.DeserializeObject <InstaExploreFeedResponse>(json, new InstaExploreFeedDataConverter()); exploreFeed = ConvertersFabric.Instance.GetExploreFeedConverter(feedResponse).Convert(); var nextId = feedResponse.Items.Medias.LastOrDefault(media => !string.IsNullOrEmpty(media.NextMaxId)) ?.NextMaxId; exploreFeed.Medias.PageSize = feedResponse.ResultsCount; paginationParameters.NextId = nextId; exploreFeed.NextId = nextId; while (feedResponse.MoreAvailable && !string.IsNullOrEmpty(paginationParameters.NextId) && paginationParameters.PagesLoaded < paginationParameters.MaximumPagesToLoad) { var nextFeed = await GetExploreFeedAsync(paginationParameters); if (!nextFeed.Succeeded) { return(Result.Fail(nextFeed.Info, exploreFeed)); } nextId = feedResponse.Items.Medias.LastOrDefault(media => !string.IsNullOrEmpty(media.NextMaxId)) ?.NextMaxId; exploreFeed.NextId = paginationParameters.NextId = nextId; paginationParameters.PagesLoaded++; exploreFeed.Medias.AddRange(nextFeed.Value.Medias); } exploreFeed.Medias.Pages = paginationParameters.PagesLoaded; return(Result.Success(exploreFeed)); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail(exception, exploreFeed)); } }
private async Task ExecuteQueueLikePhotosAsync(Queue queue, InstaBotContext db) { var tags = queue.LoadId.Split(' '); foreach (var tag in tags) { var top = await _api.GetExploreFeedAsync(PaginationParameters.MaxPagesToLoad(0)); var media = top.Value.Medias.FirstOrDefault(); //var foundPhotos = await _api.GetTagFeedAsync(tag, PaginationParameters.MaxPagesToLoad(0)); //var media = foundPhotos.Value.Medias.FirstOrDefault(); var isPhotoAlreadyLiked = db.UserActivityHistories.Any(x => x.PostedImageURI == media.InstaIdentifier && x.Queue.QueueType == QueueType.LikePhoto); if (isPhotoAlreadyLiked) { break; } await _api.LikeMediaAsync(media.InstaIdentifier); var rand = new Random(); var isNeedToComment = rand.Next(3); if (isNeedToComment == 1) { var randNumber = rand.Next(0, comments.Length); var instaComment = await _api.CommentMediaAsync(media.InstaIdentifier, comments[randNumber]); Console.WriteLine("Photo liked and commented!" + Environment.NewLine + instaComment.Info); } else { Console.WriteLine("Photo liked only!"); } queue.LastActivity = DateTime.UtcNow; db.UserActivityHistories.Add(new UserActivityHistory { Queue = queue, CreatedOn = DateTime.UtcNow, PostedImageURI = media.InstaIdentifier, }); await db.SaveChangesAsync(); Thread.Sleep(1000); } }
public ObjectResult GetAll([FromQuery] FilterParameters filter, [FromQuery] PaginationParameters pagination) { try { List <LogViewDTO> logs = _service.GetAll(pagination); logs = logs = FilterLogs(logs, filter); return(Ok(logs)); } catch (Exception ex) { return(StatusCode(500, $"Ocorreu um erro inesperado: {ex.Message}")); } }
public IActionResult Get([FromQuery] PaginationParameters paginationParameters) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = new UserCreditsManager(context, userManager).GetAllUserCredits(paginationParameters.Skip, paginationParameters.Take); if (result.Data == null) { return(NoContent()); } return(Ok(new { success = result.Success, message = result.Message, data = result.Data })); }
/// <summary> /// Get media comments /// </summary> /// <param name="mediaId">Media id</param> /// <param name="paginationParameters">Pagination parameters: next id and max amount of pages to load</param> public async Task <IResult <InstaCommentList> > GetMediaCommentsAsync(string mediaId, PaginationParameters paginationParameters) { UserAuthValidator.Validate(_userAuthValidate); try { var commentsUri = UriCreator.GetMediaCommentsUri(mediaId, paginationParameters.NextId); var request = HttpHelper.GetDefaultRequest(HttpMethod.Get, commentsUri, _deviceInfo); var response = await _httpRequestProcessor.SendAsync(request); var json = await response.Content.ReadAsStringAsync(); if (response.StatusCode != HttpStatusCode.OK) { return(Result.UnExpectedResponse <InstaCommentList>(response, json)); } var commentListResponse = JsonConvert.DeserializeObject <InstaCommentListResponse>(json); var pagesLoaded = 1; InstaCommentList Convert(InstaCommentListResponse commentsResponse) { return(ConvertersFabric.Instance.GetCommentListConverter(commentsResponse).Convert()); } while (commentListResponse.MoreComentsAvailable && !string.IsNullOrEmpty(commentListResponse.NextMaxId) && pagesLoaded < paginationParameters.MaximumPagesToLoad) { var nextComments = await GetCommentListWithMaxIdAsync(mediaId, commentListResponse.NextMaxId); if (!nextComments.Succeeded) { return(Result.Fail(nextComments.Info, Convert(commentListResponse))); } commentListResponse.NextMaxId = nextComments.Value.NextMaxId; commentListResponse.MoreComentsAvailable = nextComments.Value.MoreComentsAvailable; commentListResponse.Comments.AddRange(nextComments.Value.Comments); pagesLoaded++; } var converter = ConvertersFabric.Instance.GetCommentListConverter(commentListResponse); return(Result.Success(converter.Convert())); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail <InstaCommentList>(exception)); } }
/// <summary> /// Search places in facebook /// <para>Note: This works for non-facebook accounts too!</para> /// </summary> /// <param name="latitude">Latitude</param> /// <param name="longitude">Longitude</param> /// <param name="query">Query to search (city, country or ...)</param> /// <returns> /// <see cref="InstaPlaceList" /> /// </returns> public async Task <IResult <InstaPlaceList> > SearchPlacesAsync(double latitude, double longitude, string query) { UserAuthValidator.Validate(_userAuthValidate); try { // pagination is not working! var paginationParameters = PaginationParameters.MaxPagesToLoad(1); InstaPlaceList Convert(InstaPlaceListResponse placelistResponse) { return(ConvertersFabric.Instance.GetPlaceListConverter(placelistResponse).Convert()); } var places = await SearchPlaces(latitude, longitude, query, paginationParameters); if (!places.Succeeded) { return(Result.Fail <InstaPlaceList>(places.Info.Message)); } var placesResponse = places.Value; paginationParameters.NextId = placesResponse.RankToken; var pagesLoaded = 1; while (placesResponse.HasMore != null && placesResponse.HasMore.Value && !string.IsNullOrEmpty(placesResponse.RankToken) && pagesLoaded < paginationParameters.MaximumPagesToLoad) { var nextPlaces = await SearchPlaces(latitude, longitude, query, paginationParameters); if (!nextPlaces.Succeeded) { return(Result.Fail(nextPlaces.Info, Convert(nextPlaces.Value))); } placesResponse.RankToken = paginationParameters.NextId = nextPlaces.Value.RankToken; placesResponse.HasMore = nextPlaces.Value.HasMore; placesResponse.Items.AddRange(nextPlaces.Value.Items); placesResponse.Status = nextPlaces.Value.Status; pagesLoaded++; } return(Result.Success(ConvertersFabric.Instance.GetPlaceListConverter(placesResponse).Convert())); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail <InstaPlaceList>(exception.Message)); } }
public async Task <IResult <InstaUserShortList> > GetUserFollowersAsync(string username, PaginationParameters paginationParameters) { var followers = new InstaUserShortList(); try { var user = await GetUserAsync(username); var userFollowersUri = UriCreator.GetUserFollowersUri(user.Value.Pk, _user.RankToken, paginationParameters.NextId); var followersResponse = await GetUserListByUriAsync(userFollowersUri); if (!followersResponse.Succeeded) { Result.Fail(followersResponse.Info, (InstaUserList)null); } followers.AddRange( followersResponse.Value.Items.Select(ConvertersFabric.Instance.GetUserShortConverter) .Select(converter => converter.Convert())); followers.NextId = followersResponse.Value.NextMaxId; var pagesLoaded = 1; while (!string.IsNullOrEmpty(followersResponse.Value.NextMaxId) && pagesLoaded < paginationParameters.MaximumPagesToLoad) { var nextFollowersUri = UriCreator.GetUserFollowersUri(user.Value.Pk, _user.RankToken, followersResponse.Value.NextMaxId); followersResponse = await GetUserListByUriAsync(nextFollowersUri); if (!followersResponse.Succeeded) { return(Result.Success($"Not all pages were downloaded: {followersResponse.Info.Message}", followers)); } followers.AddRange( followersResponse.Value.Items.Select(ConvertersFabric.Instance.GetUserShortConverter) .Select(converter => converter.Convert())); pagesLoaded++; followers.NextId = followersResponse.Value.NextMaxId; } return(Result.Success(followers)); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail(exception, followers)); } }
/// <summary> /// Get user tags by username asynchronously /// <remarks>Returns media list containing tags</remarks> /// </summary> /// <param name="userId">User id (pk)</param> /// <param name="paginationParameters">Pagination parameters: next id and max amount of pages to load</param> /// <returns> /// <see cref="InstaMediaList" /> /// </returns> public async Task <IResult <InstaMediaList> > GetUserTagsAsync(long userId, PaginationParameters paginationParameters) { UserAuthValidator.Validate(_userAuthValidate); var userTags = new InstaMediaList(); try { var uri = UriCreator.GetUserTagsUri(userId, _user.RankToken, paginationParameters.NextId); var request = HttpHelper.GetDefaultRequest(HttpMethod.Get, uri, _deviceInfo); var response = await _httpRequestProcessor.SendAsync(request); var json = await response.Content.ReadAsStringAsync(); if (response.StatusCode != HttpStatusCode.OK) { return(Result.Fail("", (InstaMediaList)null)); } var mediaResponse = JsonConvert.DeserializeObject <InstaMediaListResponse>(json, new InstaMediaListDataConverter()); userTags.AddRange( mediaResponse.Medias.Select(ConvertersFabric.Instance.GetSingleMediaConverter) .Select(converter => converter.Convert())); userTags.NextId = paginationParameters.NextId = mediaResponse.NextMaxId; paginationParameters.PagesLoaded++; while (mediaResponse.MoreAvailable && !string.IsNullOrEmpty(paginationParameters.NextId) && paginationParameters.PagesLoaded < paginationParameters.MaximumPagesToLoad) { var nextMedia = await GetUserTagsAsync(userId, paginationParameters); if (!nextMedia.Succeeded) { return(nextMedia); } userTags.AddRange(nextMedia.Value); userTags.NextId = paginationParameters.NextId = nextMedia.Value.NextId; } return(Result.Success(userTags)); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail(exception, userTags)); } }
private async Task <IResult <InstaMediaList> > GetUserMediaAsync(long userId, PaginationParameters paginationParameters) { var mediaList = new InstaMediaList(); try { var instaUri = UriCreator.GetUserMediaListUri(userId, paginationParameters.NextId); var request = HttpHelper.GetDefaultRequest(HttpMethod.Get, instaUri, _deviceInfo); var response = await _httpRequestProcessor.SendAsync(request); var json = await response.Content.ReadAsStringAsync(); //Debug.WriteLine(json); if (response.StatusCode != HttpStatusCode.OK) { return(Result.UnExpectedResponse <InstaMediaList>(response, json)); } var mediaResponse = JsonConvert.DeserializeObject <InstaMediaListResponse>(json, new InstaMediaListDataConverter()); mediaList = ConvertersFabric.Instance.GetMediaListConverter(mediaResponse).Convert(); mediaList.NextMaxId = paginationParameters.NextId = mediaResponse.NextMaxId; paginationParameters.PagesLoaded++; while (mediaResponse.MoreAvailable && !string.IsNullOrEmpty(paginationParameters.NextId) && paginationParameters.PagesLoaded < paginationParameters.MaximumPagesToLoad) { var nextMedia = await GetUserMediaAsync(userId, paginationParameters); if (!nextMedia.Succeeded) { return(Result.Fail(nextMedia.Info, mediaList)); } mediaList.NextMaxId = paginationParameters.NextId = nextMedia.Value.NextMaxId; mediaList.AddRange(nextMedia.Value); } mediaList.Pages = paginationParameters.PagesLoaded; mediaList.PageSize = mediaResponse.ResultsCount; return(Result.Success(mediaList)); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail(exception, mediaList)); } }
public Task <IResult <InstaMediaList> > GetUserMedia(string user, int?maxPagesToLoad = 1) { PaginationParameters paginationParameters; if (maxPagesToLoad.HasValue) { paginationParameters = PaginationParameters.MaxPagesToLoad(maxPagesToLoad.Value); } else { paginationParameters = PaginationParameters.Empty; } return(_instaApi.GetUserMediaAsync(user, paginationParameters)); }
public async Task Execute(Queue queue, InstaBotContext db) { string tag = queue.LoadId; var instaTagFeed = await _instaApi.GetTagFeedAsync(tag, PaginationParameters.MaxPagesToLoad(0)); var lastPost = instaTagFeed.Value?.Medias?.FirstOrDefault(); if (instaTagFeed.Succeeded && lastPost != null) { await _instaApi.LikeMediaAsync(lastPost.InstaIdentifier); await UpdateQueueLastActivityAsync(queue, db); Console.WriteLine("LikeExecutor for " + queue.LoginData.Name); } }
public async void GetUserFollowingTest(string username) { Assert.True(_authInfo.ApiInstance.IsUserAuthenticated); var result = await _authInfo.ApiInstance.GetUserFollowingAsync(username, PaginationParameters.MaxPagesToLoad(5)); var followings = result.Value; var anyDuplicate = followings.GroupBy(x => x.Pk).Any(g => g.Count() > 1); //assert Assert.True(result.Succeeded); Assert.NotNull(followings); Assert.False(anyDuplicate); }
/// <summary> /// <para>List shares of a given object.</para> /// <para>It mirrors to the following Smartsheet REST API method:<br /> /// GET /workspaces/{workspaceId}/shares <br /> /// GET /sheets/{sheetId}/shares <br /> /// GET /sights/{sightId}/shares <br /> /// GET /reports/{reportId}/shares</para> /// </summary> /// <param name="objectId"> the object Id </param> /// <param name="paging"> the pagination request </param> /// <param name="shareScope"> when specified with a value of <see cref="ShareScope.Workspace"/>, the response will contain both item-level shares (scope=‘ITEM’) and workspace-level shares (scope='WORKSPACE’). </param> /// <returns> the list of Share objects (note that an empty list will be returned if there is none). </returns> /// <exception cref="System.InvalidOperationException"> if any argument is null or empty string </exception> /// <exception cref="InvalidRequestException"> if there is any problem with the REST API request </exception> /// <exception cref="AuthorizationException"> if there is any problem with the REST API authorization (access token) </exception> /// <exception cref="ResourceNotFoundException"> if the resource cannot be found </exception> /// <exception cref="ServiceUnavailableException"> if the REST API service is not available (possibly due to rate limiting) </exception> /// <exception cref="SmartsheetException"> if there is any other error during the operation </exception> public virtual PaginatedResult <Share> ListShares(long objectId, PaginationParameters paging, ShareScope shareScope) { IDictionary <string, string> parameters = new Dictionary <string, string>(); if (paging != null) { parameters = paging.toDictionary(); } if (ShareScope.Workspace.Equals(shareScope)) { parameters.Add("include", "workspaceShares"); } return(this.ListResourcesWithWrapper <Share>(MasterResourceType + "/" + objectId + "/shares" + QueryUtil.GenerateUrl(null, parameters))); }
public ApplicationResult <PageList <UserInfoDto> > GetAll(PaginationParameters paginationParameters) { var userListInfoReadModel = _userRepository.GetAll(paginationParameters); var userListMapped = Mapper.Map <IEnumerable <UserInfoDto> >(userListInfoReadModel); var userPagedList = PageList <UserInfoDto> .Create(userListMapped.AsQueryable(), paginationParameters.PageNumber, paginationParameters.PageSize); return(new ApplicationResult <PageList <UserInfoDto> >() { Data = userPagedList, IsSuccessful = true }); }
/// <summary> /// <para>List Folders of a given workspace.</para> /// /// <para>It mirrors To the following Smartsheet REST API method: GET /workspaces/{workspaceId}/Folders</para> /// </summary> /// <param name="workspaceId">the workspace Id</param> /// <param name="paging">the pagination information</param> /// <returns>the list of Folders (note that an empty list will be returned if no child folder is found), limited to the following attributes: /// <list type="bullet"> /// <item><description>id</description></item> /// <item><description>name</description></item> /// <item><description>permalink</description></item> /// </list> /// </returns> /// <exception cref="System.InvalidOperationException"> if any argument is null or empty string </exception> /// <exception cref="InvalidRequestException"> if there is any problem with the REST API request </exception> /// <exception cref="AuthorizationException"> if there is any problem with the REST API authorization (access token) </exception> /// <exception cref="ResourceNotFoundException"> if the resource cannot be found </exception> /// <exception cref="ServiceUnavailableException"> if the REST API service is not available (possibly due To rate limiting) </exception> /// <exception cref="SmartsheetException"> if there is any other error during the operation </exception> public virtual PaginatedResult<Folder> ListFolders(long workspaceId, PaginationParameters paging) { StringBuilder path = new StringBuilder("workspaces/" + workspaceId + "/folders"); if (paging != null) { path.Append(paging.ToQueryString()); } return this.ListResourcesWithWrapper<Folder>(path.ToString()); }
/// <summary> /// <para>List all Users.</para> /// <para>It mirrors To the following Smartsheet REST API method: GET /Users</para> /// </summary> /// <param name="emails">list of emails</param> /// <param name="paging"> the pagination</param> /// <returns> the list of all Users </returns> /// <exception cref="System.InvalidOperationException"> if any argument is null or empty string </exception> /// <exception cref="InvalidRequestException"> if there is any problem with the REST API request </exception> /// <exception cref="AuthorizationException"> if there is any problem with the REST API authorization (access token) </exception> /// <exception cref="ResourceNotFoundException"> if the resource cannot be found </exception> /// <exception cref="ServiceUnavailableException"> if the REST API service is not available (possibly due To rate limiting) </exception> /// <exception cref="SmartsheetException"> if there is any other error during the operation </exception> public virtual PaginatedResult<User> ListUsers(IEnumerable<string> emails, PaginationParameters paging) { StringBuilder path = new StringBuilder("users"); IDictionary<string, string> parameters = new Dictionary<string,string>(); if (paging != null) { parameters = paging.toDictionary(); } if (emails != null) { parameters.Add("email", string.Join(",", emails)); } path.Append(QueryUtil.GenerateUrl(null, parameters)); return this.ListResourcesWithWrapper<User>(path.ToString()); }
/// <summary> /// <para>List all Users.</para> /// <para>It mirrors To the following Smartsheet REST API method: GET /groups</para> /// <remarks>This operation supports pagination of results. For more information, see Paging.</remarks> /// </summary> /// <param name="paging"> the pagination</param> /// <returns> the list of all Users </returns> /// <exception cref="System.InvalidOperationException"> if any argument is null or empty string </exception> /// <exception cref="InvalidRequestException"> if there is any problem with the REST API request </exception> /// <exception cref="AuthorizationException"> if there is any problem with the REST API authorization (access token) </exception> /// <exception cref="ResourceNotFoundException"> if the resource cannot be found </exception> /// <exception cref="ServiceUnavailableException"> if the REST API service is not available (possibly due To rate limiting) </exception> /// <exception cref="SmartsheetException"> if there is any other error during the operation </exception> public virtual PaginatedResult<Group> ListGroups(PaginationParameters paging) { StringBuilder path = new StringBuilder("groups"); if (paging != null) { path.Append(paging.ToQueryString()); } return this.ListResourcesWithWrapper<Group>(path.ToString()); }
/// <summary> /// <para>List Folders under home.</para> /// /// <para>It mirrors To the following Smartsheet REST API method:<br /> /// GET /home/Folders</para> /// </summary> /// <returns>the list of Folders (note that an empty list will be returned if no child folder is found), limited to the following attributes: /// <list type="bullet"> /// <item><description>id</description></item> /// <item><description>name</description></item> /// <item><description>permalink</description></item> /// </list> /// </returns> /// <exception cref="System.InvalidOperationException"> if any argument is null or empty string </exception> /// <exception cref="InvalidRequestException"> if there is any problem with the REST API request </exception> /// <exception cref="AuthorizationException"> if there is any problem with the REST API authorization (access token) </exception> /// <exception cref="ResourceNotFoundException"> if the resource cannot be found </exception> /// <exception cref="ServiceUnavailableException"> if the REST API service is not available (possibly due To rate limiting) </exception> /// <exception cref="SmartsheetException"> if there is any other error during the operation </exception> public virtual PaginatedResult<Folder> ListFolders(PaginationParameters paging) { StringBuilder path = new StringBuilder("home/folders"); if (paging != null) { path.Append(paging.ToQueryString()); } return ListResourcesWithWrapper<Folder>(path.ToString()); }
/// <summary> /// <para>List all user alternate email(s).</para> /// <para>It mirrors to the following Smartsheet REST API method: GET /users/{userId}/alternateemails</para> /// </summary> /// <param name="userId"> the Id of the user </param> /// <param name="pagination"> the pagination</param> /// <returns> the list of all AlternateEmails </returns> /// <exception cref="System.InvalidOperationException"> if any argument is null or empty string </exception> /// <exception cref="InvalidRequestException"> if there is any problem with the REST API request </exception> /// <exception cref="AuthorizationException"> if there is any problem with the REST API authorization (access token) </exception> /// <exception cref="ResourceNotFoundException"> if the resource cannot be found </exception> /// <exception cref="ServiceUnavailableException"> if the REST API service is not available (possibly due To rate limiting) </exception> /// <exception cref="SmartsheetException"> if there is any other error during the operation </exception> public PaginatedResult<AlternateEmail> ListAlternateEmails(long userId, PaginationParameters pagination) { StringBuilder path = new StringBuilder("users/" + userId + "/alternateemails"); IDictionary<string, string> parameters = new Dictionary<string,string>(); if (pagination != null) { parameters = pagination.toDictionary(); } path.Append(QueryUtil.GenerateUrl(null, parameters)); return this.ListResourcesWithWrapper<AlternateEmail>(path.ToString()); }