tumble 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -7
- data/lib/tumble.rb +1 -1
- data/lib/tumble/blog.rb +11 -11
- data/lib/tumble/connection.rb +1 -1
- data/lib/tumble/request/oauth.rb +36 -8
- data/tumble.gemspec +1 -1
- metadata +10 -10
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Tumble #
|
2
|
-
A Ruby wrapper for
|
2
|
+
A Ruby wrapper for v2 of Tumblr's API, supporting all endpoints.
|
3
3
|
|
4
4
|
## <a name="installation"></a>Install
|
5
5
|
gem install tumble
|
@@ -9,19 +9,19 @@ A Ruby wrapper for the v2 of Tumblr's API, supporting all endpoints.
|
|
9
9
|
The gem is designed to work with Tumblr's OAuth provider for authentication. If you're using omniauth,
|
10
10
|
there's a fine adapter available [here](https://github.com/aub/omniauth-tumblr2). You'll also need to
|
11
11
|
register your app [here](http://www.tumblr.com/oauth/apps) in order to get a consumer key and secret.
|
12
|
-
Once you have those
|
12
|
+
Once you have those, you can configure Tumble in an initializer like so:
|
13
13
|
|
14
14
|
require 'tumble'
|
15
15
|
|
16
16
|
Tumble.configure do |tumble|
|
17
|
-
tumble.consumer_key =
|
18
|
-
tumble.consumer_secret =
|
17
|
+
tumble.consumer_key = ENV['tumblr']['key']
|
18
|
+
tumble.consumer_secret = ENV['tumblr']['secret']
|
19
19
|
end
|
20
20
|
|
21
21
|
## <a name="usage"></a>Use
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
A connection can then be made by creating a client, passing the OAuth token and secret you get back from
|
24
|
+
the provider:
|
25
25
|
|
26
26
|
client = Tumble::Client.new(access_token, access_secret)
|
27
27
|
|
@@ -36,7 +36,7 @@ For example, getting posts for a specific blog can be done like this:
|
|
36
36
|
|
37
37
|
client.blog('www.riotprojects.com').posts
|
38
38
|
|
39
|
-
Most of the calls allow for options to be passed
|
39
|
+
Most of the calls allow for options to be passed as a hash. Options are documented in the links above and are consistent
|
40
40
|
with the naming and functionality described in the [Tumblr docs](https://github.com/aub/omniauth-tumblr2).
|
41
41
|
|
42
42
|
## <a name="documentation"></a>Learn
|
data/lib/tumble.rb
CHANGED
data/lib/tumble/blog.rb
CHANGED
@@ -87,7 +87,7 @@ module Tumble
|
|
87
87
|
# @requires_authentication Yes
|
88
88
|
#
|
89
89
|
# @param options [Hash] A customizable set of options
|
90
|
-
# @option options [String] :type The type of post to create. Specify one of the following: text, photo, quote, link, chat, audio, video
|
90
|
+
# @option options [String, required] :type The type of post to create. Specify one of the following: text, photo, quote, link, chat, audio, video
|
91
91
|
# @option options [String] :state The state of the post. Specify one of the following: published, draft, queue
|
92
92
|
# @option options [String] :tags Comma-separated tags for this post
|
93
93
|
# @option options [String] :tweet Manages the autotweet (if enabled) for this post: set to off for no tweet, or enter text to override the default tweet
|
@@ -96,30 +96,30 @@ module Tumble
|
|
96
96
|
# @option options [String] :slug Add a short text summary to the end of the post URL
|
97
97
|
# For text posts:
|
98
98
|
# @option options [String] :title The optional title of the post, HTML entities must be escaped
|
99
|
-
# @option options [String] :body The full post body, HTML allowed
|
99
|
+
# @option options [String, required] :body The full post body, HTML allowed
|
100
100
|
# For photo posts:
|
101
101
|
# @option options [String] :caption The user-supplied caption, HTML allowed
|
102
102
|
# @option options [String] :link The "click-through URL" for the photo
|
103
|
-
# @option options [String] :source The photo source URL
|
104
|
-
# @option options [Array] :data One or more image files (submit multiple times to create a slide show)
|
103
|
+
# @option options [String, required] :source The photo source URL
|
104
|
+
# @option options [Array, required] :data One or more image files (submit multiple times to create a slide show)
|
105
105
|
# For quote posts:
|
106
|
-
# @option options [String] :quote The full text of the quote, HTML entities must be escaped
|
106
|
+
# @option options [String, required] :quote The full text of the quote, HTML entities must be escaped
|
107
107
|
# @option options [String] :source Cited source, HTML allowed
|
108
108
|
# For link posts:
|
109
109
|
# @option options [String] :title The title of the page the link points to, HTML entities should be escaped
|
110
|
-
# @option options [String] :url The link
|
110
|
+
# @option options [String, required] :url The link
|
111
111
|
# @option options [String] :description A user-supplied description, HTML allowed
|
112
112
|
# For chat posts:
|
113
113
|
# @option options [String] :title The title of the chat
|
114
|
-
# @option options [String] :conversation The text of the conversation/chat, with dialogue labels (no HTML)
|
114
|
+
# @option options [String, required] :conversation The text of the conversation/chat, with dialogue labels (no HTML)
|
115
115
|
# For audio posts:
|
116
116
|
# @option options [String] :caption The user-supplied caption
|
117
|
-
# @option options [String] :external_url The URL of the site that hosts the audio file (not tumblr)
|
118
|
-
# @option options [String] :data An audio file
|
117
|
+
# @option options [String, required] :external_url The URL of the site that hosts the audio file (not tumblr)
|
118
|
+
# @option options [String, required] :data An audio file
|
119
119
|
# For video posts:
|
120
120
|
# @option options [String] :caption The user-supplied caption
|
121
|
-
# @option options [String] :embed HTML embed code for the video
|
122
|
-
# @option options [String] :data A video file
|
121
|
+
# @option options [String, required] :embed HTML embed code for the video
|
122
|
+
# @option options [String, required] :data A video file
|
123
123
|
def create_post(options={})
|
124
124
|
@connection.post("/blog/#{name}/post", options).response
|
125
125
|
end
|
data/lib/tumble/connection.rb
CHANGED
@@ -50,11 +50,11 @@ module Tumble
|
|
50
50
|
:params => { :api_key => credentials[:consumer_key] }
|
51
51
|
}
|
52
52
|
@faraday_connection ||= Faraday::Connection.new(options) do |builder|
|
53
|
+
builder.use Tumble::Request::TumblrOAuth, credentials
|
53
54
|
builder.use Faraday::Request::UrlEncoded
|
54
55
|
builder.use Faraday::Request::Multipart
|
55
56
|
builder.use FaradayMiddleware::Mashify
|
56
57
|
builder.use FaradayMiddleware::ParseJson
|
57
|
-
builder.use Tumble::Request::TumblrOAuth, credentials
|
58
58
|
builder.adapter Faraday.default_adapter
|
59
59
|
end
|
60
60
|
end
|
data/lib/tumble/request/oauth.rb
CHANGED
@@ -1,21 +1,49 @@
|
|
1
1
|
require 'faraday'
|
2
|
-
require 'simple_oauth'
|
3
2
|
|
4
3
|
module Tumble
|
5
4
|
module Request
|
5
|
+
|
6
6
|
class TumblrOAuth < Faraday::Middleware
|
7
|
+
dependency 'simple_oauth'
|
8
|
+
|
9
|
+
AUTH_HEADER = 'Authorization'.freeze
|
10
|
+
|
11
|
+
def initialize(app, options)
|
12
|
+
super(app)
|
13
|
+
@options = options
|
14
|
+
end
|
7
15
|
|
8
16
|
def call(env)
|
9
|
-
|
10
|
-
signature_params = params.reject{ |k,v| v.respond_to?(:content_type) }
|
11
|
-
header = SimpleOAuth::Header.new(env[:method], env[:url], signature_params, @options)
|
12
|
-
env[:request_headers]['Authorization'] = header.to_s
|
17
|
+
env[:request_headers][AUTH_HEADER] ||= oauth_header(env).to_s if sign_request?(env)
|
13
18
|
@app.call(env)
|
14
19
|
end
|
15
20
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
21
|
+
def oauth_header(env)
|
22
|
+
SimpleOAuth::Header.new env[:method],
|
23
|
+
env[:url].to_s,
|
24
|
+
signature_params(body_params(env)),
|
25
|
+
oauth_options(env)
|
26
|
+
end
|
27
|
+
|
28
|
+
def sign_request?(env)
|
29
|
+
!!env[:request].fetch(:oauth, true)
|
30
|
+
end
|
31
|
+
|
32
|
+
def oauth_options(env)
|
33
|
+
if extra = env[:request][:oauth] and extra.is_a? Hash and !extra.empty?
|
34
|
+
@options.merge extra
|
35
|
+
else
|
36
|
+
@options
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def body_params(env)
|
41
|
+
env[:body] || {}
|
42
|
+
end
|
43
|
+
|
44
|
+
def signature_params(params)
|
45
|
+
params.empty? ? params :
|
46
|
+
params.reject {|k,v| v.respond_to?(:content_type) }
|
19
47
|
end
|
20
48
|
end
|
21
49
|
end
|
data/tumble.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
5
|
s.name = 'tumble'
|
6
|
-
s.version = '0.
|
6
|
+
s.version = '0.2.0'
|
7
7
|
|
8
8
|
s.summary = 'Library for accessing the Tumblr api v2'
|
9
9
|
# TODO: s.description
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tumble
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-29 00:00:00.000000000 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
17
|
-
requirement: &
|
17
|
+
requirement: &70335286948320 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70335286948320
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rake
|
28
|
-
requirement: &
|
28
|
+
requirement: &70335286947860 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70335286947860
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &70335286947440 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70335286947440
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: webmock
|
50
|
-
requirement: &
|
50
|
+
requirement: &70335286947020 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70335286947020
|
59
59
|
description:
|
60
60
|
email: aubreyholland@gmail.com
|
61
61
|
executables: []
|