Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="blog"></param>
        /// <param name="url"></param>
        /// <param name="apiMode"></param>
        /// <param name="offset"></param>
        /// <param name="limit"></param>
        public TumblrStatsManager(TumblrBlog blog = null, string url = null, TumblrApiVersion apiMode = TumblrApiVersion.V2Json, int offset = 0, int limit = 0)
        {
            DocumentManager            = new RemoteDocumentManager();
            ApiVersion                 = apiMode;
            DocumentManager.ApiVersion = apiMode;
            TotalPostsPerDocument      = (int)NumberOfPostsPerApiDocument.ApiV2;

            Blog = blog ?? ((url != null) ? new TumblrBlog(url) : null);

            if (Blog != null)
            {
                Blog.Posts = new HashSet <TumblrPost>();

                TumblrUrl    = WebHelper.RemoveTrailingBackslash(Blog.Url);
                TumblrDomain = WebHelper.GetDomainName(TumblrUrl);

                ApiQueryLimit  = limit;
                ApiQueryOffset = offset;

                TotalPostsPerDocument = (int)NumberOfPostsPerApiDocument.ApiV2; //20 for JSON, 50 for XML

                var values = Enum.GetValues(typeof(TumblrPostType)).Cast <TumblrPostType>();
                TypesCount = values.Count() - 3;

                // Get Blog Info
                DocumentManager.GetRemoteBlogInfo(TumblrApiHelper.GeneratePostTypeQueryUrl(TumblrDomain, TumblrPostType.All, 0, 1), Blog);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public bool GetTumblrBlogInfo()
 {
     try
     {
         return(DocumentManager.GetRemoteBlogInfo(TumblrApiHelper.GeneratePostTypeQueryUrl(TumblrDomain, TumblrPostType.Photo, 0, 1), Blog));
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public bool TumblrExists()
 {
     try
     {
         return(TumblrApiHelper.GeneratePostTypeQueryUrl(TumblrDomain, TumblrPostType.All, 0, 1).TumblrExists());
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 4
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);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="offset"></param>
        /// <returns></returns>
        private HashSet <TumblrPost> GetTumblrPhotoPostList(int offset = 0)
        {
            try
            {
                DocumentManager.GetRemoteDocument(TumblrApiHelper.GeneratePostTypeQueryUrl(TumblrDomain, TumblrPostType.Photo, offset));

                if ((ApiVersion == TumblrApiVersion.V2Json && DocumentManager.RemoteDocument != null))
                {
                    DocumentManager.ImageSize = ImageSize;
                    HashSet <TumblrPost> posts = DocumentManager.GetPostListFromDoc(TumblrPostType.Photo);
                    return(posts);
                }
                ProcessingStatusCode = ProcessingCode.UnableDownload;
                return(new HashSet <TumblrPost>());
            }
            catch
            {
                return(new HashSet <TumblrPost>());
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="blog"></param>
        /// <param name="url"></param>
        /// <param name="apiMode"></param>
        /// <param name="offset"></param>
        /// <param name="limit"></param>
        public TumblrStatsManager(TumblrBlog blog = null, string url = null, TumblrApiVersion apiMode = TumblrApiVersion.V2Json, int offset = 0, int limit = 0)
        {
            DocumentManager            = new DocumentManager();
            ApiVersion                 = apiMode;
            DocumentManager.ApiVersion = apiMode;
            TotalPostsPerDocument      = (int)NumberOfPostsPerApiDocument.ApiV2;

            Blog = blog ?? new TumblrBlog(url);

            Blog.Posts = new HashSet <TumblrPost>();

            TumblrUrl    = WebHelper.RemoveTrailingBackslash(Blog.Url);
            TumblrDomain = WebHelper.GetDomainName(TumblrUrl);

            ApiQueryLimit  = limit;
            ApiQueryOffset = offset;

            TotalPostsPerDocument = (int)NumberOfPostsPerApiDocument.ApiV2; //20 for JSON, 50 for XML

            // Get Blog Info
            DocumentManager.GetRemoteBlogInfo(TumblrApiHelper.GeneratePostTypeQueryUrl(TumblrDomain, TumblrPostType.All, 0, 1), Blog);
        }
Exemplo n.º 7
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>());
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool GetTumblrStats()
        {
            var url = TumblrApiHelper.GeneratePostTypeQueryUrl(TumblrDomain, TumblrPostType.All, 0, 1);

            if (url.TumblrExists())

            {
                DocumentManager.GetRemoteDocument(url);
                TotalPostsOverall = DocumentManager.GetTotalPostCount();

                var postTypes = Enum.GetValues(typeof(TumblrPostType)).Cast <TumblrPostType>().ToHashSet();
                postTypes.RemoveWhere(type => type == TumblrPostType.All || type == TumblrPostType.Regular || type == TumblrPostType.Conversation);

                foreach (TumblrPostType type in postTypes)
                {
                    int TotalPostsForType = 0;
                    url = TumblrApiHelper.GeneratePostTypeQueryUrl(TumblrDomain, type, 0, 1);

                    if (url.TumblrExists())
                    {
                        DocumentManager.GetRemoteDocument(url);
                        TotalPostsForType = DocumentManager.GetTotalPostCount();

                        switch (type)
                        {
                        case TumblrPostType.Photo:
                            TotalPhotoPosts = TotalPostsForType;
                            break;

                        case TumblrPostType.Text:
                            TotalTextPosts = TotalPostsForType;
                            break;

                        case TumblrPostType.Video:
                            TotalVideoPosts = TotalPostsForType;
                            break;

                        case TumblrPostType.Audio:
                            TotalAudioPosts = TotalPostsForType;
                            break;

                        case TumblrPostType.Link:
                            TotalLinkPosts = TotalPostsForType;
                            break;

                        case TumblrPostType.Quote:
                            TotalQuotePosts = TotalPostsForType;
                            break;

                        case TumblrPostType.Chat:
                            TotalChatPosts = TotalPostsForType;
                            break;

                        case TumblrPostType.Answer:
                            TotalAnswerPosts = TotalPostsForType;
                            break;
                        }

                        PostTypesProcessedCount++;

                        ProcessingStatusCode = ProcessingCode.Ok;
                    }
                    else
                    {
                        ProcessingStatusCode = ProcessingCode.InvalidUrl;
                    }
                }
            }

            return(true);
        }