Beispiel #1
0
 public async Task DeletePost_TumblrClient_1()
 {
     using (TumblrClient tc = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, null))
     {
         await tc.DeletePostAsync("newtsharp.tumblr.com", DeletePostInfo.PostId);
     }
 }
Beispiel #2
0
        async private void Run()
        {
            TumblrClient client = new TumblrClientFactory().Create <TumblrClient>(
                CONSUMER_KEY,
                CONSUMER_SECRET,
                new DontPanic.TumblrSharp.OAuth.Token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
                );

            UserInfo userInfo = await client.GetUserInfoAsync();

            Console.WriteLine("Primary Blog: {0}", userInfo.Name);
            Console.WriteLine("Following: {0}", userInfo.FollowingCount);
            Console.WriteLine("Likes: {0}\n", userInfo.LikesCount);

            foreach (UserBlogInfo blog in userInfo.Blogs)
            {
                BlogInfo blogInfo = null;
                if (blog.BlogType == BlogType.Public)
                {
                    try {
                        blogInfo = await client.GetBlogInfoAsync(blog.Name);
                    } catch (DontPanic.TumblrSharp.TumblrException e) {
                        // well boo =[
                    }
                }

                Console.Write("Blog: {0}", blog.Name);
                if (blog.IsPrimary)
                {
                    Console.Write(" [primary]");
                }
                if (blog.BlogType == BlogType.Private)
                {
                    Console.Write(" [private]");
                }
                if ((blogInfo != null) && blogInfo.IsNsfw)
                {
                    Console.WriteLine(" [nsfw]");
                }
                Console.Write("\n-----\n");

                Console.WriteLine("  Followers: {0}", blog.FollowersCount);
                Console.WriteLine("  Posts: {0}", (blogInfo != null) ? blogInfo.PostsCount : 0);

                if (blog.QueueCount > 0)
                {
                    Console.WriteLine("  Queue: {0}", blog.QueueCount);
                }

                if (blog.DraftsCount > 0)
                {
                    Console.WriteLine("  Drafts: {0}", blog.DraftsCount);
                }

                Console.Write("\n");
            }
        }
Beispiel #3
0
        public async Task DeletePost_TumblrClient_2()
        {
            using (TumblrClient tc = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, new Token(_accessKey, _accessSecret)))
            {
                tc.Dispose();

                await tc.DeletePostAsync("newtsharp.tumblr.com", DeletePostInfo.PostId);
            }
        }
Beispiel #4
0
        public async Task NoteConverter()
        {
            TumblrClient tc = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, new Token(_accessKey, _accessSecret));

            // find a post with notes
            PhotoPost notePost = null;

            bool findPostWithNotes = false;

            long currentID = 0;

            while (findPostWithNotes == false)
            {
                BasePost[] basePosts = await tc.GetDashboardPostsAsync(currentID, 0, 1, PostType.Photo, false, true);

                for (int i = 0; i < basePosts.Count(); i++)
                {
                    PhotoPost basePost = basePosts[i] as PhotoPost;

                    if (basePost.Notes?.Count() > 0)
                    {
                        findPostWithNotes = true;
                        notePost          = basePost;
                        break;
                    }
                    currentID = basePost.Id;
                }
            }

            // convert post
            string json = JsonConvert.SerializeObject(notePost, Formatting.Indented);

            // deserialize post
            PhotoPost jsonPost = JsonConvert.DeserializeObject <PhotoPost>(json);

            //testing
            for (int i = 0; i < notePost.Notes.Count(); i++)
            {
                BaseNote baseNote = notePost.Notes[i];
                BaseNote jsonNote = jsonPost.Notes[i];

                Assert.AreEqual(baseNote.AvatarShape, jsonNote.AvatarShape);
                Assert.AreEqual(baseNote.BlogName, jsonNote.BlogName);
                Assert.AreEqual(baseNote.BlogUrl, jsonNote.BlogUrl);
                Assert.AreEqual(baseNote.BlogUuid, jsonNote.BlogUuid);
                Assert.AreEqual(baseNote.Followed, jsonNote.Followed);
                Assert.AreEqual(baseNote.PostId, jsonNote.PostId);
                Assert.AreEqual(baseNote.ReblogParentBlogName, jsonNote.ReblogParentBlogName);
                Assert.AreEqual(baseNote.ReplyText, jsonNote.ReplyText);
                Assert.AreEqual(baseNote.Timestamp, jsonNote.Timestamp);
                Assert.AreEqual(baseNote.Type, jsonNote.Type);
            }
        }
Beispiel #5
0
        private async void btnTest_Click(object sender, EventArgs e)
        {
            // create TumblrClient
            TumblrClientFactory fTumblrFactory = new TumblrClientFactory();

            tumblrClient = fTumblrFactory.Create <TumblrClient>(eConsumerKey.Text, eConsumerSecret.Text, new Token(eAccessKey.Text, eAccessSecret.Text));

            // Queries user info
            var userInfo = await tumblrClient.GetUserInfoAsync();


            MessageBox.Show("Number of Blogs is you following: " + userInfo.FollowingCount.ToString());
        }
Beispiel #6
0
            public async Task GetBlogInfoAsync()
            {
                //instantiate the client factory
                var factory = new TumblrClientFactory();

                //create the client; TumblrClient implements IDisposable (to dispose
                //of the internal HttpClient)
                using (var client = factory.Create<TumblrClient>(consumerKey, consumerSecret, token))
                {
                    //gets the info for a blog; we can either pass the short blog name or
                    //the fully qualified blog name (<blog name>.tumblr.com)
                    var blogInfo = await client.GetBlogInfoAsync("thegetty");
                }
            }
Beispiel #7
0
        private static async Task <List <BasePost> > DownloadPostsData()
        {
            var factory = new TumblrClientFactory();
            var client  = factory.Create <TumblrClient>(Credentials.Key, Credentials.Secret);
            var posts   = new List <BasePost>();

            for (int i = 0; i < 1000; i += 20)
            {
                var next = await client.GetPostsAsync("malowiele", i, 20, PostType.Photo);

                posts.AddRange(next.Result.ToList());
            }

            return(posts);
        }
Beispiel #8
0
        public async Task TrailConverter()
        {
            TumblrClient tc = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, new Token(_accessKey, _accessSecret));

            // find a post with trials
            BasePost post = null;

            bool findPostWithTrials = false;

            long currentID = 0;

            while (findPostWithTrials == false)
            {
                BasePost[] basePosts = await tc.GetDashboardPostsAsync(currentID, 0, 20, PostType.All, false, true);

                for (int i = 0; i < 20; i++)
                {
                    BasePost basePost = basePosts[i];

                    if (basePost.Trails?.Count() > 0)
                    {
                        findPostWithTrials = true;
                        post = basePost;
                        break;
                    }

                    if (i == 19)
                    {
                        currentID = basePost.Id;
                    }
                }
            }

            // convert post
            string json = JsonConvert.SerializeObject(post, Formatting.Indented);

            // deserialize post
            BasePost jsonPost = JsonConvert.DeserializeObject <BasePost>(json);

            //testing
            for (int i = 0; i < post.Trails.Count(); i++)
            {
                Trail baseTrail = post.Trails[i];
                Trail jsonTrail = jsonPost.Trails[i];

                Assert.AreEqual(baseTrail, jsonTrail);
            }
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Follower sample!");

            // create TumblrClient
            TumblrClient tumblrClient = new TumblrClientFactory().Create <TumblrClient>(CONSUMER_KEY, CONSUMER_SECRET, new Token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET));

            // get your blogs
            var userInfo = tumblrClient.GetUserInfoAsync().GetAwaiter().GetResult();

            // display blogs
            Console.WriteLine();
            Console.WriteLine("Blogs:");

            int idx = -1;

            foreach (var blog in userInfo.Blogs)
            {
                idx++;
                Console.WriteLine(idx.ToString() + ". " + blog.Name);
            }

            //select a blog
            Console.WriteLine();
            Console.Write("select a blog (0-" + idx.ToString() + "): ");
            string blogName = userInfo.Blogs[Convert.ToUInt32(Console.ReadLine())].Name;

            // get first 20 follower
            BlogBase[] blogs = tumblrClient.GetFollowersAsync(blogName).GetAwaiter().GetResult().Result;

            // display follower
            Console.WriteLine();
            Console.WriteLine("first 20th follower:");
            foreach (var blog in blogs)
            {
                Console.WriteLine(blog.Name);
            }

            Console.ReadLine();
        }
Beispiel #10
0
        private async void Button1_Click(object sender, EventArgs e)
        {
            // creating oAuth-client
            OAuthClient oAuthClient = new OAuthClientFactory().Create(ConsumerKey.Text, ConsumerSecret.Text);

            // get requesttoken
            Token requestToken = await oAuthClient.GetRequestTokenAsync(_callbackUrl);

            // get the authorize Url
            Uri url = oAuthClient.GetAuthorizeUrl(requestToken);

            var verifierUrl = WebAuth.ShowDialog(url, _callbackUrl);

            Token accessToken = await oAuthClient.GetAccessTokenAsync(requestToken, verifierUrl.OriginalString);

            AccessKey.Text    = accessToken.Key;
            AccessSecret.Text = accessToken.Secret;

            Activate();

            UserInfo userInfo = null;

            try
            {
                var tc = new TumblrClientFactory().Create <TumblrClient>(ConsumerKey.Text, ConsumerSecret.Text, accessToken);
                userInfo = await tc.GetUserInfoAsync();
            }
            catch (Exception)
            {
                MessageBox.Show("Logon failure", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }


            MessageBox.Show($"Success! the name of your blog is {userInfo.Blogs[0].Name}", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Beispiel #11
0
        public async Task TrailsConverter()
        {
            TumblrClient tc = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, new Token(_accessKey, _accessSecret));

            // find a post with trials
            BasePost post = null;

            bool findPostWithTrials = false;

            long currentID = 0;

            while (findPostWithTrials == false)
            {
                BasePost[] basePosts = await tc.GetDashboardPostsAsync(currentID, 0, 20, PostType.All, false, true);

                for (int i = 0; i < 20; i++)
                {
                    BasePost basePost = basePosts[i];

                    if (basePost.Trails?.Count() > 0)
                    {
                        findPostWithTrials = true;
                        post = basePost;
                    }

                    if (i == 19)
                    {
                        currentID = basePost.Id;
                    }
                }
            }

            // convert post
            string json = JsonConvert.SerializeObject(post, Formatting.Indented);

            // deserialize post
            BasePost jsonPost = JsonConvert.DeserializeObject <BasePost>(json);

            //testing
            for (int i = 0; i < post.Trails.Count(); i++)
            {
                Trail baseTrail = post.Trails[i];
                Trail jsonTrail = jsonPost.Trails[i];

                Assert.AreEqual(baseTrail.Content, jsonTrail.Content);
                Assert.AreEqual(baseTrail.ContentRaw, jsonTrail.ContentRaw);

                Assert.AreEqual(baseTrail.Post.Id, jsonTrail.Post.Id);

                Assert.AreEqual(baseTrail.Blog.Active, jsonTrail.Blog.Active);
                Assert.AreEqual(baseTrail.Blog.CanBeFollowed, jsonTrail.Blog.CanBeFollowed);
                Assert.AreEqual(baseTrail.Blog.Name, jsonTrail.Blog.Name);
                Assert.AreEqual(baseTrail.Blog.ShareFollowing, jsonTrail.Blog.ShareFollowing);
                Assert.AreEqual(baseTrail.Blog.ShareLikes, jsonTrail.Blog.ShareLikes);

                Assert.AreEqual(baseTrail.Blog.Theme.AvatarShape, jsonTrail.Blog.Theme.AvatarShape);
                Assert.AreEqual(baseTrail.Blog.Theme.BackgroundColor, jsonTrail.Blog.Theme.BackgroundColor);
                Assert.AreEqual(baseTrail.Blog.Theme.BodyFont, jsonTrail.Blog.Theme.BodyFont);
                Assert.AreEqual(baseTrail.Blog.Theme.HeaderBounds, jsonTrail.Blog.Theme.HeaderBounds);
                Assert.AreEqual(baseTrail.Blog.Theme.HeaderFocusHeight, jsonTrail.Blog.Theme.HeaderFocusHeight);
                Assert.AreEqual(baseTrail.Blog.Theme.HeaderFocusWidth, jsonTrail.Blog.Theme.HeaderFocusWidth);
                Assert.AreEqual(baseTrail.Blog.Theme.HeaderFullHeight, jsonTrail.Blog.Theme.HeaderFullHeight);
                Assert.AreEqual(baseTrail.Blog.Theme.HeaderFullWidth, jsonTrail.Blog.Theme.HeaderFullWidth);
                Assert.AreEqual(baseTrail.Blog.Theme.HeaderImage, jsonTrail.Blog.Theme.HeaderImage);
                Assert.AreEqual(baseTrail.Blog.Theme.HeaderImageFocused, jsonTrail.Blog.Theme.HeaderImageFocused);
                Assert.AreEqual(baseTrail.Blog.Theme.HeaderImageScaled, jsonTrail.Blog.Theme.HeaderImageScaled);
                Assert.AreEqual(baseTrail.Blog.Theme.HeaderStretch, jsonTrail.Blog.Theme.HeaderStretch);
                Assert.AreEqual(baseTrail.Blog.Theme.LinkColor, jsonTrail.Blog.Theme.LinkColor);
                Assert.AreEqual(baseTrail.Blog.Theme.ShowAvatar, jsonTrail.Blog.Theme.ShowAvatar);
                Assert.AreEqual(baseTrail.Blog.Theme.ShowDescription, jsonTrail.Blog.Theme.ShowDescription);
                Assert.AreEqual(baseTrail.Blog.Theme.ShowHeaderImage, jsonTrail.Blog.Theme.ShowHeaderImage);
                Assert.AreEqual(baseTrail.Blog.Theme.ShowTitle, jsonTrail.Blog.Theme.ShowTitle);
                Assert.AreEqual(baseTrail.Blog.Theme.TitleColor, jsonTrail.Blog.Theme.TitleColor);
                Assert.AreEqual(baseTrail.Blog.Theme.TitleFont, jsonTrail.Blog.Theme.TitleFont);
                Assert.AreEqual(baseTrail.Blog.Theme.TitleFontWeight, jsonTrail.Blog.Theme.TitleFontWeight);
            }
        }
Beispiel #12
0
 public void TumblrClient_Create_NotValid_3()
 {
     var tc = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, new Token(null, _accessSecret));
 }
Beispiel #13
0
 public void TumblrClient_Create_Empty_3()
 {
     var tc = new TumblrClientFactory().Create <TumblrClient>(string.Empty, _consumerSecret);
 }
Beispiel #14
0
 public void TumblrClient_Create_Empty_2()
 {
     var tc = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, string.Empty);
 }
Beispiel #15
0
 public void TumblrClient_Create_Empty_1()
 {
     var tc = new TumblrClientFactory().Create <TumblrClient>(string.Empty, string.Empty);
 }
Beispiel #16
0
 public void TumblrClient_Create_Null_2()
 {
     var tc = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, null);
 }
Beispiel #17
0
 public void TumblrClient_Create_Null_1()
 {
     var tc = new TumblrClientFactory().Create <TumblrClient>(null, null);
 }
Beispiel #18
0
 public void TumblrClient_Create_Null_3()
 {
     var tc = new TumblrClientFactory().Create <TumblrClient>(null, _consumerKey, _consumerSecret);
 }