Esempio n. 1
0
        public Task <TResult> UpdateAsync <TResult>(
            Func <CollectionSummary, TResult> onFound,
            Func <string, TResult> onFailure)
        {
            var collection = new CollectionCollection()
            {
                collection = this
            };

            return(EastFive.Api.AppSettings.Postman.ApiKey.ConfigurationString(
                       apiKey =>
            {
                Uri.TryCreate($"https://api.getpostman.com/collections/{collection.collection.id}", UriKind.Absolute, out Uri getCollectionsUri);
                return getCollectionsUri.HttpClientPutResourceAsync(collection,
                                                                    (CollectionSummaryParent collectionUpdated) =>
                {
                    return onFound(collectionUpdated.collection);
                },
                                                                    mutateRequest: (request) =>
                {
                    request.Headers.Add("X-API-Key", apiKey);
                    return request;
                },
                                                                    onFailureWithBody: (statusCode, body) => onFailure(body));
            }));
        }
Esempio n. 2
0
        public void CollectionGetTreeRootTest()
        {
            Flickr f = TestData.GetAuthInstance();
            CollectionCollection tree = f.CollectionsGetTree();

            Assert.IsNotNull(tree, "CollectionList should not be null.");
            Assert.AreNotEqual(0, tree.Count, "CollectionList.Count should not be zero.");
            //Assert.IsTrue(tree.Count > 1, "CollectionList.Count should be greater than 1.");

            foreach (Collection coll in tree)
            {
                Assert.IsNotNull(coll.CollectionId, "CollectionId should not be null.");
                Assert.IsNotNull(coll.Title, "Title should not be null.");
                Assert.IsNotNull(coll.Description, "Description should not be null.");
                Assert.IsNotNull(coll.IconSmall, "IconSmall should not be null.");
                Assert.IsNotNull(coll.IconLarge, "IconLarge should not be null.");

                Assert.AreNotEqual(0, coll.Sets.Count + coll.Collections.Count, "Should be either some sets or some collections.");

                foreach (CollectionSet set in coll.Sets)
                {
                    Assert.IsNotNull(set.SetId, "SetId should not be null.");
                }
            }
        }
Esempio n. 3
0
        public void CollectionGetSubTreeForSpecificUser()
        {
            string id = "78188-72157618817175751";
            Flickr f  = TestData.GetInstance();
            CollectionCollection tree = f.CollectionsGetTree(id, TestData.TestUserId);

            Assert.IsNotNull(tree, "CollectionList should not be null.");
            Assert.AreNotEqual(0, tree.Count, "CollectionList.Count should not be zero.");

            foreach (Collection coll in tree)
            {
                Assert.IsNotNull(coll.CollectionId, "CollectionId should not be null.");
                Assert.IsNotNull(coll.Title, "Title should not be null.");
                Assert.IsNotNull(coll.Description, "Description should not be null.");
                Assert.IsNotNull(coll.IconSmall, "IconSmall should not be null.");
                Assert.IsNotNull(coll.IconLarge, "IconLarge should not be null.");

                Assert.AreNotEqual(0, coll.Sets.Count + coll.Collections.Count, "Should be either some sets or some collections.");

                foreach (CollectionSet set in coll.Sets)
                {
                    Assert.IsNotNull(set.SetId, "SetId should not be null.");
                }
            }
        }
        public void CollectionsEmptyCollection()
        {
            // Get global collection
            CollectionCollection collections = AuthInstance.CollectionsGetTree("78188-72157618817175751", null);

            Assert.IsNotNull(collections);
            Assert.IsTrue(collections.Count > 0, "Global collection should be greater than zero.");

            var col = collections[0];

            Assert.AreEqual("Global Collection", col.Title, "Global Collection title should be correct.");

            Assert.IsNotNull(col.Collections, "Child collections property should not be null.");
            Assert.IsTrue(col.Collections.Count > 0, "Global collection should have child collections.");

            var subsol = col.Collections[0];

            Assert.IsNotNull(subsol.Collections, "Child collection Collections property should ne null.");
            Assert.AreEqual(0, subsol.Collections.Count, "Child collection should not have and sub collections.");
        }
        public IEnumerable <CollectionFlickr> GetSchema()
        {
            string cFlickrschemaTxt = FlickrSchemaCacheFilePath();

            if (File.Exists(cFlickrschemaTxt) && _reloadFromFlickr == false)
            {
                string readAllText = File.ReadAllText(cFlickrschemaTxt);
                List <CollectionFlickr> deserializeObject = JsonConvert.DeserializeObject <List <CollectionFlickr> >(readAllText);

                return(deserializeObject);
            }

            CollectionCollection collectionsGetTree = _flickr.CollectionsGetTree();

            List <CollectionFlickr> collections = new List <CollectionFlickr>(collectionsGetTree.Count);

            foreach (Collection collectionFlickr in collectionsGetTree)
            {
                CollectionFlickr flickr = new CollectionFlickr
                {
                    Id           = collectionFlickr.CollectionId,
                    Title        = collectionFlickr.Title,
                    AlbumsFlickr = new BindingList <AlbumFlickr>()
                };

                foreach (CollectionSet collectionSet in collectionFlickr.Sets)
                {
                    AlbumFlickr albumFlickr = new AlbumFlickr
                    {
                        Id    = collectionSet.SetId,
                        Title = collectionSet.Title
                    };
                    flickr.AlbumsFlickr.Add(albumFlickr);

                    _log.DebugFormat("Getting photos from album: [{0}]", albumFlickr.Title);
                    int page = 1;
                    PhotosetPhotoCollection photosetPhotoCollection = new PhotosetPhotoCollection();
                    int numberOfPhotos = _flickr.PhotosetsGetInfo(albumFlickr.Id).NumberOfPhotos;

                    while (true)
                    {
                        int count = 0;

                        if (numberOfPhotos >= 100)
                        {
                            count           = 100;
                            numberOfPhotos -= 100;
                        }
                        else
                        {
                            count          = numberOfPhotos;
                            numberOfPhotos = 0;
                        }

                        PhotosetPhotoCollection getPhotosetPhotoCollection = _flickr.PhotosetsGetPhotos(albumFlickr.Id, page, count);

                        foreach (Photo getPhoto in getPhotosetPhotoCollection)
                        {
                            photosetPhotoCollection.Add(getPhoto);
                        }

                        if (numberOfPhotos == 0)
                        {
                            break;
                        }

                        page++;
                    }

                    albumFlickr.PhotoList = new BindingList <PhotoFlickr>();

                    foreach (Photo photoFromSet in photosetPhotoCollection)
                    {
                        albumFlickr.PhotoList.Add(new PhotoFlickr
                        {
                            Id    = photoFromSet.PhotoId,
                            Title = photoFromSet.Title,
                            Tags  = photoFromSet.Tags.ToList()
                        });
                    }
                }

                collections.Add(flickr);
            }

            string serializeObject = JsonConvert.SerializeObject(collections);

            File.WriteAllText(cFlickrschemaTxt, serializeObject);

            return(collections);
        }