示例#1
0
 /// <summary>
 /// Generate Tumblr API query string for posts
 /// </summary>
 /// <param name="tumblrDomain">Tumblr domain</param>
 /// <param name="postType">Tumblr post type</param>
 /// <param name="offset">Tumblr posts offset</param>
 /// <param name="limit">Tumblr post limit per document</param>
 /// <returns>Tumblr API query string for blog posts</returns>
 public static string GeneratePostTypeQueryUrl(string tumblrDomain, TumblrPostType postType, int offset = 0,
                                               int limit = (int)NumberOfPostsPerApiDocument.ApiV2)
 {
     return(string.Format(ApiUrl, WebHelper.RemoveTrailingBackslash(tumblrDomain), (postType == TumblrPostType.All) ?
                          PostQuery : new StringBuilder(PostQuery).Append("/").Append(postType.ToString().ToLower()).ToString(), ApiKey,
                          string.Format(Offset, offset.ToString()), string.Format(Limit, limit.ToString())));
 }
示例#2
0
        /// <summary>
        /// Generate Tumblr API query string for posts
        /// </summary>
        /// <param name="tumblrDomain">Tumblr domain</param>
        /// <param name="postType">Tumblr post type</param>
        /// <param name="offset">Tumblr posts offset</param>
        /// <param name="limit">Tumblr post limit per document</param>
        /// <returns>Tumblr API query string for blog posts</returns>
        public static string GeneratePostTypeQueryUrl(string tumblrDomain, TumblrPostType postType, int offset = 0, int limit = (int)NumberOfPostsPerApiDocument.ApiV2)
        {
            tumblrDomain = WebHelper.RemoveTrailingBackslash(tumblrDomain);

            string postQuery = (postType == TumblrPostType.All) ?
                               PostQuery : string.Concat(PostQuery, "/", postType.ToString().ToLower());

            return(string.Format(ApiUrl, tumblrDomain, postQuery, ApiKey, string.Format(Offset, offset.ToString()), string.Format(Limit, limit.ToString())));
        }
示例#3
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public bool GetTumblrBlogInfo()
 {
     try
     {
         TumblrPostType postType = PhotoPostOnly == true ? TumblrPostType.Photo : TumblrPostType.All;
         return(DocumentManager.GetRemoteBlogInfo(TumblrApiHelper.GeneratePostTypeQueryUrl(TumblrDomain, postType, 0, 1), Blog));
     }
     catch
     {
         return(false);
     }
 }
示例#4
0
        /// <summary>
        ///
        ///
        ///
        ///
        /// </summary>
        /// <param name="offset"></param>
        /// <returns></returns>
        private HashSet <TumblrPost> GetTumblrPostList(int offset = 0)
        {
            try
            {
                TumblrPostType postType = PhotoPostOnly == true ? TumblrPostType.Photo : TumblrPostType.All;
                var            query    = TumblrApiHelper.GeneratePostTypeQueryUrl(TumblrDomain, postType, offset);

                DocumentManager.GetRemoteDocument(query);

                if ((ApiVersion == TumblrApiVersion.V2Json && DocumentManager.JsonDocument != null))
                {
                    HashSet <TumblrPost> posts = DocumentManager.GetPostListFromDoc(TumblrPostType.All);
                    return(posts);
                }
                ProcessingStatusCode = ProcessingCode.UnableDownload;
                return(new HashSet <TumblrPost>());
            }
            catch
            {
                return(new HashSet <TumblrPost>());
            }
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tumblrPostType"></param>
        /// <returns></returns>
        public HashSet <TumblrPost> GetPostListFromDoc(TumblrPostType tumblrPostType)
        {
            try
            {
                HashSet <TumblrPost> postList = new HashSet <TumblrPost>();

                if (JsonDocument != null && JsonDocument.response != null && JsonDocument.response.posts != null)
                {
                    JArray            jPostArray = JsonDocument.response.posts;
                    HashSet <dynamic> jPostList  = jPostArray.ToObject <HashSet <dynamic> >();

                    foreach (dynamic jPost in jPostList)
                    {
                        TumblrPost post = new TumblrPost();

                        switch (tumblrPostType)
                        {
                        case TumblrPostType.Photo:
                            PostHelper.GeneratePhotoPost(ref post, jPost, ImageSize);
                            break;

                        default:
                            PostHelper.IncludeCommonPostFields(ref post, jPost);
                            break;
                        }

                        postList.Add(post);
                    }
                }

                return(postList);
            }
            catch
            {
                return(null);
            }
        }