embedly 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source :rubygems
2
2
 
3
3
  gem "querystring"
4
4
  gem "oauth"
5
+ gem "typhoeus"
5
6
 
6
7
  group :development do
7
8
  gem "jeweler"
data/README.rdoc CHANGED
@@ -62,6 +62,9 @@ You can configure some parameters in the api:
62
62
 
63
63
  # use a custom logger
64
64
  config.logger = MyAwesomeLogger.new(STDERR)
65
+
66
+ # disable typhoeus and use Net::HTTP instead
67
+ config.typhoeus = false
65
68
  end
66
69
 
67
70
  == Testing
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.3.0
data/lib/embedly/api.rb CHANGED
@@ -7,6 +7,7 @@ require 'embedly/model'
7
7
  require 'embedly/exceptions'
8
8
  require 'querystring'
9
9
  require 'oauth'
10
+ require 'typhoeus'
10
11
 
11
12
  # Performs api calls to embedly.
12
13
  #
@@ -45,6 +46,7 @@ class Embedly::API
45
46
  # [:+key+] Your api.embed.ly key.
46
47
  # [:+secret+] Your api.embed.ly secret if you are using oauth.
47
48
  # [:+user_agent+] Your User-Agent header. Defaults to Mozilla/5.0 (compatible; embedly-ruby/VERSION;)
49
+ # [:+timeout+] Request timeout (in seconds). Defaults to 180 seconds or 3 minutes
48
50
  # [:+headers+] Additional headers to send with requests.
49
51
  def initialize opts={}
50
52
  @endpoints = [:oembed, :objectify, :preview]
@@ -53,15 +55,24 @@ class Embedly::API
53
55
  @api_version = Hash.new('1')
54
56
  @api_version.merge!({:objectify => '2'})
55
57
  @hostname = opts[:hostname] || 'api.embed.ly'
58
+ @timeout = opts[:timeout] || 180
56
59
  @headers = {
57
60
  'User-Agent' => opts[:user_agent] || "Mozilla/5.0 (compatible; embedly-ruby/#{Embedly::VERSION};)"
58
61
  }.merge(opts[:headers]||{})
59
62
  end
60
63
 
64
+ def _do_typhoeus_call path
65
+ scheme, host, port = uri_parse hostname
66
+ url = "#{scheme}://#{hostname}:#{port}#{path}"
67
+ logger.debug { "calling #{site}#{path} with headers #{headers} using Typhoeus" }
68
+ Typhoeus::Request.get(url, {:headers => headers, :timeout => (@timeout*1000) })
69
+ end
70
+
61
71
  def _do_basic_call path
62
72
  scheme, host, port = uri_parse hostname
63
- logger.debug { "calling #{site}#{path} with headers #{headers}" }
73
+ logger.debug { "calling #{site}#{path} with headers #{headers} using Net::HTTP" }
64
74
  Net::HTTP.start(host, port, :use_ssl => scheme == 'https') do |http|
75
+ http.read_timeout = @timeout
65
76
  http.get(path, headers)
66
77
  end
67
78
  end
@@ -83,7 +94,7 @@ class Embedly::API
83
94
  if key and secret
84
95
  _do_oauth_call path
85
96
  else
86
- _do_basic_call path
97
+ configuration.typhoeus ? _do_typhoeus_call(path) : _do_basic_call(path)
87
98
  end
88
99
  end
89
100
 
@@ -32,7 +32,8 @@ module Embedly
32
32
  :key => ENV['EMBEDLY_KEY'],
33
33
  :secret => ENV['EMBEDLY_SECRET'],
34
34
  :headers => {},
35
- :query => {}
35
+ :query => {},
36
+ :typhoeus => true
36
37
  }
37
38
  end
38
39
 
@@ -85,6 +86,10 @@ Usage [OPTIONS] <url> [url] ..
85
86
  options[:query][key.to_sym] = value
86
87
  end
87
88
 
89
+ parser.on("--no-typhoeus", "Don't use typhoeus.") do
90
+ Embedly.configuration.typhoeus = false
91
+ end
92
+
88
93
  parser.separator ""
89
94
  parser.separator "Common Options:"
90
95
 
@@ -121,6 +126,7 @@ Usage [OPTIONS] <url> [url] ..
121
126
 
122
127
  def options
123
128
  @options = Parser.parse!(@args.dup)
129
+ @options
124
130
  end
125
131
  end
126
132
  end
@@ -18,7 +18,7 @@ require 'logger'
18
18
  # end
19
19
  #
20
20
  class Embedly::Configuration
21
- attr_accessor :key # :nodoc:
21
+ attr_accessor :key, :typhoeus # :nodoc:
22
22
 
23
23
  def initialize # :nodoc:
24
24
  self.reset
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embedly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
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: querystring
17
- requirement: &69757780 !ruby/object:Gem::Requirement
17
+ requirement: &71434060 !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: *69757780
25
+ version_requirements: *71434060
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: oauth
28
- requirement: &69752680 !ruby/object:Gem::Requirement
28
+ requirement: &71433770 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,21 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *69752680
36
+ version_requirements: *71433770
37
+ - !ruby/object:Gem::Dependency
38
+ name: typhoeus
39
+ requirement: &71433500 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *71433500
37
48
  - !ruby/object:Gem::Dependency
38
49
  name: jeweler
39
- requirement: &69752030 !ruby/object:Gem::Requirement
50
+ requirement: &71433250 !ruby/object:Gem::Requirement
40
51
  none: false
41
52
  requirements:
42
53
  - - ! '>='
@@ -44,10 +55,10 @@ dependencies:
44
55
  version: '0'
45
56
  type: :development
46
57
  prerelease: false
47
- version_requirements: *69752030
58
+ version_requirements: *71433250
48
59
  - !ruby/object:Gem::Dependency
49
60
  name: cucumber
50
- requirement: &69751240 !ruby/object:Gem::Requirement
61
+ requirement: &71432930 !ruby/object:Gem::Requirement
51
62
  none: false
52
63
  requirements:
53
64
  - - ! '>='
@@ -55,10 +66,10 @@ dependencies:
55
66
  version: '0'
56
67
  type: :development
57
68
  prerelease: false
58
- version_requirements: *69751240
69
+ version_requirements: *71432930
59
70
  - !ruby/object:Gem::Dependency
60
71
  name: rake
61
- requirement: &69750240 !ruby/object:Gem::Requirement
72
+ requirement: &71432640 !ruby/object:Gem::Requirement
62
73
  none: false
63
74
  requirements:
64
75
  - - ! '>='
@@ -66,10 +77,10 @@ dependencies:
66
77
  version: '0'
67
78
  type: :development
68
79
  prerelease: false
69
- version_requirements: *69750240
80
+ version_requirements: *71432640
70
81
  - !ruby/object:Gem::Dependency
71
82
  name: rspec
72
- requirement: &69749290 !ruby/object:Gem::Requirement
83
+ requirement: &71432350 !ruby/object:Gem::Requirement
73
84
  none: false
74
85
  requirements:
75
86
  - - ! '>='
@@ -77,10 +88,10 @@ dependencies:
77
88
  version: '0'
78
89
  type: :development
79
90
  prerelease: false
80
- version_requirements: *69749290
91
+ version_requirements: *71432350
81
92
  - !ruby/object:Gem::Dependency
82
93
  name: yard
83
- requirement: &69748410 !ruby/object:Gem::Requirement
94
+ requirement: &71432060 !ruby/object:Gem::Requirement
84
95
  none: false
85
96
  requirements:
86
97
  - - ! '>='
@@ -88,10 +99,10 @@ dependencies:
88
99
  version: '0'
89
100
  type: :development
90
101
  prerelease: false
91
- version_requirements: *69748410
102
+ version_requirements: *71432060
92
103
  - !ruby/object:Gem::Dependency
93
104
  name: aruba
94
- requirement: &69747860 !ruby/object:Gem::Requirement
105
+ requirement: &71431780 !ruby/object:Gem::Requirement
95
106
  none: false
96
107
  requirements:
97
108
  - - ! '>='
@@ -99,7 +110,7 @@ dependencies:
99
110
  version: '0'
100
111
  type: :development
101
112
  prerelease: false
102
- version_requirements: *69747860
113
+ version_requirements: *71431780
103
114
  description: Ruby Embedly client library
104
115
  email: bob@embed.ly
105
116
  executables:
@@ -153,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
164
  version: '0'
154
165
  segments:
155
166
  - 0
156
- hash: -397755075
167
+ hash: 990086959
157
168
  required_rubygems_version: !ruby/object:Gem::Requirement
158
169
  none: false
159
170
  requirements: