roe 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,40 @@
1
+ *.gem
2
+ *.rbc
3
+ *.sw[a-p]
4
+ *.tmproj
5
+ *.tmproject
6
+ *.un~
7
+ *~
8
+ .DS_Store
9
+ .Spotlight-V100
10
+ .Trashes
11
+ ._*
12
+ .bundle
13
+ .config
14
+ .directory
15
+ .elc
16
+ .emacs.desktop
17
+ .emacs.desktop.lock
18
+ .redcar
19
+ .yardoc
20
+ Desktop.ini
21
+ Gemfile.lock
22
+ Icon?
23
+ InstalledFiles
24
+ Session.vim
25
+ Thumbs.db
26
+ \#*\#
27
+ _yardoc
28
+ auto-save-list
29
+ coverage
30
+ doc
31
+ lib/bundler/man
32
+ pkg
33
+ pkg/*
34
+ rdoc
35
+ spec/reports
36
+ test/tmp
37
+ test/version_tmp
38
+ tmp
39
+ tmtags
40
+ tramp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
@@ -0,0 +1 @@
1
+ SimpleCov.start
@@ -0,0 +1,3 @@
1
+ --markup markdown
2
+ -
3
+ LICENSE.md
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Steve Agalloco
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,73 @@
1
+ Roe
2
+ ===
3
+
4
+ Roe is a ruby oEmbed client.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ (sudo) gem install roe
10
+
11
+ Usage
12
+ -----
13
+
14
+ Roe exposes a method `resolve` for accessing oEmbed data:
15
+
16
+ ```ruby
17
+ Roe.resolve('http://twitpic.com/7745l9')
18
+ # => <Hashie::Rash version="1.0" type="photo" width=240 height=160 >
19
+ ```
20
+
21
+ You can pass an options hash (optional) to refine your query:
22
+
23
+ ```ruby
24
+ Roe.resolve('http://twitpic.com/7745l9', :maxheight => 240)
25
+ ```
26
+
27
+ Under the hood, Roe uses Faraday as well as MultiJson to parse the provider
28
+ responses. It then converts the response hash into a Hashie::Rash. You can
29
+ specify an http client by configuring Roe:
30
+
31
+ ```ruby
32
+ Roe.configure do |config|
33
+ config.adapter = :typhoeus
34
+ config.user_agent = 'oEmbed Client'
35
+ config.proxy = ENV['http_proxy']
36
+ end
37
+ ```
38
+
39
+ Supported Providers
40
+ -------------------
41
+
42
+ * YouTube
43
+ * Flickr
44
+ * Viddler
45
+ * Qik
46
+ * Hulu
47
+ * Revision 3
48
+ * Vimeo
49
+ * Opera
50
+ * Skitch
51
+ * Instagram
52
+
53
+ TODO
54
+ ----
55
+
56
+ * add the ability to dynamically add new services
57
+ * support for more providers
58
+
59
+ Note on Patches/Pull Requests
60
+ -----------------------------
61
+
62
+ * Fork the project.
63
+ * Make your feature addition or bug fix.
64
+ * Add tests for it. This is important so I don't break it in a
65
+ future version unintentionally.
66
+ * Commit, do not mess with rakefile, version, or history.
67
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
68
+ * Send me a pull request. Bonus points for topic branches.
69
+
70
+ Copyright
71
+ ---------
72
+
73
+ Copyright (c) 2011 Steve Agalloco. See LICENSE for details.
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
10
+ task :test => :spec
11
+
12
+ require 'yard'
13
+ namespace :doc do
14
+ YARD::Rake::YardocTask.new do |task|
15
+ task.files = ['LICENSE.md', 'lib/**/*.rb']
16
+ task.options = ['--markup', 'markdown']
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ require 'roe/configuration'
2
+ require 'roe/client'
3
+
4
+ module Roe
5
+ extend Configuration
6
+ extend self
7
+
8
+ @providers = [
9
+ { :pattern => /youtube\.com/, :service => 'http://www.youtube.com/oembed' },
10
+ { :pattern => /(flic\.kr|(www\.)?flickr.com)/, :service => 'http://www.flickr.com/services/oembed' },
11
+ { :pattern => /viddler\.com/, :service => 'http://lab.viddler.com/services/oembed/' },
12
+ { :pattern => /qik\.com/, :service => 'http://qik.com/api/oembed.json' },
13
+ { :pattern => /revision3\.com/, :service => 'http://revision3.com/api/oembed/' },
14
+ { :pattern => /hulu\.com/, :service => 'http://www.hulu.com/api/oembed' },
15
+ { :pattern => /vimeo\.com/, :service => 'http://vimeo.com/api/oembed.json' },
16
+ { :pattern => /opera\.com/, :service => 'http://my.opera.com/service/oembed' },
17
+ { :pattern => /skitch\.com/, :service => 'http://skitch.com/oembed' },
18
+ { :pattern => /instagr\.am/, :service => 'http://api.instagram.com/oembed' }
19
+ ]
20
+
21
+ def resolve(url, options = {})
22
+ @providers.each do |provider|
23
+ return Client.new(provider[:service]).resolve(url, options) if match?(provider[:pattern], url)
24
+ end
25
+
26
+ nil
27
+ end
28
+
29
+ private
30
+ def match?(pattern, url)
31
+ pattern.match(url)
32
+ end
33
+
34
+ end
@@ -0,0 +1,63 @@
1
+ require 'uri'
2
+ require 'faraday_middleware'
3
+
4
+ module Roe
5
+ class Client
6
+ attr_accessor :endpoint, :format
7
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
8
+
9
+ def initialize(endpoint, format = :json)
10
+ @endpoint = endpoint
11
+ @format = format
12
+
13
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
14
+ send("#{key}=", Roe.options[key])
15
+ end
16
+ end
17
+
18
+ def resolve(uri, options={})
19
+ response = connection.get do |req|
20
+ req.url endpoint_path, options.merge!(:url => uri, :format => format)
21
+ end
22
+ response.body.oembed || response.body
23
+ end
24
+
25
+ private
26
+ def connection
27
+ merged_options = connection_options.merge({
28
+ :headers => {
29
+ 'Accept' => "application/#{format}",
30
+ 'User-Agent' => user_agent
31
+ },
32
+ :proxy => proxy,
33
+ :url => endpoint_host
34
+ })
35
+
36
+ Faraday.new(merged_options) do |builder|
37
+ builder.use Faraday::Request::UrlEncoded
38
+ builder.use Faraday::Response::Rashify
39
+ case format.to_s
40
+ when 'xml'
41
+ builder.use Faraday::Response::ParseXml
42
+ when 'json'
43
+ builder.use Faraday::Response::ParseJson
44
+ end
45
+ builder.use Faraday::Response::RaiseError
46
+ builder.adapter(adapter)
47
+ end
48
+ end
49
+
50
+ def endpoint_path
51
+ parsed_endpoint.path
52
+ end
53
+
54
+ def endpoint_host
55
+ parsed_endpoint.scheme + '://' + parsed_endpoint.host
56
+ end
57
+
58
+ def parsed_endpoint
59
+ @parsed_endpoint ||= URI.parse(@endpoint)
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,53 @@
1
+ require 'roe/version'
2
+
3
+ module Roe
4
+ # Defines constants and methods related to configuration
5
+ module Configuration
6
+ # An array of valid keys in the options hash on configuration
7
+ VALID_OPTIONS_KEYS = [
8
+ :adapter,
9
+ :proxy,
10
+ :user_agent,
11
+ :connection_options].freeze
12
+
13
+ # The adapter that will be used to connect if none is set
14
+ DEFAULT_ADAPTER = :net_http
15
+
16
+ # By default, don't use a proxy server
17
+ DEFAULT_PROXY = nil
18
+
19
+ # The value sent in the 'User-Agent' header if none is set
20
+ DEFAULT_USER_AGENT = "Roe Ruby Gem #{Roe::VERSION}".freeze
21
+
22
+ DEFAULT_CONNECTION_OPTIONS = {}.freeze
23
+
24
+ # @private
25
+ attr_accessor *VALID_OPTIONS_KEYS
26
+
27
+ # When this module is extended, set all configuration options to their default values
28
+ def self.extended(base)
29
+ base.reset
30
+ end
31
+
32
+ # Convenience method to allow configuration options to be set in a block
33
+ def configure
34
+ yield self
35
+ end
36
+
37
+ # Create a hash of options and their values
38
+ def options
39
+ options = {}
40
+ VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
41
+ options
42
+ end
43
+
44
+ # Reset all configuration options to defaults
45
+ def reset
46
+ self.adapter = DEFAULT_ADAPTER
47
+ self.proxy = DEFAULT_PROXY
48
+ self.user_agent = DEFAULT_USER_AGENT
49
+ self.connection_options = DEFAULT_CONNECTION_OPTIONS
50
+ self
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module Roe
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/roe/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.version = Roe::VERSION
6
+ gem.name = 'roe'
7
+
8
+ gem.author = "Steve Agalloco"
9
+ gem.email = 'steve.agalloco@gmail.com'
10
+ gem.homepage = 'https://github.com/spagalloco/roe'
11
+ gem.description = 'A simple Ruby oEmbed client'
12
+ gem.summary = 'A simple Ruby oEmbed client'
13
+
14
+ gem.add_dependency "faraday_middleware", "~> 0.7"
15
+ gem.add_dependency "multi_json", "~> 1.0"
16
+ gem.add_dependency "multi_xml", "~> 0.4"
17
+ gem.add_dependency "hashie", "~> 1.1"
18
+ gem.add_dependency "rash", "~> 0.3"
19
+
20
+ gem.add_development_dependency 'rake', '~> 0.9'
21
+ gem.add_development_dependency 'rdiscount', '~> 1.6'
22
+ gem.add_development_dependency 'rspec', '~> 2.6'
23
+ gem.add_development_dependency 'simplecov', '~> 0.4'
24
+ gem.add_development_dependency 'yard', '~> 0.7'
25
+ gem.add_development_dependency 'webmock', '~> 1.7'
26
+ gem.add_development_dependency 'vcr', '~> 1.11'
27
+
28
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
29
+ gem.files = `git ls-files`.split("\n")
30
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
31
+ gem.require_paths = ['lib']
32
+ end
@@ -0,0 +1,184 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://vimeo.com:80/api/oembed.json?format=json&url=http://vimeo.com/7100569
6
+ body: !!null
7
+ headers:
8
+ accept:
9
+ - application/json
10
+ user-agent:
11
+ - Roe Ruby Gem 0.0.1
12
+ accept-encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ response: !ruby/struct:VCR::Response
15
+ status: !ruby/struct:VCR::ResponseStatus
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ date:
20
+ - Tue, 25 Oct 2011 05:05:39 GMT
21
+ server:
22
+ - Apache
23
+ x-powered-by:
24
+ - PHP/5.3.5-0.dotdeb.0
25
+ expires:
26
+ - Mon, 24 Oct 2011 17:05:39 GMT
27
+ cache-control:
28
+ - no-store, no-cache, must-revalidate
29
+ - post-check=0, pre-check=0
30
+ vary:
31
+ - Accept-Encoding
32
+ content-encoding:
33
+ - gzip
34
+ content-length:
35
+ - '345'
36
+ content-type:
37
+ - application/json
38
+ body: !binary |-
39
+ H4sIAAAAAAAAA3VQ2WrDMBD8FVXPwUd6pDFpoAf9gUKfBEa2N5FaWTbS2sGU
40
+ /ntXMiR1oU/SzO7Ozs4Xx6kHXvBRN9DxFR/Bed1ZYvIkI9y7LpRcaWUb+t51
41
+ G/vO/OAM0QqxL0Qq0jHUk7prRUpdqNGEqScnmyvCckDVnbWepYeJvXRWqgEu
42
+ 1f8V6zDQnPu1L3sz+OCVkMI2zO30wZE8865+EBeV3sgJXPJLLF4s0k2eZbd3
43
+ W8HZSTeoaCZf32cEFeijQsKbdYBRteoc3UxcYE5QfWp8NKY7vQ7GvNUOwDK5
44
+ xPudSGdHe/IYV/AibCDDcQEvSH/Fm8FJjMHn+T1B8LXT/czE+NhBW9Ke2BHQ
45
+ M1TAJCLY0EFWGQ2AG8EnIXU1tJWV2vyNsprvrxs7R4BepOvtjUjJUPzRe52V
46
+ wV7y0R8XUgvrF3pxRIy01A3BOdXvH6QjkP9gAgAA
47
+ http_version: '1.1'
48
+ - !ruby/struct:VCR::HTTPInteraction
49
+ request: !ruby/struct:VCR::Request
50
+ method: :get
51
+ uri: http://www.hulu.com:80/api/oembed.json?format=json&url=http://www.hulu.com/watch/20807/late-night-with-conan-obrien-wed-may-21-2008
52
+ body: !!null
53
+ headers:
54
+ accept:
55
+ - application/json
56
+ user-agent:
57
+ - Roe Ruby Gem 0.0.1
58
+ accept-encoding:
59
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
60
+ response: !ruby/struct:VCR::Response
61
+ status: !ruby/struct:VCR::ResponseStatus
62
+ code: 200
63
+ message: OK
64
+ headers:
65
+ server:
66
+ - nginx
67
+ content-type:
68
+ - application/json; charset=utf-8
69
+ status:
70
+ - 200 OK
71
+ p3p:
72
+ - CP="NOI DSP COR NID ADMa OPTa OUR NOR"
73
+ x-ua-compatible:
74
+ - IE=EmulateIE9; IE=EmulateIE7
75
+ content-length:
76
+ - '921'
77
+ cache-control:
78
+ - max-age=3600
79
+ date:
80
+ - Tue, 25 Oct 2011 05:05:39 GMT
81
+ connection:
82
+ - keep-alive
83
+ body: ! '{"provider_name": "Hulu", "type": "video", "title": "Wed, May 21, 2008
84
+ (Late Night with Conan O''Brien)", "provider_url": "http://www.hulu.com/", "air_date":
85
+ {}, "duration": 2543.98, "height": 296, "cache_age": 3600, "embed_url": "http://www.hulu.com/embed/0-njKp22bl4GivFXH0lh5w",
86
+ "width": 512, "html": "\u003cobject width=\"512\" height=\"296\"\u003e\u003cparam
87
+ name=\"movie\" value=\"http://www.hulu.com/embed/0-njKp22bl4GivFXH0lh5w\"\u003e\u003c/param\u003e\u003cparam
88
+ name=\"flashvars\" value=\"ap=1\"\u003e\u003c/param\u003e\u003cembed src=\"http://www.hulu.com/embed/0-njKp22bl4GivFXH0lh5w\"
89
+ type=\"application/x-shockwave-flash\" width=\"512\" height=\"296\" flashvars=\"ap=1\"\u003e\u003c/embed\u003e\u003c/object\u003e",
90
+ "author_name": "NBC", "version": "1.0", "thumbnail_width": 145, "thumbnail_url":
91
+ "http://thumbnails.hulu.com/8/500/23678_145x80_manicured__SIXr9mO9sUO3dYt+S-XTIw.jpg",
92
+ "thumbnail_height": 80}'
93
+ http_version: '1.1'
94
+ - !ruby/struct:VCR::HTTPInteraction
95
+ request: !ruby/struct:VCR::Request
96
+ method: :get
97
+ uri: http://www.hulu.com:80/api/oembed.xml?format=xml&url=http://www.hulu.com/watch/20807/late-night-with-conan-obrien-wed-may-21-2008
98
+ body: !!null
99
+ headers:
100
+ accept:
101
+ - application/xml
102
+ user-agent:
103
+ - Roe Ruby Gem 0.0.1
104
+ accept-encoding:
105
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
106
+ response: !ruby/struct:VCR::Response
107
+ status: !ruby/struct:VCR::ResponseStatus
108
+ code: 200
109
+ message: OK
110
+ headers:
111
+ server:
112
+ - nginx
113
+ content-type:
114
+ - application/xml; charset=utf-8
115
+ status:
116
+ - 200 OK
117
+ p3p:
118
+ - CP="NOI DSP COR NID ADMa OPTa OUR NOR"
119
+ x-ua-compatible:
120
+ - IE=EmulateIE9; IE=EmulateIE7
121
+ ntcoent-length:
122
+ - '1110'
123
+ vary:
124
+ - Accept-Encoding
125
+ cache-control:
126
+ - max-age=3600
127
+ date:
128
+ - Tue, 25 Oct 2011 05:05:40 GMT
129
+ content-length:
130
+ - '1110'
131
+ connection:
132
+ - keep-alive
133
+ body: ! "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<oembed>\n <type>video</type>\n
134
+ \ <thumbnail_height>80</thumbnail_height>\n <title>Wed, May 21, 2008 (Late
135
+ Night with Conan O'Brien)</title>\n <embed_url>http://www.hulu.com/embed/0-njKp22bl4GivFXH0lh5w</embed_url>\n
136
+ \ <provider_name>Hulu</provider_name>\n <height>296</height>\n <width>512</width>\n
137
+ \ <html>&lt;object width=\"512\" height=\"296\"&gt;&lt;param name=\"movie\"
138
+ value=\"http://www.hulu.com/embed/0-njKp22bl4GivFXH0lh5w\"&gt;&lt;/param&gt;&lt;param
139
+ name=\"flashvars\" value=\"ap=1\"&gt;&lt;/param&gt;&lt;embed src=\"http://www.hulu.com/embed/0-njKp22bl4GivFXH0lh5w\"
140
+ type=\"application/x-shockwave-flash\" width=\"512\" height=\"296\" flashvars=\"ap=1\"&gt;&lt;/embed&gt;&lt;/object&gt;</html>\n
141
+ \ <provider_url>http://www.hulu.com/</provider_url>\n <version>1.0</version>\n
142
+ \ <cache_age>3600</cache_age>\n <thumbnail_url>http://thumbnails.hulu.com/8/500/23678_145x80_manicured__SIXr9mO9sUO3dYt+S-XTIw.jpg</thumbnail_url>\n
143
+ \ <duration>2543.98</duration>\n <author_name>NBC</author_name>\n <air_date>Wed
144
+ May 21 00:00:00 UTC 2008</air_date>\n <thumbnail_width>145</thumbnail_width>\n</oembed>\n"
145
+ http_version: '1.1'
146
+ - !ruby/struct:VCR::HTTPInteraction
147
+ request: !ruby/struct:VCR::Request
148
+ method: :get
149
+ uri: http://vimeo.com:80/api/oembed.json?format=json&url=123
150
+ body: !!null
151
+ headers:
152
+ accept:
153
+ - application/json
154
+ user-agent:
155
+ - Roe Ruby Gem 0.0.1
156
+ accept-encoding:
157
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
158
+ response: !ruby/struct:VCR::Response
159
+ status: !ruby/struct:VCR::ResponseStatus
160
+ code: 404
161
+ message: Not Found
162
+ headers:
163
+ date:
164
+ - Sun, 30 Oct 2011 19:29:12 GMT
165
+ server:
166
+ - Apache
167
+ x-powered-by:
168
+ - PHP/5.3.5-0.dotdeb.0
169
+ expires:
170
+ - Sun, 30 Oct 2011 07:29:12 GMT
171
+ cache-control:
172
+ - no-store, no-cache, must-revalidate
173
+ - post-check=0, pre-check=0
174
+ vary:
175
+ - Accept-Encoding
176
+ content-encoding:
177
+ - gzip
178
+ content-length:
179
+ - '33'
180
+ content-type:
181
+ - text/html; charset=UTF-8
182
+ body: !binary |-
183
+ H4sIAAAAAAAAAzMxMFHwyy9RcMsvzUsBAJJUDlwNAAAA
184
+ http_version: '1.1'
@@ -0,0 +1,87 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://www.hulu.com:80/api/oembed.json?format=json&url=http://www.hulu.com/watch/240024/family-guy-episode-vi-its-a-trap
6
+ body: !!null
7
+ headers:
8
+ accept:
9
+ - application/json
10
+ user-agent:
11
+ - Roe Ruby Gem 0.0.1
12
+ accept-encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ response: !ruby/struct:VCR::Response
15
+ status: !ruby/struct:VCR::ResponseStatus
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ server:
20
+ - nginx
21
+ content-type:
22
+ - application/json; charset=utf-8
23
+ status:
24
+ - 200 OK
25
+ p3p:
26
+ - CP="NOI DSP COR NID ADMa OPTa OUR NOR"
27
+ x-ua-compatible:
28
+ - IE=EmulateIE9; IE=EmulateIE7
29
+ content-length:
30
+ - '892'
31
+ cache-control:
32
+ - max-age=3580
33
+ date:
34
+ - Tue, 25 Oct 2011 05:05:40 GMT
35
+ connection:
36
+ - keep-alive
37
+ body: ! '{"thumbnail_height": 80, "type": "video", "title": "Episode VI: It''s
38
+ a Trap (Family Guy)", "provider_name": "Hulu", "embed_url": "http://www.hulu.com/embed/aEKsCa0CKH1QI798K_-dMA",
39
+ "height": 296, "provider_url": "http://www.hulu.com/", "width": 512, "html":
40
+ "\u003cobject width=\"512\" height=\"296\"\u003e\u003cparam name=\"movie\" value=\"http://www.hulu.com/embed/aEKsCa0CKH1QI798K_-dMA\"\u003e\u003c/param\u003e\u003cparam
41
+ name=\"flashvars\" value=\"ap=1\"\u003e\u003c/param\u003e\u003cembed src=\"http://www.hulu.com/embed/aEKsCa0CKH1QI798K_-dMA\"
42
+ type=\"application/x-shockwave-flash\" width=\"512\" height=\"296\" flashvars=\"ap=1\"\u003e\u003c/embed\u003e\u003c/object\u003e",
43
+ "cache_age": 3600, "version": "1.0", "duration": 2622.95, "author_name": "FOX",
44
+ "air_date": {}, "thumbnail_width": 145, "thumbnail_url": "http://thumbnails.hulu.com/440/50147440/269257_145x80_generated.jpg"}'
45
+ http_version: '1.1'
46
+ - !ruby/struct:VCR::HTTPInteraction
47
+ request: !ruby/struct:VCR::Request
48
+ method: :get
49
+ uri: http://www.hulu.com:80/api/oembed?format=json&url=http://www.hulu.com/watch/240024/family-guy-episode-vi-its-a-trap
50
+ body: !!null
51
+ headers:
52
+ accept:
53
+ - application/json
54
+ user-agent:
55
+ - Roe Ruby Gem 0.0.1
56
+ accept-encoding:
57
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
58
+ response: !ruby/struct:VCR::Response
59
+ status: !ruby/struct:VCR::ResponseStatus
60
+ code: 200
61
+ message: OK
62
+ headers:
63
+ server:
64
+ - nginx
65
+ content-type:
66
+ - application/json; charset=utf-8
67
+ status:
68
+ - 200 OK
69
+ p3p:
70
+ - CP="NOI DSP COR NID ADMa OPTa OUR NOR"
71
+ x-ua-compatible:
72
+ - IE=EmulateIE9; IE=EmulateIE7
73
+ content-length:
74
+ - '809'
75
+ cache-control:
76
+ - max-age=3600
77
+ date:
78
+ - Fri, 04 Nov 2011 04:49:43 GMT
79
+ connection:
80
+ - keep-alive
81
+ body: ! '{"type":"video","provider_name":"Hulu","duration":2622.95,"provider_url":"http://www.hulu.com/","thumbnail_url":"http://thumbnails.hulu.com/440/50147440/269257_145x80_generated.jpg","title":"Episode
82
+ VI: It''s a Trap (Family Guy)","width":512,"cache_age":3600,"embed_url":"http://www.hulu.com/embed/aEKsCa0CKH1QI798K_-dMA","author_name":"FOX","version":"1.0","air_date":"Sun
83
+ May 22 00:00:00 UTC 2011","height":296,"thumbnail_width":145,"html":"<object
84
+ width=\"512\" height=\"296\"><param name=\"movie\" value=\"http://www.hulu.com/embed/aEKsCa0CKH1QI798K_-dMA\"></param><param
85
+ name=\"flashvars\" value=\"ap=1\"></param><embed src=\"http://www.hulu.com/embed/aEKsCa0CKH1QI798K_-dMA\"
86
+ type=\"application/x-shockwave-flash\" width=\"512\" height=\"296\" flashvars=\"ap=1\"></embed></object>","thumbnail_height":80}'
87
+ http_version: '1.1'
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roe::Client do
4
+
5
+ use_vcr_cassette "client", :record => :new_episodes
6
+
7
+ describe '.new' do
8
+ it 'initializes with a url' do
9
+ client = Roe::Client.new('http://www.youtube.com/oembed')
10
+ client.endpoint.should eq('http://www.youtube.com/oembed')
11
+ end
12
+
13
+ it 'defaults the format to json' do
14
+ client = Roe::Client.new('http://www.youtube.com/oembed')
15
+ client.format.should eq(:json)
16
+ end
17
+
18
+ it 'accepts an optional format argument' do
19
+ client = Roe::Client.new('http://www.youtube.com/oembed', :xml)
20
+ client.format.should eq(:xml)
21
+ end
22
+ end
23
+
24
+ describe '#resolve' do
25
+ it 'returns a Hashie::Rash' do
26
+ client = Roe::Client.new('http://vimeo.com/api/oembed.json')
27
+ client.resolve('http://vimeo.com/7100569').should be_kind_of(Hashie::Rash)
28
+ end
29
+
30
+ it 'returns oembed data using json format' do
31
+ client = Roe::Client.new('http://www.hulu.com/api/oembed.json')
32
+ data = client.resolve('http://www.hulu.com/watch/20807/late-night-with-conan-obrien-wed-may-21-2008')
33
+ data.embed_url.should be
34
+ end
35
+
36
+ it 'returns oembed data using xml format' do
37
+ client = Roe::Client.new('http://www.hulu.com/api/oembed.xml', :xml)
38
+ data = client.resolve('http://www.hulu.com/watch/20807/late-night-with-conan-obrien-wed-may-21-2008')
39
+ data.embed_url.should be
40
+ end
41
+
42
+ it 'raises a Faraday error when passing invalid arguments' do
43
+ client = Roe::Client.new('http://vimeo.com/api/oembed.json')
44
+ lambda {
45
+ client.resolve('123')
46
+ }.should raise_error
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roe do
4
+ after do
5
+ Roe.reset
6
+ end
7
+
8
+ use_vcr_cassette "roe", :record => :new_episodes
9
+
10
+ describe ".resolve" do
11
+ it 'returns a Hashie::Rash' do
12
+ data = Roe.resolve('http://www.hulu.com/watch/240024/family-guy-episode-vi-its-a-trap')
13
+ data.should be_kind_of(Hashie::Rash)
14
+ end
15
+
16
+ it 'returns oembed data' do
17
+ data = Roe.resolve('http://www.hulu.com/watch/240024/family-guy-episode-vi-its-a-trap')
18
+ data.embed_url.should be
19
+ end
20
+
21
+ it 'returns nil when no data found' do
22
+ data = Roe.resolve('http://m.cnn.com/')
23
+ data.should be_nil
24
+ end
25
+ end
26
+
27
+ describe ".adapter" do
28
+ it "should return the default adapter" do
29
+ Roe.adapter.should == Roe::Configuration::DEFAULT_ADAPTER
30
+ end
31
+ end
32
+
33
+ describe ".adapter=" do
34
+ it "should set the adapter" do
35
+ Roe.adapter = :typhoeus
36
+ Roe.adapter.should == :typhoeus
37
+ end
38
+ end
39
+
40
+ describe ".user_agent" do
41
+ it "should return the default user agent" do
42
+ Roe.user_agent.should == Roe::Configuration::DEFAULT_USER_AGENT
43
+ end
44
+ end
45
+
46
+ describe ".user_agent=" do
47
+ it "should set the user_agent" do
48
+ Roe.user_agent = 'Custom User Agent'
49
+ Roe.user_agent.should == 'Custom User Agent'
50
+ end
51
+ end
52
+
53
+ describe ".configure" do
54
+ Roe::Configuration::VALID_OPTIONS_KEYS.each do |key|
55
+ it "should set the #{key}" do
56
+ Roe.configure do |config|
57
+ config.send("#{key}=", key)
58
+ Roe.send(key).should == key
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,17 @@
1
+ require 'simplecov'
2
+
3
+ $:.unshift File.expand_path('..', __FILE__)
4
+ $:.unshift File.expand_path('../../lib', __FILE__)
5
+
6
+ require 'roe'
7
+ require 'rspec'
8
+ require 'vcr'
9
+
10
+ RSpec.configure do |c|
11
+ c.extend VCR::RSpec::Macros
12
+ end
13
+
14
+ VCR.config do |c|
15
+ c.cassette_library_dir = 'spec/fixtures'
16
+ c.stub_with :webmock
17
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Steve Agalloco
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-14 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday_middleware
16
+ requirement: &70246493480000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.7'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70246493480000
25
+ - !ruby/object:Gem::Dependency
26
+ name: multi_json
27
+ requirement: &70246493479300 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70246493479300
36
+ - !ruby/object:Gem::Dependency
37
+ name: multi_xml
38
+ requirement: &70246493478260 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '0.4'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70246493478260
47
+ - !ruby/object:Gem::Dependency
48
+ name: hashie
49
+ requirement: &70246493477800 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70246493477800
58
+ - !ruby/object:Gem::Dependency
59
+ name: rash
60
+ requirement: &70246493477320 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '0.3'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70246493477320
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: &70246493476640 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '0.9'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70246493476640
80
+ - !ruby/object:Gem::Dependency
81
+ name: rdiscount
82
+ requirement: &70246493475900 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: '1.6'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70246493475900
91
+ - !ruby/object:Gem::Dependency
92
+ name: rspec
93
+ requirement: &70246493475360 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: '2.6'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70246493475360
102
+ - !ruby/object:Gem::Dependency
103
+ name: simplecov
104
+ requirement: &70246493474760 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '0.4'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70246493474760
113
+ - !ruby/object:Gem::Dependency
114
+ name: yard
115
+ requirement: &70246493474260 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ~>
119
+ - !ruby/object:Gem::Version
120
+ version: '0.7'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *70246493474260
124
+ - !ruby/object:Gem::Dependency
125
+ name: webmock
126
+ requirement: &70246493473360 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '1.7'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: *70246493473360
135
+ - !ruby/object:Gem::Dependency
136
+ name: vcr
137
+ requirement: &70246493472860 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ~>
141
+ - !ruby/object:Gem::Version
142
+ version: '1.11'
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: *70246493472860
146
+ description: A simple Ruby oEmbed client
147
+ email: steve.agalloco@gmail.com
148
+ executables: []
149
+ extensions: []
150
+ extra_rdoc_files: []
151
+ files:
152
+ - .gemtest
153
+ - .gitignore
154
+ - .rspec
155
+ - .simplecov
156
+ - .yardopts
157
+ - Gemfile
158
+ - LICENSE.md
159
+ - README.md
160
+ - Rakefile
161
+ - lib/roe.rb
162
+ - lib/roe/client.rb
163
+ - lib/roe/configuration.rb
164
+ - lib/roe/version.rb
165
+ - roe.gemspec
166
+ - spec/fixtures/client.yml
167
+ - spec/fixtures/roe.yml
168
+ - spec/roe/client_spec.rb
169
+ - spec/roe_spec.rb
170
+ - spec/spec_helper.rb
171
+ homepage: https://github.com/spagalloco/roe
172
+ licenses: []
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ none: false
185
+ requirements:
186
+ - - ! '>='
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ requirements: []
190
+ rubyforge_project:
191
+ rubygems_version: 1.8.10
192
+ signing_key:
193
+ specification_version: 3
194
+ summary: A simple Ruby oEmbed client
195
+ test_files:
196
+ - spec/fixtures/client.yml
197
+ - spec/fixtures/roe.yml
198
+ - spec/roe/client_spec.rb
199
+ - spec/roe_spec.rb
200
+ - spec/spec_helper.rb
201
+ has_rdoc: