tumble 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/tumble/client.rb CHANGED
@@ -7,29 +7,27 @@ module Tumble
7
7
  # Initialize a client to use for making requests
8
8
  #
9
9
  # @param [String] oauth_token
10
- # @param [Hash] options
11
- # @option options Hash :ssl Additional SSL options (like the path to certificate file)
12
- def initialize(oauth_token, options={})
13
- @oauth_token = options[:oauth_token]
14
- @ssl = options[:ssl].nil? ? Hash.new : options[:ssl]
15
- end
16
-
17
- def ssl
18
- @ssl
10
+ # @param [String] oauth_secret
11
+ def initialize(access_token, access_secret)
12
+ @access_token = access_token
13
+ @access_secret = access_secret
19
14
  end
20
15
 
21
16
  def connection
22
17
  options = {
23
18
  :url => api_url,
24
- :ssl => @ssl,
25
19
  :params => { :oauth_token => @oauth_token },
26
- :headers => default_headers
20
+ :headers => {
21
+ :accept => 'application/json',
22
+ :user_agent => 'tumble'
23
+ }
27
24
  }
28
25
  @connection ||= Faraday::Connection.new(options) do |builder|
29
26
  builder.use Faraday::Request::Multipart
30
27
  builder.use Faraday::Request::UrlEncoded
31
28
  builder.use FaradayMiddleware::Mashify
32
29
  builder.use FaradayMiddleware::ParseJson
30
+ builder.use Tumble::Request::TumblrOAuth, credentials
33
31
  builder.adapter Faraday.default_adapter
34
32
  end
35
33
  end
@@ -42,13 +40,17 @@ module Tumble
42
40
  Blog.new(self, blog_name)
43
41
  end
44
42
 
45
- private
46
-
47
- def default_headers
48
- headers = {
49
- :accept => 'application/json',
50
- :user_agent => 'tumble'
43
+ def credentials
44
+ {
45
+ :consumer_key => Config.consumer_key,
46
+ :consumer_secret => Config.consumer_secret,
47
+ :token => @access_token,
48
+ :token_secret => @access_secret,
51
49
  }
52
50
  end
51
+
52
+ def user_info
53
+ @connection.post('http://api.tumblr.com/v2/user/info')
54
+ end
53
55
  end
54
56
  end
@@ -0,0 +1,19 @@
1
+ module Tumble
2
+ module Config
3
+ def self.consumer_key=(key)
4
+ @consumer_key = key
5
+ end
6
+
7
+ def self.consumer_key
8
+ @consumer_key
9
+ end
10
+
11
+ def self.consumer_secret=(secret)
12
+ @consumer_secret = secret
13
+ end
14
+
15
+ def self.consumer_secret
16
+ @consumer_secret
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ require 'faraday'
2
+ require 'simple_oauth'
3
+
4
+ module Tumble
5
+ module Request
6
+ class TumblrOAuth < Faraday::Middleware
7
+
8
+ def call(env)
9
+ params = env[:body] || {}
10
+ signature_params = params
11
+ params.each do |key, value|
12
+ signature_params = {} if value.respond_to?(:content_type)
13
+ end
14
+ header = SimpleOAuth::Header.new(env[:method], env[:url], signature_params, @options)
15
+ env[:request_headers]['Authorization'] = header.to_s
16
+
17
+ @app.call(env)
18
+ end
19
+
20
+ def initialize(app, options)
21
+ @app, @options = app, options
22
+ end
23
+ end
24
+ end
25
+ end
data/lib/tumble.rb CHANGED
@@ -1,7 +1,12 @@
1
- %w(blog client).each do |file|
1
+ %w(blog client config request/oauth).each do |file|
2
2
  require File.join(File.dirname(__FILE__), 'tumble', file)
3
3
  end
4
4
 
5
5
  module Tumble
6
- VERSION = '0.0.2'
6
+ VERSION = '0.0.3'
7
+
8
+ def self.config
9
+ yield Config
10
+ Config
11
+ end
7
12
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tumble::Config do
4
+ it 'should allow me to set the consumer key and secret' do
5
+ Tumble.config do |config|
6
+ config.consumer_key = 'abc'
7
+ config.consumer_secret = '123'
8
+ end
9
+ Tumble::Config.consumer_key.should == 'abc'
10
+ Tumble::Config.consumer_secret.should == '123'
11
+ end
12
+ end
13
+
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tumble::Request::TumblrOAuth do
4
+ let(:oauth) { Tumble::Request::TumblrOAuth.new(lambda{ |env| env }, Hash.new) }
5
+ let(:request) do
6
+ {
7
+ :method => 'post',
8
+ :url => 'http://test.com/test.json',
9
+ :request_headers => {},
10
+ :body => { :status => 'Test' }
11
+ }
12
+ end
13
+
14
+ it 'should sign requests correctly' do
15
+ response = SimpleOAuth::Header.parse(oauth.call(request)[:request_headers]['Authorization'])
16
+ signature = response.delete(:signature)
17
+ header = SimpleOAuth::Header.new(:post, "http://test.com/test.json", { :status => 'Test' }, response)
18
+ signature.should == SimpleOAuth::Header.parse(header.to_s)[:signature]
19
+ end
20
+ 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.0.2'
6
+ s.version = '0.0.3'
7
7
 
8
8
  s.summary = 'Library for accessing the Tumblr api v2'
9
9
  # TODO: s.description
@@ -25,8 +25,12 @@ Gem::Specification.new do |s|
25
25
  lib/tumble.rb
26
26
  lib/tumble/blog.rb
27
27
  lib/tumble/client.rb
28
+ lib/tumble/config.rb
29
+ lib/tumble/request/oauth.rb
28
30
  spec/blog_spec.rb
29
31
  spec/client_spec.rb
32
+ spec/config_spec.rb
33
+ spec/oauth_spec.rb
30
34
  spec/spec_helper.rb
31
35
  tumble.gemspec
32
36
  ]
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.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
17
- requirement: &70198851703960 !ruby/object:Gem::Requirement
17
+ requirement: &70176759564620 !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: *70198851703960
25
+ version_requirements: *70176759564620
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rake
28
- requirement: &70198851703500 !ruby/object:Gem::Requirement
28
+ requirement: &70176759563740 !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: *70198851703500
36
+ version_requirements: *70176759563740
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &70198851703080 !ruby/object:Gem::Requirement
39
+ requirement: &70176759555780 !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: *70198851703080
47
+ version_requirements: *70176759555780
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: webmock
50
- requirement: &70198851702660 !ruby/object:Gem::Requirement
50
+ requirement: &70176759555040 !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: *70198851702660
58
+ version_requirements: *70176759555040
59
59
  description:
60
60
  email: aubreyholland@gmail.com
61
61
  executables: []
@@ -68,8 +68,12 @@ files:
68
68
  - lib/tumble.rb
69
69
  - lib/tumble/blog.rb
70
70
  - lib/tumble/client.rb
71
+ - lib/tumble/config.rb
72
+ - lib/tumble/request/oauth.rb
71
73
  - spec/blog_spec.rb
72
74
  - spec/client_spec.rb
75
+ - spec/config_spec.rb
76
+ - spec/oauth_spec.rb
73
77
  - spec/spec_helper.rb
74
78
  - tumble.gemspec
75
79
  has_rdoc: true