tumblr_client 0.7.5 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/lib/tumblr/config.rb +2 -1
- data/lib/tumblr/connection.rb +12 -9
- data/lib/tumblr/post.rb +12 -11
- data/lib/tumblr/version.rb +1 -1
- data/spec/examples/post_spec.rb +4 -20
- data/tumblr_client.gemspec +2 -0
- metadata +30 -3
- data/lib/tumblr/request/oauth.rb +0 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85e2a013fa7e390e522e3832dbaae337e3a4ff88
|
4
|
+
data.tar.gz: a250c8be007a9165f57ab0b69fb1f790da93f78c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b33406cfec5727d2f3c7960843b00d0bcfa79e3042d90739b08e98fcb33c0abeebe469283b89918b9a3960140e96ca3380065c9b8a9e546cdccebbeb12128499
|
7
|
+
data.tar.gz: 588baf76498eb98cc75ba6a83ab8d1c2df1adaf939d99b7a5736f9a5fa1ee3b57a3bbce4bd0a7d19e3e752add705b32b4754236246be41b1b08ef42ba5af32ef
|
data/README.md
CHANGED
@@ -33,6 +33,11 @@ Once you have your configuration squared away it's time to make some requests!
|
|
33
33
|
|
34
34
|
That's it! You now have a client that can make any request to the Tumblr API.
|
35
35
|
|
36
|
+
Also since the client is created with the amazing library [Faraday](https://github.com/lostisland/faraday), you can
|
37
|
+
configure it to use any HTTP Client it supports.
|
38
|
+
|
39
|
+
>> client = Tumblr::Client.new(:client => :httpclient)
|
40
|
+
|
36
41
|
### Some quick examples
|
37
42
|
|
38
43
|
Getting user information:
|
@@ -53,10 +58,6 @@ Posting some photos to Tumblr:
|
|
53
58
|
# Uploads a great photoset
|
54
59
|
>> client.photo("codingjester.tumblr.com", {:data => ['/path/to/pic.jpg', '/path/to/pic.jpg']})
|
55
60
|
|
56
|
-
# You can also post with the raw data
|
57
|
-
>> raw = File.open('/path/to/pic.jpg', 'rb').read
|
58
|
-
>> client.photo('codingjester.tumblr.com', :data_raw => [raw]
|
59
|
-
|
60
61
|
### The irb Console
|
61
62
|
|
62
63
|
Finally, there is an irb console packaged with the gem that should help you test any calls you want to make.
|
data/lib/tumblr/config.rb
CHANGED
data/lib/tumblr/connection.rb
CHANGED
@@ -1,27 +1,30 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
require 'faraday_middleware'
|
3
|
-
require 'tumblr/request/oauth'
|
4
3
|
|
5
4
|
module Tumblr
|
6
5
|
module Connection
|
7
6
|
|
8
7
|
def connection(options={})
|
9
|
-
|
8
|
+
|
10
9
|
default_options = {
|
11
10
|
:headers => {
|
12
11
|
:accept => 'application/json',
|
13
12
|
:user_agent => "tumblr_client (ruby) - #{Tumblr::VERSION}"
|
14
13
|
},
|
15
|
-
:url => "http://#{
|
14
|
+
:url => "http://#{api_host}/"
|
16
15
|
}
|
17
|
-
|
18
|
-
|
16
|
+
|
17
|
+
client = options[:client] ||= Faraday.default_adapter
|
18
|
+
|
19
|
+
Faraday.new("http://#{api_host}/", default_options.merge(options)) do |conn|
|
20
|
+
data = { :api_host => api_host }.merge(credentials)
|
19
21
|
unless credentials.empty?
|
20
|
-
|
22
|
+
conn.request :oauth, data
|
21
23
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
conn.request :multipart
|
25
|
+
conn.request :url_encoded
|
26
|
+
conn.response :json, :content_type => /\bjson$/
|
27
|
+
conn.adapter client
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
data/lib/tumblr/post.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'mime/types'
|
2
|
+
|
1
3
|
module Tumblr
|
2
4
|
module Post
|
3
5
|
|
@@ -17,7 +19,7 @@ module Tumblr
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def photo(blog_name, options = {})
|
20
|
-
valid_opts = STANDARD_POST_OPTIONS + [:caption, :link, :data, :
|
22
|
+
valid_opts = STANDARD_POST_OPTIONS + [:caption, :link, :data, :source, :photoset_layout]
|
21
23
|
validate_options(valid_opts, options)
|
22
24
|
validate_no_collision options, [:data, :source]
|
23
25
|
convert_source_array :source, options
|
@@ -60,7 +62,7 @@ module Tumblr
|
|
60
62
|
end
|
61
63
|
|
62
64
|
def audio(blog_name, options = {})
|
63
|
-
valid_opts = STANDARD_POST_OPTIONS + [:data, :
|
65
|
+
valid_opts = STANDARD_POST_OPTIONS + [:data, :caption, :external_url]
|
64
66
|
validate_options(valid_opts, options)
|
65
67
|
validate_no_collision options, [:data, :external_url]
|
66
68
|
|
@@ -70,7 +72,7 @@ module Tumblr
|
|
70
72
|
end
|
71
73
|
|
72
74
|
def video(blog_name, options = {})
|
73
|
-
valid_opts = STANDARD_POST_OPTIONS + [:data, :
|
75
|
+
valid_opts = STANDARD_POST_OPTIONS + [:data, :embed, :caption]
|
74
76
|
validate_options(valid_opts, options)
|
75
77
|
validate_no_collision options, [:data, :embed]
|
76
78
|
|
@@ -98,18 +100,17 @@ module Tumblr
|
|
98
100
|
# Look for the various ways that data can be passed, and normalize
|
99
101
|
# the result in this hash
|
100
102
|
def extract_data!(options)
|
101
|
-
validate_no_collision options, [:data, :data_raw]
|
102
103
|
if options.has_key?(:data)
|
103
104
|
data = options.delete :data
|
104
105
|
data = [data] unless Array === data
|
105
106
|
data.each.with_index do |filepath, idx|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
options["data[#{idx}]"] =
|
107
|
+
mime = MIME::Types.type_for(filepath)
|
108
|
+
if (!mime.empty?)
|
109
|
+
mime_type = MIME::Types.type_for(filepath)[0].content_type
|
110
|
+
else
|
111
|
+
mime_type = "application/octet-stream"
|
112
|
+
end
|
113
|
+
options["data[#{idx}]"] = Faraday::UploadIO.new(filepath, mime_type)
|
113
114
|
end
|
114
115
|
end
|
115
116
|
end
|
data/lib/tumblr/version.rb
CHANGED
data/spec/examples/post_spec.rb
CHANGED
@@ -108,30 +108,20 @@ describe Tumblr::Post do
|
|
108
108
|
|
109
109
|
before do
|
110
110
|
fakefile = OpenStruct.new :read => file_data
|
111
|
-
File.stub(:open).with(file_path
|
111
|
+
File.stub(:open).with(file_path + '.jpg').and_return(fakefile)
|
112
112
|
client.should_receive(:post).once.with("v2/blog/#{blog_name}/post", {
|
113
|
-
'data[0]' =>
|
113
|
+
'data[0]' => kind_of(Faraday::UploadIO),
|
114
114
|
:type => type.to_s
|
115
115
|
}).and_return('post')
|
116
116
|
end
|
117
117
|
|
118
118
|
it 'should be able to pass data as an array of filepaths' do
|
119
|
-
r = client.send type, blog_name, :data => [file_path]
|
119
|
+
r = client.send type, blog_name, :data => [file_path + ".jpg"]
|
120
120
|
r.should == 'post'
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'should be able to pass data as a single filepath' do
|
124
|
-
r = client.send type, blog_name, :data => file_path
|
125
|
-
r.should == 'post'
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'should be able to pass an array of raw data' do
|
129
|
-
r = client.send type, blog_name, :data_raw => [file_data]
|
130
|
-
r.should == 'post'
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'should be able to pass raw data' do
|
134
|
-
r = client.send type, blog_name, :data_raw => file_data
|
124
|
+
r = client.send type, blog_name, :data => file_path + ".jpg"
|
135
125
|
r.should == 'post'
|
136
126
|
end
|
137
127
|
|
@@ -180,12 +170,6 @@ describe Tumblr::Post do
|
|
180
170
|
}.should raise_error ArgumentError
|
181
171
|
end
|
182
172
|
|
183
|
-
it 'should get an error when passing data & raw_data' do
|
184
|
-
lambda {
|
185
|
-
client.send type, blog_name, :raw_data => 'hi', :data => 'bye'
|
186
|
-
}.should raise_error ArgumentError
|
187
|
-
end
|
188
|
-
|
189
173
|
end
|
190
174
|
|
191
175
|
end
|
data/tumblr_client.gemspec
CHANGED
@@ -5,7 +5,9 @@ Gem::Specification.new do |gem|
|
|
5
5
|
gem.add_dependency 'faraday', '>= 0.8'
|
6
6
|
gem.add_dependency 'faraday_middleware', '>= 0.8'
|
7
7
|
gem.add_dependency 'json'
|
8
|
+
gem.add_dependency 'simple_oauth'
|
8
9
|
gem.add_dependency 'oauth'
|
10
|
+
gem.add_dependency 'mime-types'
|
9
11
|
gem.add_development_dependency 'rake'
|
10
12
|
gem.add_development_dependency 'rspec'
|
11
13
|
gem.add_development_dependency 'webmock'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tumblr_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Bunting
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - '>='
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: simple_oauth
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: oauth
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,6 +81,20 @@ dependencies:
|
|
67
81
|
- - '>='
|
68
82
|
- !ruby/object:Gem::Version
|
69
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: mime-types
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
70
98
|
- !ruby/object:Gem::Dependency
|
71
99
|
name: rake
|
72
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,7 +174,6 @@ files:
|
|
146
174
|
- lib/tumblr/helpers.rb
|
147
175
|
- lib/tumblr/post.rb
|
148
176
|
- lib/tumblr/request.rb
|
149
|
-
- lib/tumblr/request/oauth.rb
|
150
177
|
- lib/tumblr/tagged.rb
|
151
178
|
- lib/tumblr/user.rb
|
152
179
|
- lib/tumblr/version.rb
|
data/lib/tumblr/request/oauth.rb
DELETED
@@ -1,72 +0,0 @@
|
|
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
|
-
|
11
|
-
def call(env)
|
12
|
-
if env[:method].to_s == 'get'
|
13
|
-
params = Faraday::Utils.parse_query(env[:url].query) || {}
|
14
|
-
url = "#{env[:url].scheme}://#{env[:url].host}#{env[:url].path}"
|
15
|
-
else
|
16
|
-
params = env[:body] || {}
|
17
|
-
url = env[:url]
|
18
|
-
end
|
19
|
-
signature_params = params
|
20
|
-
params.each do |key, value|
|
21
|
-
signature_params = {} if value.respond_to?(:content_type)
|
22
|
-
end
|
23
|
-
env[:request_headers]['Authorization'] = self.oauth_gen(env[:method], url, signature_params)
|
24
|
-
env[:request_headers]['Content-type'] = 'application/x-www-form-urlencoded'
|
25
|
-
env[:request_headers]['Host'] = @options[:api_host]
|
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] = Base64.encode64(OpenSSL::Random.random_bytes(32)).gsub(/\W/, '')
|
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
|
-
end
|
52
|
-
|
53
|
-
def oauth_sig(method, url, params)
|
54
|
-
parts = [method.upcase, URI.encode(url.to_s, /[^a-z0-9\-\.\_\~]/i)]
|
55
|
-
|
56
|
-
#sort the parameters
|
57
|
-
params = Hash[params.sort_by{ |key, value| key.to_s}]
|
58
|
-
|
59
|
-
encoded = []
|
60
|
-
params.each do |key, value|
|
61
|
-
encoded << "#{key.to_s}=#{URI.encode(value.to_s, /[^a-z0-9\-\.\_\~]/i)}"
|
62
|
-
end
|
63
|
-
|
64
|
-
parts << URI.encode(encoded.join('&'), /[^a-z0-9\-\.\_\~]/i)
|
65
|
-
signature_base = parts.join('&')
|
66
|
-
secret = "#{@options[:consumer_secret]}&#{@options[:token_secret]}"
|
67
|
-
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, secret, signature_base)).chomp.gsub(/\n/, '')
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|