tumblr_client_faraday_0_8 0.6.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/LICENSE.md +26 -0
- data/README.md +72 -0
- data/Rakefile +10 -0
- data/bin/tumblr +33 -0
- data/lib/tumblr/blog.rb +57 -0
- data/lib/tumblr/client.rb +26 -0
- data/lib/tumblr/config.rb +36 -0
- data/lib/tumblr/connection.rb +23 -0
- data/lib/tumblr/helpers.rb +14 -0
- data/lib/tumblr/post.rb +113 -0
- data/lib/tumblr/request.rb +35 -0
- data/lib/tumblr/request/oauth.rb +72 -0
- data/lib/tumblr/tagged.rb +18 -0
- data/lib/tumblr/user.rb +40 -0
- data/lib/tumblr_client.rb +11 -0
- data/tumblr.gemspec +22 -0
- metadata +160 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2012, John Bunting, Tumblr, Inc.
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer in the
|
11
|
+
documentation and/or other materials provided with the distribution.
|
12
|
+
* Neither the name of Tumblr, Inc. nor the names of its contributors may
|
13
|
+
be used to endorse or promote products derived from this software without
|
14
|
+
specific prior written permission.
|
15
|
+
* This license can change at any time.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
21
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
23
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
24
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
25
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Tumblr Ruby Gem
|
2
|
+
|
3
|
+
This is a ruby wrapper for the Tumblr v2 API. There should be support for all endpoints
|
4
|
+
currently available on the [Tumblr API](http://www.tumblr.com/docs/en/api/v2).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
gem install tumblr_client
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
First and foremost, this gem will *not* do a three legged oauth request for you. It is just a wrapper to help make
|
13
|
+
your life easier when using the v2 api. If you need to do the full oauth workflow, then please check out the
|
14
|
+
[Ruby OAuth Gem](http://oauth.rubyforge.org/).
|
15
|
+
|
16
|
+
### Configuration
|
17
|
+
|
18
|
+
Configuration for the gem is actually pretty easy:
|
19
|
+
|
20
|
+
Tumblr.configure do |config|
|
21
|
+
config.consumer_key = "consumer_key"
|
22
|
+
config.consumer_secret = "consumer_secret"
|
23
|
+
config.oauth_token = "access_token"
|
24
|
+
config.oauth_token_secret = "access_token_secret"
|
25
|
+
end
|
26
|
+
|
27
|
+
Once you have your configuration squared away it's time to make some requests!
|
28
|
+
|
29
|
+
>> client = Tumblr.new
|
30
|
+
|
31
|
+
That's it! You now have a client that can make any request to the Tumblr API.
|
32
|
+
|
33
|
+
### Some quick examples
|
34
|
+
|
35
|
+
Getting user information:
|
36
|
+
|
37
|
+
>> client.info
|
38
|
+
|
39
|
+
Getting a specific blog's posts and type:
|
40
|
+
|
41
|
+
#Grabbing a specific blogs posts
|
42
|
+
>> client.posts("codingjester.tumblr.com")
|
43
|
+
|
44
|
+
#Grabbing only the last 10 photos off the blog
|
45
|
+
>> client.posts("codingjester.tumblr.com", :type => "photo", :limit => 10)
|
46
|
+
|
47
|
+
|
48
|
+
Posting some photos to Tumblr:
|
49
|
+
|
50
|
+
#Uploads a great photoset
|
51
|
+
>> client.photo("codingjester.tumblr.com", {:data => ['/path/to/pic.jpg', '/path/to/pic.jpg']})
|
52
|
+
|
53
|
+
### The irb Console
|
54
|
+
|
55
|
+
Finally, there is an irb console packaged with the gem that should help you test any calls you want to make.
|
56
|
+
The magic here is that you have a ```.tumblr``` file in your home directory. Inside this file it's just a basic
|
57
|
+
YAML layout with four lines:
|
58
|
+
|
59
|
+
consumer_key: "your_consumer_key"
|
60
|
+
consumer_secret: "your_consumer_secret"
|
61
|
+
oauth_token: "your_access_token"
|
62
|
+
oauth_token_secret: "your_access_token_secret"
|
63
|
+
|
64
|
+
From there, you should be able to run any of the above commands, with no problem! Just fire off the command ```tumblr``
|
65
|
+
from the terminal and you should be dropped into a console.
|
66
|
+
|
67
|
+
|
68
|
+
### Contributions and Pull Requests
|
69
|
+
|
70
|
+
No request is too small and I encourage everyone to get involved. As you can see, we're sorely lacking in tests! So
|
71
|
+
please if you would like to contribute, let me know and throw me a pull request!
|
72
|
+
|
data/Rakefile
ADDED
data/bin/tumblr
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.join File.dirname(__FILE__), '..', 'lib'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'tumblr_client'
|
5
|
+
require 'yaml'
|
6
|
+
require 'irb'
|
7
|
+
require 'irb/completion'
|
8
|
+
|
9
|
+
configuration = YAML.load_file File.join ENV['HOME'], '.tumblr' rescue {}
|
10
|
+
|
11
|
+
ENV['IRBRC'] = '.irbrc' if File.exists? '.irbrc'
|
12
|
+
|
13
|
+
Tumblr.configure do |config|
|
14
|
+
config.consumer_key = configuration["consumer_key"]
|
15
|
+
config.consumer_secret = configuration["consumer_secret"]
|
16
|
+
config.oauth_token = configuration["oauth_token"]
|
17
|
+
config.oauth_token_secret = configuration["oauth_token_secret"]
|
18
|
+
end
|
19
|
+
|
20
|
+
puts %q[
|
21
|
+
. .o8 oooo
|
22
|
+
.o8 "888 `888
|
23
|
+
.o888oo oooo oooo ooo. .oo. .oo. 888oooo. 888 oooo d8b
|
24
|
+
888 `888 `888 `888P"Y88bP"Y88b d88' `88b 888 `888""8P
|
25
|
+
888 888 888 888 888 888 888 888 888 888
|
26
|
+
888 . 888 888 888 888 888 888 888 888 888 .o.
|
27
|
+
"888" `V88V"V8P' o888o o888o o888o `Y8bod8P' o888o d888b Y8P
|
28
|
+
|
29
|
+
]
|
30
|
+
|
31
|
+
ARGV.clear
|
32
|
+
IRB.start
|
33
|
+
exit!
|
data/lib/tumblr/blog.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Tumblr
|
2
|
+
class Client
|
3
|
+
module Blog
|
4
|
+
|
5
|
+
@@standard_options = [:type, :id, :tag, :limit, :offset, :reblog_info, :notes_info, :filter]
|
6
|
+
#
|
7
|
+
#Gets the info about the blog
|
8
|
+
#
|
9
|
+
def blog_info(blog_name)
|
10
|
+
get("v2/blog/#{blog_name}/info", {:api_key => Tumblr::consumer_key})
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
#Gets the avatar of specified size
|
15
|
+
#Defaults to 64
|
16
|
+
#
|
17
|
+
def avatar(blog_name, size=64)
|
18
|
+
get("v2/blog/#{blog_name}/avatar", {:size => size})
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Gets the list of followers for the blog
|
23
|
+
#
|
24
|
+
def followers(blog_name, options={})
|
25
|
+
if valid_options([:limit, :offset], options)
|
26
|
+
get("v2/blog/#{blog_name}/followers", options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def posts(blog_name, options={})
|
31
|
+
url = "v2/blog/#{blog_name}/posts"
|
32
|
+
|
33
|
+
if options.has_key?(:type)
|
34
|
+
url = "#{url}/#{options[:type]}"
|
35
|
+
end
|
36
|
+
|
37
|
+
params = {:api_key => Tumblr::consumer_key}
|
38
|
+
unless options.empty?
|
39
|
+
params.merge!(options)
|
40
|
+
end
|
41
|
+
get(url, params)
|
42
|
+
end
|
43
|
+
|
44
|
+
def queue(blog_name)
|
45
|
+
get("v2/blog/#{blog_name}/posts/queue", {})
|
46
|
+
end
|
47
|
+
|
48
|
+
def draft(blog_name)
|
49
|
+
get("v2/blog/#{blog_name}/posts/draft", {})
|
50
|
+
end
|
51
|
+
|
52
|
+
def submissions(blog_name)
|
53
|
+
get("v2/blog/#{blog_name}/posts/submission", {})
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'tumblr/blog'
|
2
|
+
require 'tumblr/user'
|
3
|
+
require 'tumblr/request'
|
4
|
+
require 'tumblr/connection'
|
5
|
+
require 'tumblr/post'
|
6
|
+
require 'tumblr/tagged'
|
7
|
+
require 'tumblr/helpers'
|
8
|
+
|
9
|
+
module Tumblr
|
10
|
+
class Client
|
11
|
+
include Tumblr::Request
|
12
|
+
include Tumblr::Client::Blog
|
13
|
+
include Tumblr::Client::User
|
14
|
+
include Tumblr::Client::Post
|
15
|
+
include Tumblr::Client::Tagged
|
16
|
+
include Tumblr::Client::Helper
|
17
|
+
include Tumblr::Connection
|
18
|
+
|
19
|
+
def initialize(attrs= {})
|
20
|
+
attrs = Tumblr.options.merge(attrs)
|
21
|
+
Config::VALID_OPTIONS_KEYS.each do |key|
|
22
|
+
instance_variable_set("@#{key}".to_sym, attrs[key])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Tumblr
|
2
|
+
|
3
|
+
module Config
|
4
|
+
|
5
|
+
VALID_OPTIONS_KEYS = [
|
6
|
+
:consumer_key,
|
7
|
+
:consumer_secret,
|
8
|
+
:oauth_token,
|
9
|
+
:oauth_token_secret
|
10
|
+
]
|
11
|
+
|
12
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
13
|
+
|
14
|
+
def configure
|
15
|
+
yield self
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def options
|
20
|
+
options = {}
|
21
|
+
VALID_OPTIONS_KEYS.each{ |k| options[k] = send(k) }
|
22
|
+
options
|
23
|
+
end
|
24
|
+
|
25
|
+
def credentials
|
26
|
+
{
|
27
|
+
:consumer_key => consumer_key,
|
28
|
+
:consumer_secret => consumer_secret,
|
29
|
+
:token => oauth_token,
|
30
|
+
:token_secret => oauth_token_secret
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'tumblr/request/oauth'
|
4
|
+
|
5
|
+
module Tumblr
|
6
|
+
module Connection
|
7
|
+
def connection(options={})
|
8
|
+
default_options = {
|
9
|
+
:headers => {
|
10
|
+
:accept => "application/json",
|
11
|
+
:user_agent => "Tumblr v1.0"
|
12
|
+
},
|
13
|
+
:url => "http://api.tumblr.com/"
|
14
|
+
}
|
15
|
+
Faraday.new("http://api.tumblr.com/", default_options.merge(options)) do |builder|
|
16
|
+
builder.use Tumblr::Request::TumblrOAuth, Tumblr::credentials if not Tumblr::credentials.empty?
|
17
|
+
builder.use Faraday::Request::UrlEncoded
|
18
|
+
builder.use FaradayMiddleware::ParseJson, :content_type => "application/json"
|
19
|
+
builder.use Faraday::Adapter::NetHttp
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Tumblr
|
2
|
+
class Client
|
3
|
+
module Helper
|
4
|
+
|
5
|
+
def valid_options(valid_opts, opts)
|
6
|
+
bad_opts = opts.select { |val| !valid_opts.include?(val) }
|
7
|
+
if !bad_opts.empty?
|
8
|
+
raise Exception, "Invalid options passed, Only #{valid_opts} allowed."
|
9
|
+
end
|
10
|
+
return true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/tumblr/post.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
module Tumblr
|
2
|
+
class Client
|
3
|
+
module Post
|
4
|
+
|
5
|
+
@@standard_post_options = [:state, :tags, :tweet, :date, :markdown, :slug]
|
6
|
+
|
7
|
+
def edit(blog_name, options={})
|
8
|
+
post("v2/blog/#{blog_name}/post/edit", options)
|
9
|
+
end
|
10
|
+
|
11
|
+
#Don't be lazy and create a nice interface
|
12
|
+
def reblog(blog_name, options={})
|
13
|
+
post("v2/blog/#{blog_name}/post/reblog", options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete(blog_name, id)
|
17
|
+
post("v2/blog/#{blog_name}/post/delete", {:id => id})
|
18
|
+
end
|
19
|
+
|
20
|
+
def photo(blog_name, options={})
|
21
|
+
valid_opts = @@standard_post_options + [:caption, :link, :data, :source, :photoset_layout]
|
22
|
+
if valid_options(valid_opts, options)
|
23
|
+
options[:type] = "photo"
|
24
|
+
if (options.has_key?(:data) && options.has_key?(:source))
|
25
|
+
raise Exception, "You can only use one parameter, either source or data."
|
26
|
+
end
|
27
|
+
if options.has_key?(:source) && options[:source].kind_of?(Array)
|
28
|
+
count = 0
|
29
|
+
options[:source].each do |src|
|
30
|
+
options["source[#{count}]"] = src
|
31
|
+
count += 1
|
32
|
+
end
|
33
|
+
options.delete(:source)
|
34
|
+
end
|
35
|
+
if options.has_key?(:data)
|
36
|
+
#Probably can be refactored
|
37
|
+
if options[:data].kind_of?(Array)
|
38
|
+
count = 0
|
39
|
+
options[:data].each do |filepath|
|
40
|
+
options["data[#{count}]"] = File.open(filepath, 'rb').read()
|
41
|
+
count += 1
|
42
|
+
end
|
43
|
+
options.delete(:data)
|
44
|
+
else
|
45
|
+
options[:data] = File.open(options[:data],'rb').read()
|
46
|
+
end
|
47
|
+
end
|
48
|
+
post("v2/blog/#{blog_name}/post", options)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def quote(blog_name, options={})
|
53
|
+
valid_opts = @@standard_post_options + [:quote, :source]
|
54
|
+
if valid_options(valid_opts, options)
|
55
|
+
options[:type] = "quote"
|
56
|
+
post("v2/blog/#{blog_name}/post", options)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def text(blog_name, options={})
|
61
|
+
valid_opts = @@standard_post_options + [:title, :body]
|
62
|
+
if valid_options(valid_opts, options)
|
63
|
+
options[:type] = "text"
|
64
|
+
post("v2/blog/#{blog_name}/post", options)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def link(blog_name, options={})
|
69
|
+
valid_opts = @@standard_post_options + [:title, :url, :description]
|
70
|
+
if valid_options(valid_opts, options)
|
71
|
+
options[:type] = "link"
|
72
|
+
post("v2/blog/#{blog_name}/post", options)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def chat(blog_name, options={})
|
77
|
+
valid_opts = @@standard_post_options + [:title, :conversation]
|
78
|
+
if valid_options(valid_opts, options)
|
79
|
+
options[:type] = "chat"
|
80
|
+
post("v2/blog/#{blog_name}/post", options)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def audio(blog_name, options={})
|
85
|
+
valid_opts = @@standard_post_options + [:data, :caption, :external_url]
|
86
|
+
if valid_options(valid_opts, options)
|
87
|
+
options[:type] = "audio"
|
88
|
+
if (options.has_key?(:data) && options.has_key?(:external_url))
|
89
|
+
raise Exception, "You can only use one parameter, either data or external url."
|
90
|
+
end
|
91
|
+
if(options.has_key?(:data))
|
92
|
+
options[:data] = File.open(options[:data],'rb').read()
|
93
|
+
end
|
94
|
+
post("v2/blog/#{blog_name}/post", options)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def video(blog_name, options={})
|
99
|
+
valid_opts = @@standard_post_options + [:data, :embed, :caption]
|
100
|
+
if valid_options(valid_opts, options)
|
101
|
+
options[:type] = "video"
|
102
|
+
if (options.has_key?(:data) && options.has_key?(:embed))
|
103
|
+
raise Exception, "You can only use one parameter, either data or embed."
|
104
|
+
end
|
105
|
+
if(options.has_key?(:data))
|
106
|
+
options[:data] = File.open(options[:data],'rb').read()
|
107
|
+
end
|
108
|
+
post("v2/blog/#{blog_name}/post", options)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Tumblr
|
4
|
+
module Request
|
5
|
+
|
6
|
+
#Performs a get request
|
7
|
+
def get(path, params={})
|
8
|
+
response = connection.get do |req|
|
9
|
+
req.url path
|
10
|
+
req.params = params
|
11
|
+
end
|
12
|
+
#Check for errors and encapsulate
|
13
|
+
respond(response)
|
14
|
+
end
|
15
|
+
|
16
|
+
#Performs post request
|
17
|
+
def post(path, params={})
|
18
|
+
response = connection.post do |req|
|
19
|
+
req.url path
|
20
|
+
req.body = params unless params.empty?
|
21
|
+
end
|
22
|
+
#Check for errors and encapsulate
|
23
|
+
respond(response)
|
24
|
+
end
|
25
|
+
|
26
|
+
def respond(response)
|
27
|
+
if [201, 200].include?(response.status)
|
28
|
+
response.body['response']
|
29
|
+
else
|
30
|
+
response.body['meta']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'time'
|
3
|
+
require 'uri'
|
4
|
+
require 'openssl'
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
module Tumblr
|
8
|
+
module Request
|
9
|
+
class TumblrOAuth < Faraday::Middleware
|
10
|
+
def call(env)
|
11
|
+
if env[:method].to_s == "get"
|
12
|
+
params = Faraday::Utils.parse_query(env[:url].query) || {}
|
13
|
+
url = "#{env[:url].scheme}://#{env[:url].host}#{env[:url].path}"
|
14
|
+
else
|
15
|
+
params = env[:body] || {}
|
16
|
+
url = env[:url]
|
17
|
+
end
|
18
|
+
signature_params = params
|
19
|
+
params.each do |key, value|
|
20
|
+
signature_params = {} if value.respond_to?(:content_type)
|
21
|
+
end
|
22
|
+
env[:request_headers]["Authorization"] = self.oauth_gen(env[:method], url, signature_params)
|
23
|
+
env[:request_headers]["Content-type"] = "application/x-www-form-urlencoded"
|
24
|
+
env[:request_headers]["Host"] = "api.tumblr.com"
|
25
|
+
|
26
|
+
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(app, options={})
|
31
|
+
@app, @options = app, options
|
32
|
+
end
|
33
|
+
|
34
|
+
def oauth_gen(method, url, params)
|
35
|
+
params[:oauth_consumer_key] = @options[:consumer_key]
|
36
|
+
params[:oauth_nonce] = Time.now.to_i
|
37
|
+
params[:oauth_signature_method] = 'HMAC-SHA1'
|
38
|
+
params[:oauth_timestamp] = Time.now.to_i
|
39
|
+
params[:oauth_token] = @options[:token]
|
40
|
+
params[:oauth_version] = "1.0"
|
41
|
+
params[:oauth_signature] = self.oauth_sig(method, url, params)
|
42
|
+
|
43
|
+
header = []
|
44
|
+
params.each do |key, value|
|
45
|
+
if key.to_s.include?("oauth")
|
46
|
+
header << "#{key.to_s}=#{value}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
"OAuth #{header.join(", ")}"
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
def oauth_sig(method, url, params)
|
55
|
+
parts = [method.upcase, URI.encode(url.to_s, /[^a-z0-9\-\.\_\~]/i)]
|
56
|
+
|
57
|
+
#sort the parameters
|
58
|
+
params = Hash[params.sort_by{ |key, value| key.to_s}]
|
59
|
+
|
60
|
+
encoded = []
|
61
|
+
params.each do |key, value|
|
62
|
+
encoded << "#{key.to_s}=#{URI.encode(value.to_s, /[^a-z0-9\-\.\_\~]/i)}"
|
63
|
+
end
|
64
|
+
|
65
|
+
parts << URI.encode(encoded.join("&"), /[^a-z0-9\-\.\_\~]/i)
|
66
|
+
signature_base = parts.join("&")
|
67
|
+
secret = "#{@options[:consumer_secret]}&#{@options[:token_secret]}"
|
68
|
+
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, secret, signature_base)).chomp.gsub(/\n/, '')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Tumblr
|
2
|
+
class Client
|
3
|
+
module Tagged
|
4
|
+
|
5
|
+
@@standard_options = [:before, :limit, :filter]
|
6
|
+
|
7
|
+
def tagged(tag, options={})
|
8
|
+
params = {:tag => tag, :api_key => Tumblr::consumer_key}
|
9
|
+
unless options.empty?
|
10
|
+
params.merge!(options)
|
11
|
+
end
|
12
|
+
if valid_options(@@standard_options, options)
|
13
|
+
get("v2/tagged", params)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/tumblr/user.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Tumblr
|
2
|
+
class Client
|
3
|
+
module User
|
4
|
+
def info
|
5
|
+
info = get("v2/user/info")
|
6
|
+
end
|
7
|
+
|
8
|
+
def dashboard(options={})
|
9
|
+
valid_opts = [:limit, :offset, :type, :since_id, :reblog_info, :notes_info]
|
10
|
+
if valid_options(valid_opts, options)
|
11
|
+
get("v2/user/dashboard", options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def likes(offset=0, limit=20)
|
16
|
+
likes = get("v2/user/likes", {:limit => limit, :offset => offset})
|
17
|
+
end
|
18
|
+
|
19
|
+
def following(offset=0, limit=20)
|
20
|
+
following = get("v2/user/following", {:limit => limit, :offset => offset})
|
21
|
+
end
|
22
|
+
|
23
|
+
def follow(url)
|
24
|
+
follow = post("v2/user/follow", {:url => url})
|
25
|
+
end
|
26
|
+
|
27
|
+
def unfollow(url)
|
28
|
+
follow = post("v2/user/unfollow", {:url => url})
|
29
|
+
end
|
30
|
+
|
31
|
+
def like(id, reblog_key)
|
32
|
+
like = post("v2/user/like", {:id => id, :reblog_key => reblog_key})
|
33
|
+
end
|
34
|
+
|
35
|
+
def unlike(id, reblog_key)
|
36
|
+
unlike = post("v2/user/unlike", {:id => id, :reblog_key => reblog_key})
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/tumblr.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.add_dependency 'faraday', '>= 0.8'
|
5
|
+
gem.add_dependency 'faraday_middleware'
|
6
|
+
gem.add_dependency 'json'
|
7
|
+
gem.add_development_dependency 'rake'
|
8
|
+
gem.add_development_dependency 'rspec'
|
9
|
+
gem.add_development_dependency 'webmock'
|
10
|
+
gem.authors = ["John Bunting"]
|
11
|
+
gem.description = %q{A Ruby wrapper for the Tumblr v2 API}
|
12
|
+
gem.email = ['codingjester@gmail.com']
|
13
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
15
|
+
gem.name = "tumblr_client_faraday_0_8"
|
16
|
+
gem.homepage="https://github.com/sahin-ml/tumblr_client_faraday_0_8.git"
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
|
19
|
+
gem.summary = %q{Tumblr API wrapper}
|
20
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
gem.version = "0.6.7.1"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tumblr_client_faraday_0_8
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.7.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- John Bunting
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.8'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.8'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday_middleware
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: json
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: webmock
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: A Ruby wrapper for the Tumblr v2 API
|
111
|
+
email:
|
112
|
+
- codingjester@gmail.com
|
113
|
+
executables:
|
114
|
+
- tumblr
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.md
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- bin/tumblr
|
124
|
+
- lib/tumblr/blog.rb
|
125
|
+
- lib/tumblr/client.rb
|
126
|
+
- lib/tumblr/config.rb
|
127
|
+
- lib/tumblr/connection.rb
|
128
|
+
- lib/tumblr/helpers.rb
|
129
|
+
- lib/tumblr/post.rb
|
130
|
+
- lib/tumblr/request.rb
|
131
|
+
- lib/tumblr/request/oauth.rb
|
132
|
+
- lib/tumblr/tagged.rb
|
133
|
+
- lib/tumblr/user.rb
|
134
|
+
- lib/tumblr_client.rb
|
135
|
+
- tumblr.gemspec
|
136
|
+
homepage: https://github.com/sahin-ml/tumblr_client_faraday_0_8.git
|
137
|
+
licenses: []
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 1.3.6
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 1.8.24
|
157
|
+
signing_key:
|
158
|
+
specification_version: 3
|
159
|
+
summary: Tumblr API wrapper
|
160
|
+
test_files: []
|