Пример #1
0
        /// <summary>Get posts from Tumblr API.</summary>
        /// <param name="blog">The blog to target.</param>
        /// <param name="published">if set to <c>true</c> [published].</param>
        /// <param name="drafts">if set to <c>true</c> [drafts].</param>
        /// <param name="queued">if set to <c>true</c> [queued].</param>
        /// <param name="forceUserAuth">if set to <c>true</c> [force user authentication].</param>
        /// <returns>JArray.</returns>
        public async Task <JArray> GetPostsFromTumblr(string blog, bool published, bool drafts, bool queued, bool forceUserAuth)
        {
            JArray posts = new JArray();

            using (TumblrClient tumblrClient = new TumblrClient(_httpClient, OauthSettings.ConsumerKey, OauthSettings.ConsumerSecret, _logger))
            {
                if (published)
                {
                    JArray publicPosts = await tumblrClient.GetPosts(blog, forceUserAuth);

                    posts.Merge(publicPosts);
                }
                if (drafts)
                {
                    JArray draftPosts = await tumblrClient.GetDrafts(blog);

                    posts.Merge(draftPosts);
                }
                if (queued)
                {
                    JArray queuedPosts = await tumblrClient.GetQueue(blog);

                    posts.Merge(queuedPosts);
                }
            }
            return(posts);
        }
Пример #2
0
        public Tags(IEnumerable <string> tags = null, bool caseSensitive = false, TumblrClient tumblrClient = null)
        {
            this.tags = new List <string>();

            postTags = new HashSet <string>();

            if (caseSensitive)
            {
                CaseSensitive = true;
            }

            if (tags != null)
            {
                foreach (var tag in tags)
                {
                    Add(tag);
                }
            }

            if (tumblrClient != null)
            {
                this.tumblrClient = tumblrClient;
            }

            LoadTagsFromPosts();
        }
Пример #3
0
        public TumblrClientTest()
        {
            var keyProvider = new Mock <IKeyProvider>();

            keyProvider.Setup(key => key.TumblrApiKey).Returns("test-api-key");
            _client = new TumblrClient(_webClient.Object, keyProvider.Object);
        }
Пример #4
0
        public FrAuthenticate(ServiceHost host)
        {
            InitializeComponent();

            tumblrClient = null;

            this.host = host;
        }
Пример #5
0
        public async Task UserInfo_Disposed()
        {
            tc = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, new Token(_accessKey, _accessSecret));

            tc.Dispose();

            var userInfo = await tc.GetUserInfoAsync();
        }
Пример #6
0
        public async Task DeletePost_Success()
        {
            tumblrClient = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, new Token(_accessKey, _accessSecret));

            await tumblrClient.DeletePostAsync("newtsharp.tumblr.com", DeletePostInfo.PostId);

            DeletePostInfo = null;
        }
Пример #7
0
        public async Task UserInfo_1()
        {
            tumblrClient = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, new Token(_accessKey, _accessSecret));

            var userInfo = await tumblrClient.GetUserInfoAsync();

            Assert.AreEqual(userInfo.Blogs[1].Name, "newtsharp");
        }
Пример #8
0
 static Tumblr()
 {
     BlogName = "ibestsimple";
     Client   = new TumblrClientFactory().Create <TumblrClient>(
         CONSUMER_KEY,
         CONSUMER_SECRET,
         new DontPanic.TumblrSharp.OAuth.Token(
             OAUTH_TOKEN, OAUTH_TOKEN_SECRET));
 }
Пример #9
0
        public Tags(TumblrClient tumblrClient)
        {
            this.tumblrClient = tumblrClient ?? throw new ArgumentNullException("tumblrClient");

            this.tags = new List <string>();

            postTags = new HashSet <string>();

            LoadTagsFromPosts();
        }
Пример #10
0
        public async Task CreatePost_Required_2()
        {
            tumblrClient = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, null);

            PostData postData = PostData.CreateText(_postText + _footnote, "Testpost", new List <string> {
                "NewTumblrSharp", "Test"
            });

            PostCreationInfo postCreationInfo = await tumblrClient.CreatePostAsync("newtsharp.tumblr.com", postData);
        }
Пример #11
0
        private async void btnTest_Click(object sender, EventArgs e)
        {
            // create TumblrClient
            tumblrClient = new TumblrClientFactory().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());
        }
Пример #12
0
        public Tumblr()
        {
            if (CONSUMER_KEY == "xxx")
            {
                Console.WriteLine("Change in sourcecode the consumerKey, etc...!");
                Console.WriteLine();

                throw new Exception();
            }

            this.client = new TumblrClientFactory().Create <TumblrClient>(CONSUMER_KEY, CONSUMER_SECRET, new Token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET));
        }
Пример #13
0
        public async Task CreatePost_Text_1()
        {
            tumblrClient = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, new Token(_accessKey, _accessSecret));

            PostData postData = PostData.CreateText(_postText + _footnote, "Testpost", new List <string> {
                "NewTumblrSharp", _version
            });

            PostCreationInfo postCreationInfo = await tumblrClient.CreatePostAsync("newtsharp.tumblr.com", postData);

            Assert.IsNotNull(postCreationInfo);

            Assert.AreNotEqual(postCreationInfo.PostId, 0);
        }
Пример #14
0
        public Tags(TumblrClient tumblrClient, bool caseSensitive = false, IEnumerable <string> tags = null) : this(tumblrClient)
        {
            if (caseSensitive)
            {
                CaseSensitive = true;
            }

            if (tags != null)
            {
                foreach (var tag in tags)
                {
                    Add(tag);
                }
            }
        }
Пример #15
0
        public async void GotCallback(string data)
        {
            Console.WriteLine("Get access token");
            Token accessToken = await _oAuthClient.GetAccessTokenAsync(_oAuthToken, data);

            Console.WriteLine("Loading without await...");
            this.Invoke(new Action(() =>
            {
                form1.groupBox1.Enabled = true;
                form1.textBox3.Text     = accessToken.Key;
                form1.textBox4.Text     = accessToken.Secret;
            }));

            Console.WriteLine("Build client");
            _tumblrClient = new TumblrClientFactory().Create <TumblrClient>(consumerKey, consumerSecret, accessToken);
            UserInfo info = await _tumblrClient.GetUserInfoAsync();

            this.Invoke(new Action(() =>
            {
                form1.groupBox2.Enabled = true;
                textBox5.Text           = info.Name;
                textBox6.Text           = info.Blogs.Length.ToString();
                textBox7.Text           = info.FollowingCount.ToString();
                textBox8.Text           = info.LikesCount.ToString();
            }));

            this.Invoke(new Action(() =>
            {
                form1.groupBox3.Enabled = true;

                /* add to ComboBox */
                comboBox1.Items.Add("Text");
                comboBox1.Items.Add("Answer");
                comboBox1.Items.Add("Audio");
                comboBox1.Items.Add("Chat");
                comboBox1.Items.Add("Link");
                comboBox1.Items.Add("Photo");
                comboBox1.Items.Add("Quote");
                comboBox1.Items.Add("Video");

                /* Add to PostCreationState */
                comboBox2.Items.Add("Draft");
                comboBox2.Items.Add("Private");
                comboBox2.Items.Add("Published");
                comboBox2.Items.Add("Queue");
                comboBox2.Items.Add("Submission");
            }));
        }
Пример #16
0
        private async void BtnPost_Click(object sender, EventArgs e)
        {
            EnabledForm(false);

            string blogName = cbBlogs.Text;

            string caption = TbCaption.Text;

            PostData postData = PostData.CreatePhoto(binaryFiles, caption, null, tags.ToList());

            var postCreationInfo = await TumblrClient.CreatePostAsync(blogName, postData);

            System.Diagnostics.Process.Start($"https://www.tumblr.com/blog/{blogName}");

            EnabledForm(true);
        }
Пример #17
0
        private async void BtnPost_Click(object sender, EventArgs e)
        {
            string blogName = cbBlogs.Text;

            string caption = TbCaption.Text;

            PostData postData = PostData.CreatePhoto(binaryFiles, caption, null, tags.ToList(), PostCreationState.Queue);

            if (CbDateTime.Checked)
            {
                postData.Publish_On = Convert.ToDateTime(TbDateTime.Text);
            }

            var postCreationInfo = await TumblrClient.CreatePostAsync(blogName, postData);

            System.Diagnostics.Process.Start($"https://www.tumblr.com/blog/{blogName}/queue");
        }
Пример #18
0
        public ActionResult Index(string id)
        {
            //use: http://localhost:62385/?id=samsonau
            //use: http://localhost:62385/?id=huskyhuddle
            id = id.IsEmpty() ? "samsonau" : id;

            var tc = new TumblrClient(new HmacSha1HashProvider(), "z35mVaZpxg4JC7IdJ1KB1GHYOqYXfwwnv0cIOlHafuMUZ7Tlat",
                                      "gn3rVOlvrYVjLZP4tYnxb1FXYNiFGFZt3twWotz84VeYb9oWbj");

            var qq = tc.GetPostsAsync(id);

            qq.Wait();

            var q = qq.Result;

            Photo[] photoSet = ((PhotoPost)(q.Result[0])).PhotoSet;
            return(View(photoSet));
        }
Пример #19
0
        public Tags(TumblrClient tumblrClient, bool caseSensitive = false, string tags = "") : this(tumblrClient)
        {
            if (caseSensitive)
            {
                CaseSensitive = true;
            }

            if (tags != string.Empty)
            {
                string regex = @"\B#(?<tag>[a-z0-9\s]*)";

                RegexOptions options = RegexOptions.Multiline;

                MatchCollection matches = Regex.Matches(tags, regex, options);

                foreach (Match match in matches)
                {
                    Add(match.Groups["tag"].Value);
                }
            }
        }
Пример #20
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app">IApplicationBuilder</param>
        /// <param name="env">IHostingEnvironment</param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Map("/Request", context =>
            {
                context.Run(async(subcontext) =>
                {
                    // create the callbackurl
                    string callbackUrl = subcontext.Response.HttpContext.Request.Scheme + "://" + subcontext.Response.HttpContext.Request.Host.ToString() + "/TumblrLogIn";

                    // ordering requesttoken
                    requestToken = await oAuthClient.GetRequestTokenAsync(callbackUrl);

                    // get the url for authorization
                    var lAuthorizeUrl = oAuthClient.GetAuthorizeUrl(requestToken);

                    // call the authorize url
                    subcontext.Response.Redirect(lAuthorizeUrl.AbsoluteUri);
                });
            });

            app.MapWhen(
                context => context.Request.Path.StartsWithSegments("/TumblrLogIn"),
                context =>
            {
                context.Run(async(subcontext) =>
                {
                    IQueryCollection query = subcontext.Request.Query;

                    query.TryGetValue("oauth_token", out StringValues oauth_token);
                    query.TryGetValue("oauth_verifier", out StringValues oauth_verifier);

                    // ordering accesstoken
                    accessToken = await oAuthClient.GetAccessTokenAsync(requestToken, oauth_token.ToString(), oauth_verifier.ToString());

                    // create tumblrclient
                    tumblrClient = new TumblrClientFactory().Create <TumblrClient>(CONSUMER_KEY, CONSUMER_SECRET, accessToken);

                    var userInfo = await tumblrClient.GetUserInfoAsync();

                    await subcontext.Response.WriteAsync($"<h1>Authenticate - Examples for Asp.Net</h1><p>User: {userInfo.Name}</p><p>Following: {userInfo.FollowingCount}</p>");
                });
            });

            app.Map("", context =>
            {
                context.Run(async(subcontext) =>
                {
                    if (CONSUMER_KEY == "xxx")
                    {
                        await subcontext.Response.WriteAsync("<h1>Authenticate - Examples for Asp.Net</h1><p>You must set the consumerkey and the consumersecret in the source code. Restart the project.</p>");
                    }
                    else
                    {
                        await subcontext.Response.WriteAsync("<h1>Authenticate - Examples for Asp.Net</h1><p>Login Tumblr</p><a href=\"Request\">LogIn</a>");
                    }
                });
            });
        }
Пример #21
0
 public TumblrClient_MethodenTest()
 {
     tumblrClient = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, new Token(_accessKey, _accessSecret));
 }
 public void ValidClientWithLogin()
 {
     var _ = new TumblrClient(new TumblrClientCredentials("xxx", "yyy"),
                              new TumblrCredentials("testkey", "testsecret"));
 }
 public void ValidClientCredsPasses()
 {
     var _ = new TumblrClient(new TumblrClientCredentials("xxx", "yyy"));
 }
Пример #24
0
 /// <summary>
 /// Initializes a new instance of the login form with a specified OAuth client.
 /// </summary>
 /// <param name="client">Instance of the OAuth client.</param>
 /// <param name="autoLogout">Disables saving and restoring authorization cookies in WebBrowser. Default: false.</param>
 /// <param name="loadUserInfo">Indicates the need to make a request for recive the user profile or not. Default: false.</param>
 public TumblrLogin(TumblrClient client, bool autoLogout = false, bool loadUserInfo = false) : base(client, autoLogout, loadUserInfo)
 {
     this.Width  = 845;
     this.Height = 540;
     this.Icon   = Properties.Resources.tumblr;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TumblrSharpClientWrapper"/> class.
 /// </summary>
 /// <param name="client">The Tumblr client.</param>
 public TumblrSharpClientWrapper(TumblrClient client)
 {
     _client = client;
 }
Пример #26
0
        public async Task CreatePost_Required_4()
        {
            tumblrClient = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, new Token(_accessKey, _accessSecret));

            PostCreationInfo postCreationInfo = await tumblrClient.CreatePostAsync("newtsharp.tumblr.com", PostData.CreateText());
        }
Пример #27
0
        public async Task UserInfo_Required()
        {
            tc = new TumblrClientFactory().Create <TumblrClient>(_consumerKey, _consumerSecret, null);

            var userInfo = await tc.GetUserInfoAsync();
        }
Пример #28
0
 public TumblrService(IOptions <TumblrOptions> options)
 {
     _client = new TumblrClientFactory().Create <TumblrClient>(
         options.Value.ConsumerKey,
         options.Value.ConsumerSecret);
 }
Пример #29
0
 /// <summary>
 /// create Tumblrservice
 /// </summary>
 /// <param name="clientFactory">IHttpClientFactory to create internal HttpClient</param>
 public MyTumblrService(IHttpClientFactory clientFactory)
 {
     _tc = new TumblrClientFactory().Create <TumblrClient>(clientFactory, Settings.CONSUMER_KEY, Settings.CONSUMER_SECRET, new Token(Settings.OAUTH_TOKEN, Settings.OAUTH_TOKEN_SECRET));
 }
Пример #30
0
 public TumblrService()
 {
     Client = new TumblrClientFactory().Create <TumblrClient>(CONSUMER_KEY, CONSUMER_SECRET, new DontPanic.TumblrSharp.OAuth.Token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET));
 }