tumblr_wrapper 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -0
- data/lib/tumblr_wrapper/http.rb +5 -2
- data/lib/tumblr_wrapper/{blog.rb → resources/blog.rb} +0 -0
- data/lib/tumblr_wrapper/{blog_resource.rb → resources/blog_resource.rb} +0 -0
- data/lib/tumblr_wrapper/{post.rb → resources/post.rb} +0 -0
- data/lib/tumblr_wrapper/{resource.rb → resources/resource.rb} +0 -0
- data/lib/tumblr_wrapper/response.rb +32 -0
- data/lib/tumblr_wrapper/version.rb +1 -1
- data/lib/tumblr_wrapper.rb +6 -4
- data/spec/integration/tumblr_wrapper_spec.rb +15 -5
- data/tumblr_wrapper.gemspec +1 -0
- metadata +26 -12
data/README.md
CHANGED
@@ -78,6 +78,17 @@ To delete a post:
|
|
78
78
|
|
79
79
|
post.delete({id: "ID FROM TUMBLR"})
|
80
80
|
|
81
|
+
The response object is a TumblrWrapper::Response.
|
82
|
+
It responds to `:status`, `:meta`, and any of the keys under "response" from tumblr.
|
83
|
+
Any of the values which are hashes will have indifferent access.
|
84
|
+
For example,
|
85
|
+
|
86
|
+
response = blog.posts
|
87
|
+
response.status.should == 200
|
88
|
+
response.meta[:status].should == 200
|
89
|
+
response.blog[:title].should == "Your Blog Title"
|
90
|
+
response.posts.should be_a(Array)
|
91
|
+
|
81
92
|
## Contributing
|
82
93
|
|
83
94
|
1. Fork it
|
data/lib/tumblr_wrapper/http.rb
CHANGED
@@ -8,12 +8,14 @@ module TumblrWrapper::HTTP
|
|
8
8
|
conn.response :json, :content_type => /\bjson$/
|
9
9
|
conn.adapter Faraday.default_adapter
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
|
+
response = if opts[:signed]
|
12
13
|
connection.get(long_path(path), params)
|
13
14
|
else
|
14
15
|
parameters = params.merge({api_key: TumblrWrapper.consumer_key})
|
15
16
|
connection.get(long_path(path), parameters)
|
16
17
|
end
|
18
|
+
TumblrWrapper::Response.new(response)
|
17
19
|
end
|
18
20
|
|
19
21
|
def http_post(path, body)
|
@@ -25,7 +27,8 @@ module TumblrWrapper::HTTP
|
|
25
27
|
conn.adapter Faraday.default_adapter
|
26
28
|
end
|
27
29
|
|
28
|
-
connection.post long_path(path), body
|
30
|
+
response = connection.post long_path(path), body
|
31
|
+
TumblrWrapper::Response.new(response)
|
29
32
|
end
|
30
33
|
|
31
34
|
private
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class TumblrWrapper::Response
|
2
|
+
attr_reader :status, :meta
|
3
|
+
def initialize(faraday_response)
|
4
|
+
@faraday_response = faraday_response
|
5
|
+
@status = faraday_response.status
|
6
|
+
@response = faraday_response.body["response"]
|
7
|
+
parse_meta
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def faraday_response
|
12
|
+
@faraday_response
|
13
|
+
end
|
14
|
+
|
15
|
+
def response
|
16
|
+
@response
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_meta
|
20
|
+
resp = faraday_response.body["meta"] || {}
|
21
|
+
@meta = resp.with_indifferent_access
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(meth, *args, &block)
|
25
|
+
if response.keys.include?(meth.to_s)
|
26
|
+
r = response[meth.to_s]
|
27
|
+
r.respond_to?(:keys) ? r.with_indifferent_access : r
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/tumblr_wrapper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'active_support/all'
|
2
3
|
require 'oauth'
|
3
4
|
require 'faraday'
|
4
5
|
require 'faraday_middleware'
|
@@ -7,10 +8,11 @@ require "tumblr_wrapper/version"
|
|
7
8
|
require "tumblr_wrapper/validators"
|
8
9
|
require "tumblr_wrapper/http"
|
9
10
|
require "tumblr_wrapper/client"
|
10
|
-
require "tumblr_wrapper/resource"
|
11
|
-
require "tumblr_wrapper/blog_resource"
|
12
|
-
require "tumblr_wrapper/blog"
|
13
|
-
require "tumblr_wrapper/post"
|
11
|
+
require "tumblr_wrapper/resources/resource"
|
12
|
+
require "tumblr_wrapper/resources/blog_resource"
|
13
|
+
require "tumblr_wrapper/resources/blog"
|
14
|
+
require "tumblr_wrapper/resources/post"
|
15
|
+
require "tumblr_wrapper/response"
|
14
16
|
|
15
17
|
module TumblrWrapper
|
16
18
|
ENDPOINT = 'http://api.tumblr.com'
|
@@ -32,10 +32,15 @@ describe TumblrWrapper, type: :integration do
|
|
32
32
|
token = client.build_access_token(access_token, access_token_secret)
|
33
33
|
|
34
34
|
blog_resource = TumblrWrapper::Blog.new(blogname, token)
|
35
|
-
|
35
|
+
response = blog_resource.info
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
response.should be_a(TumblrWrapper::Response)
|
38
|
+
response.status.should == 200
|
39
|
+
|
40
|
+
response.meta[:msg].should == "OK"
|
41
|
+
response.meta[:status].should == 200
|
42
|
+
|
43
|
+
response.blog[:title].should == blog_title
|
39
44
|
end
|
40
45
|
end
|
41
46
|
|
@@ -45,7 +50,7 @@ describe TumblrWrapper, type: :integration do
|
|
45
50
|
token = client.build_access_token(access_token, access_token_secret)
|
46
51
|
|
47
52
|
blog_resource = TumblrWrapper::Blog.new(blogname, token)
|
48
|
-
|
53
|
+
response = blog_resource.followers
|
49
54
|
end
|
50
55
|
end
|
51
56
|
|
@@ -55,7 +60,12 @@ describe TumblrWrapper, type: :integration do
|
|
55
60
|
token = client.build_access_token(access_token, access_token_secret)
|
56
61
|
|
57
62
|
blog_resource = TumblrWrapper::Blog.new(blogname, token)
|
58
|
-
|
63
|
+
response = blog_resource.posts
|
64
|
+
response.status.should == 200
|
65
|
+
|
66
|
+
response.meta.should be_present
|
67
|
+
response.blog.should be_present
|
68
|
+
response.posts.should be_present
|
59
69
|
end
|
60
70
|
end
|
61
71
|
end
|
data/tumblr_wrapper.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_development_dependency 'rspec'
|
19
19
|
gem.add_development_dependency 'vcr'
|
20
20
|
gem.add_development_dependency 'webmock'
|
21
|
+
gem.add_dependency 'activesupport'
|
21
22
|
gem.add_dependency 'oauth'
|
22
23
|
gem.add_dependency 'faraday'
|
23
24
|
gem.add_dependency 'faraday_middleware'
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- rheaton
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-08-
|
17
|
+
date: 2012-08-03 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -70,7 +70,7 @@ dependencies:
|
|
70
70
|
type: :development
|
71
71
|
version_requirements: *id004
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
|
-
name:
|
73
|
+
name: activesupport
|
74
74
|
prerelease: false
|
75
75
|
requirement: &id005 !ruby/object:Gem::Requirement
|
76
76
|
none: false
|
@@ -83,7 +83,7 @@ dependencies:
|
|
83
83
|
type: :runtime
|
84
84
|
version_requirements: *id005
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
|
-
name:
|
86
|
+
name: oauth
|
87
87
|
prerelease: false
|
88
88
|
requirement: &id006 !ruby/object:Gem::Requirement
|
89
89
|
none: false
|
@@ -96,7 +96,7 @@ dependencies:
|
|
96
96
|
type: :runtime
|
97
97
|
version_requirements: *id006
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
|
-
name:
|
99
|
+
name: faraday
|
100
100
|
prerelease: false
|
101
101
|
requirement: &id007 !ruby/object:Gem::Requirement
|
102
102
|
none: false
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
type: :runtime
|
110
110
|
version_requirements: *id007
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: faraday_middleware
|
113
113
|
prerelease: false
|
114
114
|
requirement: &id008 !ruby/object:Gem::Requirement
|
115
115
|
none: false
|
@@ -121,6 +121,19 @@ dependencies:
|
|
121
121
|
version: "0"
|
122
122
|
type: :runtime
|
123
123
|
version_requirements: *id008
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: simple_oauth
|
126
|
+
prerelease: false
|
127
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
type: :runtime
|
136
|
+
version_requirements: *id009
|
124
137
|
description: ruby wrapper for tumblr api
|
125
138
|
email:
|
126
139
|
- rachelmheaton@gmail.com
|
@@ -138,12 +151,13 @@ files:
|
|
138
151
|
- README.md
|
139
152
|
- Rakefile
|
140
153
|
- lib/tumblr_wrapper.rb
|
141
|
-
- lib/tumblr_wrapper/blog.rb
|
142
|
-
- lib/tumblr_wrapper/blog_resource.rb
|
143
154
|
- lib/tumblr_wrapper/client.rb
|
144
155
|
- lib/tumblr_wrapper/http.rb
|
145
|
-
- lib/tumblr_wrapper/
|
146
|
-
- lib/tumblr_wrapper/
|
156
|
+
- lib/tumblr_wrapper/resources/blog.rb
|
157
|
+
- lib/tumblr_wrapper/resources/blog_resource.rb
|
158
|
+
- lib/tumblr_wrapper/resources/post.rb
|
159
|
+
- lib/tumblr_wrapper/resources/resource.rb
|
160
|
+
- lib/tumblr_wrapper/response.rb
|
147
161
|
- lib/tumblr_wrapper/validators.rb
|
148
162
|
- lib/tumblr_wrapper/version.rb
|
149
163
|
- spec/blog_resource_spec.rb
|