oembed_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +30 -0
- data/LICENSE.txt +20 -0
- data/README.md +48 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/oembed_client.rb +93 -0
- data/oembed_client.gemspec +71 -0
- data/test/fixtures/vcr_cassettes/flickr_response.yml +44 -0
- data/test/fixtures/vcr_cassettes/response.yml +34 -0
- data/test/fixtures/vcr_cassettes/youtube_response.yml +34 -0
- data/test/helper.rb +32 -0
- data/test/test_oembed_client.rb +47 -0
- metadata +141 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'multi_json'
|
4
|
+
|
5
|
+
# Add dependencies to develop your gem here.
|
6
|
+
# Include everything needed to run rake, tests, features, etc.
|
7
|
+
group :development do
|
8
|
+
gem "shoulda", ">= 0"
|
9
|
+
gem "bundler", "~> 1.0.0"
|
10
|
+
gem "jeweler", "~> 1.6.4"
|
11
|
+
gem "rcov", ">= 0"
|
12
|
+
gem 'webmock'
|
13
|
+
gem 'vcr'
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.2.6)
|
5
|
+
crack (0.3.1)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.6.4)
|
8
|
+
bundler (~> 1.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
multi_json (1.0.3)
|
12
|
+
rake (0.9.2)
|
13
|
+
rcov (0.9.11)
|
14
|
+
shoulda (2.11.3)
|
15
|
+
vcr (1.11.3)
|
16
|
+
webmock (1.7.6)
|
17
|
+
addressable (~> 2.2, > 2.2.5)
|
18
|
+
crack (>= 0.1.7)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
bundler (~> 1.0.0)
|
25
|
+
jeweler (~> 1.6.4)
|
26
|
+
multi_json
|
27
|
+
rcov
|
28
|
+
shoulda
|
29
|
+
vcr
|
30
|
+
webmock
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Brian Landau
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# oEmbed Client
|
2
|
+
|
3
|
+
A simple abstract oEmbed Client for ruby.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
gem install oembed_client
|
8
|
+
|
9
|
+
Or in your `Gemfile`:
|
10
|
+
|
11
|
+
gem 'oembed_client'
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Creating your own subclass:
|
16
|
+
|
17
|
+
require 'oembed_client'
|
18
|
+
|
19
|
+
class YoutubeOembedClient < OembedClient
|
20
|
+
base_url 'http://www.youtube.com/oembed'
|
21
|
+
default_options iframe: '1', maxwidth: '520'
|
22
|
+
end
|
23
|
+
|
24
|
+
c = YoutubeOembedClient.new('http://www.youtube.com/watch?v=4r7wHMg5Yjg')
|
25
|
+
c.embed_html # => "<iframe ..."
|
26
|
+
|
27
|
+
Automagically create a new class for a oEmbed service URL:
|
28
|
+
|
29
|
+
require 'oembed_client'
|
30
|
+
|
31
|
+
OembedClient.create_client_class_for('http://www.flickr.com/services/oembed')
|
32
|
+
c = OembedClient::Flickr.new('http://www.flickr.com/photos/brianlandau/6173724585/in/photostream')
|
33
|
+
c.url # => "http://farm7.static.flickr.com/6174/6173724585_8a984a740b.jpg"
|
34
|
+
|
35
|
+
## Contributing to oembed_client
|
36
|
+
|
37
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
38
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
39
|
+
* Fork the project
|
40
|
+
* Start a feature/bugfix branch
|
41
|
+
* Commit and push until you are happy with your contribution
|
42
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
43
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
44
|
+
|
45
|
+
# Copyright
|
46
|
+
|
47
|
+
Copyright (c) 2011 Brian Landau. See LICENSE.txt for
|
48
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "oembed_client"
|
18
|
+
gem.homepage = "http://github.com/brianjlandau/oembed_client"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A simple abstract oEmbed Client for ruby.}
|
21
|
+
gem.description = %Q{A simple abstract oEmbed Client for ruby.}
|
22
|
+
gem.email = "brianjlandau@gmail.com"
|
23
|
+
gem.authors = ["Brian Landau"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
test.rcov_opts << '--sort coverage'
|
42
|
+
test.rcov_opts << '--only-uncovered'
|
43
|
+
end
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'cgi'
|
3
|
+
require 'multi_json'
|
4
|
+
|
5
|
+
class OembedClient
|
6
|
+
attr_reader :url
|
7
|
+
|
8
|
+
STANDARD_RESPONSE_PARAMS = %w(type version title author_name author_url provider_name
|
9
|
+
provider_url cache_age thumbnail_url thumbnail_width thumbnail_height
|
10
|
+
url width height)
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def create_client_class_for(url)
|
14
|
+
client_name = URI.parse(url).host.split('.')[-2].capitalize
|
15
|
+
klass = const_set(client_name, Class.new(self))
|
16
|
+
klass.base_url(url)
|
17
|
+
klass
|
18
|
+
end
|
19
|
+
|
20
|
+
def base_url(url = nil)
|
21
|
+
if url.nil?
|
22
|
+
@base_url
|
23
|
+
else
|
24
|
+
@base_url = url
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def default_options(options = nil)
|
29
|
+
if options.nil?
|
30
|
+
@default_options ||= {}
|
31
|
+
else
|
32
|
+
@default_options = options
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize(url, embed_options = {})
|
38
|
+
@url = url
|
39
|
+
@embed_options = embed_options
|
40
|
+
end
|
41
|
+
|
42
|
+
def omembed_url
|
43
|
+
self.class.base_url+'?'+params
|
44
|
+
end
|
45
|
+
|
46
|
+
def params
|
47
|
+
querify_params(self.class.default_options.merge(@embed_options).merge(:url => @url, :format => 'json'))
|
48
|
+
end
|
49
|
+
|
50
|
+
def fetch
|
51
|
+
open(omembed_url)
|
52
|
+
end
|
53
|
+
|
54
|
+
def response
|
55
|
+
@response ||= fetch.read
|
56
|
+
end
|
57
|
+
|
58
|
+
def json
|
59
|
+
@json ||= MultiJson.decode(response)
|
60
|
+
end
|
61
|
+
|
62
|
+
def embed_html
|
63
|
+
json['html']
|
64
|
+
end
|
65
|
+
|
66
|
+
%w(photo video link rich).each do |embed_type|
|
67
|
+
define_method("#{embed_type}?") do
|
68
|
+
type == embed_type
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
STANDARD_RESPONSE_PARAMS.each do |attribute|
|
73
|
+
define_method(attribute) do
|
74
|
+
json[attribute]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def method_missing(name, *args, &block)
|
79
|
+
if json.keys.include?(name.to_s)
|
80
|
+
json[name.to_s]
|
81
|
+
else
|
82
|
+
super
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def querify_params(params)
|
89
|
+
params.map {|key, value|
|
90
|
+
"#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
|
91
|
+
}.join('&')
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{oembed_client}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Brian Landau}]
|
12
|
+
s.date = %q{2011-10-10}
|
13
|
+
s.description = %q{A simple abstract oEmbed Client for ruby.}
|
14
|
+
s.email = %q{brianjlandau@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/oembed_client.rb",
|
28
|
+
"oembed_client.gemspec",
|
29
|
+
"test/fixtures/vcr_cassettes/flickr_response.yml",
|
30
|
+
"test/fixtures/vcr_cassettes/response.yml",
|
31
|
+
"test/fixtures/vcr_cassettes/youtube_response.yml",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_oembed_client.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/brianjlandau/oembed_client}
|
36
|
+
s.licenses = [%q{MIT}]
|
37
|
+
s.require_paths = [%q{lib}]
|
38
|
+
s.rubygems_version = %q{1.8.6}
|
39
|
+
s.summary = %q{A simple abstract oEmbed Client for ruby.}
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<multi_json>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
48
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
49
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<webmock>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<vcr>, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<multi_json>, [">= 0"])
|
54
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
55
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
56
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
57
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
58
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
59
|
+
s.add_dependency(%q<vcr>, [">= 0"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<multi_json>, [">= 0"])
|
63
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
66
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
68
|
+
s.add_dependency(%q<vcr>, [">= 0"])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: http://www.flickr.com:80/services/oembed?format=json&url=http://www.flickr.com/photos/brianlandau/6173724585/in/photostream
|
6
|
+
body: !!null
|
7
|
+
headers: !!null
|
8
|
+
response: !ruby/struct:VCR::Response
|
9
|
+
status: !ruby/struct:VCR::ResponseStatus
|
10
|
+
code: 200
|
11
|
+
message: OK
|
12
|
+
headers:
|
13
|
+
date:
|
14
|
+
- Mon, 10 Oct 2011 03:32:50 GMT
|
15
|
+
p3p:
|
16
|
+
- policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV
|
17
|
+
TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY
|
18
|
+
ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"
|
19
|
+
set-cookie:
|
20
|
+
- localization=en-us%3Bus%3Bus; expires=Mon, 07-Oct-2013 03:32:50 GMT; path=/;
|
21
|
+
domain=.flickr.com
|
22
|
+
cache-control:
|
23
|
+
- private
|
24
|
+
x-served-by:
|
25
|
+
- www125.flickr.mud.yahoo.com
|
26
|
+
vary:
|
27
|
+
- Accept-Encoding
|
28
|
+
content-type:
|
29
|
+
- application/json
|
30
|
+
age:
|
31
|
+
- '0'
|
32
|
+
transfer-encoding:
|
33
|
+
- chunked
|
34
|
+
connection:
|
35
|
+
- keep-alive
|
36
|
+
via:
|
37
|
+
- HTTP/1.1 r19.ycpi.mud.yahoo.net (YahooTrafficServer/1.20.4 [cMsSf ])
|
38
|
+
server:
|
39
|
+
- YTS/1.20.4
|
40
|
+
body: ! '{"version":"1.0","type":"photo","author_url":"http:\/\/www.flickr.com\/photos\/brianlandau\/","cache_age":3600,"provider_name":"Flickr","provider_url":"http:\/\/www.flickr.com\/","title":"IMG_3930","author_name":"Brian
|
41
|
+
Landau","width":"500","height":"375","url":"http:\/\/farm7.static.flickr.com\/6174\/6173724585_8a984a740b.jpg"}
|
42
|
+
|
43
|
+
'
|
44
|
+
http_version: '1.1'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: http://www.youtube.com:80/oembed?format=json&iframe=1&maxwidth=520&url=http://www.youtube.com/watch?v=4r7wHMg5Yjg
|
6
|
+
body: !!null
|
7
|
+
headers: !!null
|
8
|
+
response: !ruby/struct:VCR::Response
|
9
|
+
status: !ruby/struct:VCR::ResponseStatus
|
10
|
+
code: 200
|
11
|
+
message: OK
|
12
|
+
headers:
|
13
|
+
date:
|
14
|
+
- Mon, 10 Oct 2011 03:24:09 GMT
|
15
|
+
server:
|
16
|
+
- Apache
|
17
|
+
x-content-type-options:
|
18
|
+
- nosniff
|
19
|
+
expires:
|
20
|
+
- Tue, 27 Apr 1971 19:44:06 EST
|
21
|
+
cache-control:
|
22
|
+
- no-cache
|
23
|
+
content-type:
|
24
|
+
- application/json
|
25
|
+
transfer-encoding:
|
26
|
+
- chunked
|
27
|
+
body: ! '{"provider_url": "http:\/\/www.youtube.com\/", "title": "The Crazy Nastyass
|
28
|
+
Honey Badger (original narration by Randall)", "html": "\u003ciframe width=\"459\"
|
29
|
+
height=\"344\" src=\"http:\/\/www.youtube.com\/embed\/4r7wHMg5Yjg?fs=1\" frameborder=\"0\"
|
30
|
+
allowfullscreen\u003e\u003c\/iframe\u003e", "author_name": "czg123", "height":
|
31
|
+
344, "thumbnail_width": 480, "width": 459, "version": "1.0", "author_url": "http:\/\/www.youtube.com\/user\/czg123",
|
32
|
+
"provider_name": "YouTube", "thumbnail_url": "http:\/\/i1.ytimg.com\/vi\/4r7wHMg5Yjg\/hqdefault.jpg",
|
33
|
+
"type": "video", "thumbnail_height": 360}'
|
34
|
+
http_version: '1.1'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: http://www.youtube.com:80/oembed?format=json&iframe=1&maxwidth=520&url=http://www.youtube.com/watch?v=4r7wHMg5Yjg
|
6
|
+
body: !!null
|
7
|
+
headers: !!null
|
8
|
+
response: !ruby/struct:VCR::Response
|
9
|
+
status: !ruby/struct:VCR::ResponseStatus
|
10
|
+
code: 200
|
11
|
+
message: OK
|
12
|
+
headers:
|
13
|
+
date:
|
14
|
+
- Mon, 10 Oct 2011 03:32:26 GMT
|
15
|
+
server:
|
16
|
+
- Apache
|
17
|
+
x-content-type-options:
|
18
|
+
- nosniff
|
19
|
+
expires:
|
20
|
+
- Tue, 27 Apr 1971 19:44:06 EST
|
21
|
+
cache-control:
|
22
|
+
- no-cache
|
23
|
+
content-type:
|
24
|
+
- application/json
|
25
|
+
transfer-encoding:
|
26
|
+
- chunked
|
27
|
+
body: ! '{"provider_url": "http:\/\/www.youtube.com\/", "title": "The Crazy Nastyass
|
28
|
+
Honey Badger (original narration by Randall)", "html": "\u003ciframe width=\"459\"
|
29
|
+
height=\"344\" src=\"http:\/\/www.youtube.com\/embed\/4r7wHMg5Yjg?fs=1\" frameborder=\"0\"
|
30
|
+
allowfullscreen\u003e\u003c\/iframe\u003e", "author_name": "czg123", "height":
|
31
|
+
344, "thumbnail_width": 480, "width": 459, "version": "1.0", "author_url": "http:\/\/www.youtube.com\/user\/czg123",
|
32
|
+
"provider_name": "YouTube", "thumbnail_url": "http:\/\/i1.ytimg.com\/vi\/4r7wHMg5Yjg\/hqdefault.jpg",
|
33
|
+
"type": "video", "thumbnail_height": 360}'
|
34
|
+
http_version: '1.1'
|
data/test/helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
require 'vcr'
|
13
|
+
require 'webmock'
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
17
|
+
require 'oembed_client'
|
18
|
+
|
19
|
+
class YoutubeOembedClient < OembedClient
|
20
|
+
base_url 'http://www.youtube.com/oembed'
|
21
|
+
default_options :iframe => '1', :maxwidth => '520'
|
22
|
+
end
|
23
|
+
|
24
|
+
VCR.config do |c|
|
25
|
+
c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
|
26
|
+
c.stub_with :webmock
|
27
|
+
c.default_cassette_options = { :record => :once }
|
28
|
+
c.allow_http_connections_when_no_cassette = true
|
29
|
+
end
|
30
|
+
|
31
|
+
class Test::Unit::TestCase
|
32
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestOembedClient < Test::Unit::TestCase
|
4
|
+
context 'OembedClient' do
|
5
|
+
should "be able to create a new client class on it's own" do
|
6
|
+
VCR.insert_cassette('flickr_response')
|
7
|
+
OembedClient.create_client_class_for('http://www.flickr.com/services/oembed')
|
8
|
+
OembedClient::Flickr.ancestors.include?(OembedClient)
|
9
|
+
assert_equal 'http://www.flickr.com/services/oembed', OembedClient::Flickr.base_url
|
10
|
+
c = OembedClient::Flickr.new('http://www.flickr.com/photos/brianlandau/6173724585/in/photostream')
|
11
|
+
assert_equal 'http://farm7.static.flickr.com/6174/6173724585_8a984a740b.jpg', c.url
|
12
|
+
assert c.photo?
|
13
|
+
VCR.eject_cassette
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'for existing YouTube client' do
|
17
|
+
setup do
|
18
|
+
VCR.insert_cassette('youtube_response')
|
19
|
+
@client = YoutubeOembedClient.new('http://www.youtube.com/watch?v=4r7wHMg5Yjg')
|
20
|
+
end
|
21
|
+
|
22
|
+
should 'correctly report that it is a video' do
|
23
|
+
assert @client.video?
|
24
|
+
end
|
25
|
+
|
26
|
+
should 'correctly report that it is not another type' do
|
27
|
+
assert !@client.photo?
|
28
|
+
assert !@client.link?
|
29
|
+
assert !@client.rich?
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'correctly report the title' do
|
33
|
+
assert_equal 'The Crazy Nastyass Honey Badger (original narration by Randall)',
|
34
|
+
@client.title
|
35
|
+
end
|
36
|
+
|
37
|
+
should 'correctly report the embed html' do
|
38
|
+
assert_equal %q{<iframe width="459" height="344" src="http://www.youtube.com/embed/4r7wHMg5Yjg?fs=1" frameborder="0" allowfullscreen></iframe>},
|
39
|
+
@client.embed_html
|
40
|
+
end
|
41
|
+
|
42
|
+
teardown do
|
43
|
+
VCR.eject_cassette
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oembed_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Landau
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-10 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: multi_json
|
16
|
+
requirement: &2153207640 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153207640
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: shoulda
|
27
|
+
requirement: &2153207160 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2153207160
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &2153206680 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.0.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2153206680
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: &2153206200 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.6.4
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2153206200
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rcov
|
60
|
+
requirement: &2153205720 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2153205720
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: &2153205240 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2153205240
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: vcr
|
82
|
+
requirement: &2153204760 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2153204760
|
91
|
+
description: A simple abstract oEmbed Client for ruby.
|
92
|
+
email: brianjlandau@gmail.com
|
93
|
+
executables: []
|
94
|
+
extensions: []
|
95
|
+
extra_rdoc_files:
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
files:
|
99
|
+
- .document
|
100
|
+
- Gemfile
|
101
|
+
- Gemfile.lock
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
105
|
+
- VERSION
|
106
|
+
- lib/oembed_client.rb
|
107
|
+
- oembed_client.gemspec
|
108
|
+
- test/fixtures/vcr_cassettes/flickr_response.yml
|
109
|
+
- test/fixtures/vcr_cassettes/response.yml
|
110
|
+
- test/fixtures/vcr_cassettes/youtube_response.yml
|
111
|
+
- test/helper.rb
|
112
|
+
- test/test_oembed_client.rb
|
113
|
+
homepage: http://github.com/brianjlandau/oembed_client
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
hash: -2977244797834292682
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 1.8.6
|
138
|
+
signing_key:
|
139
|
+
specification_version: 3
|
140
|
+
summary: A simple abstract oEmbed Client for ruby.
|
141
|
+
test_files: []
|