tumbl_rb 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -11,10 +11,12 @@ Simple Ruby wrapper for the Tumblr v2 API
11
11
 
12
12
  ## Examples
13
13
 
14
- ### Add your api_key (consumer_oauth_key)
14
+ ### Global Configuration
15
15
  ```ruby
16
16
  TumblRb.configure do |config|
17
- config.consumer_oauth_key = "1234567890"
17
+ config.consumer_oauth_key = "1234567890" # API KEY
18
+ config.timeout = 5 # OPEN/READ TIMEOUT
19
+ config.open_timeout = 5 # OPEN TIMEOUT
18
20
  end
19
21
  ```
20
22
 
@@ -10,7 +10,32 @@ module TumblRb
10
10
  # @example
11
11
  # TumblRb.info("andrewpthorp")
12
12
  def info(blog)
13
- get("/v2/blog/#{Blog.new blog}/info", {}, false)
13
+ get("/v2/blog/#{Blog.new blog}/info", {}, false, false)
14
+ end
15
+
16
+ # Get the avatar of a blog
17
+ #
18
+ # @param [String, Hash] blog to get avatar from
19
+ # @param [Integer] size of integer (16, 24, 30, 40, 48, 64, 96, 128, 512)
20
+ #
21
+ # @return [Hashie::Mash]
22
+ # @example
23
+ # TumblRb.avatar("andrewpthorp", 512)
24
+ def avatar(blog, size=64)
25
+ get("/v2/blog/#{Blog.new blog}/avatar/#{size}", {}, false, false)
26
+ end
27
+
28
+ # Get the followers of a blog
29
+ #
30
+ # @param [String, Hash] blog to get followers of
31
+ # @param [Integer] number of results (1-20, defaults 20)
32
+ # @param [Integer] result to start at (defaults 0)
33
+ #
34
+ # @return [Hashie::Mash]
35
+ # @example
36
+ # TumblRb.followers("andrewpthorp", 20, 0)
37
+ def followers(blog, limit=20, offset=0)
38
+ get("/v2/blog/#{Blog.new blog}/followers", { :limit => limit, :offset => offset }, false, false)
14
39
  end
15
40
 
16
41
 
@@ -8,11 +8,14 @@ module TumblRb
8
8
  :api_version,
9
9
  :proxy,
10
10
  :consumer_oauth_key,
11
+ :timeout,
12
+ :open_timeout,
11
13
  :user_agent].freeze
12
14
 
13
- DEFAULT_ADAPTER = Faraday.default_adapter
14
- DEFAULT_API_VERSION = 2
15
- DEFAULT_USER_AGENT = "TumblRb Ruby Gem #{TumblRb::VERSION}".freeze
15
+ DEFAULT_ADAPTER = Faraday.default_adapter
16
+ DEFAULT_API_VERSION = 2
17
+ DEFAULT_USER_AGENT = "TumblRb Ruby Gem #{TumblRb::VERSION}".freeze
18
+ DEFAULT_TIMEOUT = 10
16
19
 
17
20
  attr_accessor(*VALID_OPTIONS_KEYS)
18
21
 
@@ -34,6 +37,8 @@ module TumblRb
34
37
  self.consumer_oauth_key = nil
35
38
  self.proxy = nil
36
39
  self.user_agent = DEFAULT_USER_AGENT
40
+ self.timeout = DEFAULT_TIMEOUT
41
+ self.open_timeout = DEFAULT_TIMEOUT
37
42
  end
38
43
  end
39
44
  end
@@ -11,6 +11,8 @@ module TumblRb
11
11
  def request(method, path, options, raw, include_meta)
12
12
  response = connection(raw).send(method) do |request|
13
13
  request.url(path, options)
14
+ request.options[:timeout] = timeout
15
+ request.options[:open_timeout] = open_timeout
14
16
  end
15
17
 
16
18
  if raw
@@ -1,3 +1,3 @@
1
1
  module TumblRb
2
- VERSION = "0.1.0" unless defined?(TumblRb::VERSION)
2
+ VERSION = "0.1.1" unless defined?(TumblRb::VERSION)
3
3
  end
@@ -35,4 +35,24 @@ describe TumblRb::Client do
35
35
  end
36
36
  end
37
37
 
38
+ describe "timeout" do
39
+ before do
40
+ @blog = "andrewpthorp.tumblr.com"
41
+ end
42
+
43
+ it "should raise an error when a timeout happens" do
44
+ client = TumblRb::Client.new(:timeout => 0, :open_timeout => 0)
45
+ lambda {
46
+ client.info(@blog)
47
+ }.should raise_error
48
+ end
49
+
50
+ it "should not raise an error when a timeout doesn't happen" do
51
+ stub_request(:get, "http://api.tumblr.com/v2/blog/#{@blog}/info").to_return(:body => fixture("info.json"))
52
+ client = TumblRb::Client.new
53
+ lambda {
54
+ client.info(@blog)
55
+ }.should_not raise_error
56
+ end
57
+ end
38
58
  end
data/tumbl_rb.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.add_runtime_dependency 'faraday_middleware', '~> 0.8'
21
21
  s.add_runtime_dependency 'hashie', '~> 1.2'
22
22
  s.add_runtime_dependency 'multi_json', '~> 1.3'
23
+ s.add_runtime_dependency 'oauth', '~> 0.4'
23
24
 
24
25
  s.add_development_dependency 'json'
25
26
  s.add_development_dependency 'rake'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tumbl_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-25 00:00:00.000000000 Z
12
+ date: 2012-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -91,6 +91,22 @@ dependencies:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
93
  version: '1.3'
94
+ - !ruby/object:Gem::Dependency
95
+ name: oauth
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '0.4'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '0.4'
94
110
  - !ruby/object:Gem::Dependency
95
111
  name: json
96
112
  requirement: !ruby/object:Gem::Requirement