ruby-oembed 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -0
- data/Rakefile +16 -0
- data/VERSION +1 -0
- data/idea.rb +59 -0
- data/integration_test/test.rb +31 -0
- data/integration_test/test_urls.csv +502 -0
- data/lib/oembed.rb +14 -0
- data/lib/oembed/embedly_urls.json +143 -0
- data/lib/oembed/errors.rb +28 -0
- data/lib/oembed/formatters.rb +29 -0
- data/lib/oembed/provider.rb +86 -0
- data/lib/oembed/provider_discovery.rb +55 -0
- data/lib/oembed/providers.rb +156 -0
- data/lib/oembed/response.rb +59 -0
- data/lib/oembed/response/link.rb +6 -0
- data/lib/oembed/response/photo.rb +9 -0
- data/lib/oembed/response/rich.rb +6 -0
- data/lib/oembed/response/video.rb +6 -0
- data/rails/init.rb +3 -0
- data/ruby-oembed.gemspec +75 -0
- data/spec/provider_spec.rb +175 -0
- data/spec/providers_spec.rb +125 -0
- data/spec/response_spec.rb +90 -0
- data/spec/spec_helper.rb +69 -0
- metadata +125 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe OEmbed::Response do
|
4
|
+
include OEmbedSpecHelper
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@flickr = OEmbed::Provider.new("http://www.flickr.com/services/oembed/")
|
8
|
+
@qik = OEmbed::Provider.new("http://qik.com/api/oembed.{format}", :xml)
|
9
|
+
@viddler = OEmbed::Provider.new("http://lab.viddler.com/services/oembed/", :json)
|
10
|
+
|
11
|
+
@flickr << "http://*.flickr.com/*"
|
12
|
+
@qik << "http://qik.com/video/*"
|
13
|
+
@qik << "http://qik.com/*"
|
14
|
+
@viddler << "http://*.viddler.com/*"
|
15
|
+
|
16
|
+
@new_res = OEmbed::Response.new(valid_response(:object), OEmbed::Providers::OohEmbed)
|
17
|
+
|
18
|
+
@default_res = OEmbed::Response.create_for(valid_response(:json), @flickr)
|
19
|
+
@xml_res = OEmbed::Response.create_for(valid_response(:xml), @qik, :xml)
|
20
|
+
@json_res = OEmbed::Response.create_for(valid_response(:json), @viddler, :json)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should set the provider" do
|
24
|
+
@new_res.provider.should == OEmbed::Providers::OohEmbed
|
25
|
+
|
26
|
+
@default_res.provider.should == @flickr
|
27
|
+
@xml_res.provider.should == @qik
|
28
|
+
@json_res.provider.should == @viddler
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should parse the data into #fields" do
|
32
|
+
@new_res.fields.keys.should == valid_response(:object).keys
|
33
|
+
|
34
|
+
@default_res.fields.keys.should == valid_response(:object).keys
|
35
|
+
@xml_res.fields.keys.should == valid_response(:object).keys
|
36
|
+
@json_res.fields.keys.should == valid_response(:object).keys
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should only allow JSON or XML" do
|
40
|
+
lambda do
|
41
|
+
OEmbed::Response.create_for(valid_response(:json), @flickr, :json)
|
42
|
+
end.should_not raise_error(OEmbed::FormatNotSupported)
|
43
|
+
|
44
|
+
lambda do
|
45
|
+
OEmbed::Response.create_for(valid_response(:xml), @flickr, :xml)
|
46
|
+
end.should_not raise_error(OEmbed::FormatNotSupported)
|
47
|
+
|
48
|
+
lambda do
|
49
|
+
OEmbed::Response.create_for(valid_response(:yml), @flickr, :yml)
|
50
|
+
end.should raise_error(OEmbed::FormatNotSupported)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not parse the incorrect format" do
|
54
|
+
lambda do
|
55
|
+
OEmbed::Response.create_for(valid_response(:xml), @flickr)
|
56
|
+
end.should raise_error(JSON::ParserError)
|
57
|
+
|
58
|
+
lambda do
|
59
|
+
OEmbed::Response.create_for(valid_response(:xml), @viddler, :json)
|
60
|
+
end.should raise_error(JSON::ParserError)
|
61
|
+
|
62
|
+
lambda do
|
63
|
+
OEmbed::Response.create_for(valid_response(:json), @viddler, :xml)
|
64
|
+
end.should raise_error(ArgumentError)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should access the XML data through #field" do
|
68
|
+
@xml_res.field(:type).should == "photo"
|
69
|
+
@xml_res.field(:version).should == "1.0"
|
70
|
+
@xml_res.field(:fields).should == "hello"
|
71
|
+
@xml_res.field(:__id__).should == "1234"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should access the JSON data through #field" do
|
75
|
+
@json_res.field(:type).should == "photo"
|
76
|
+
@json_res.field(:version).should == "1.0"
|
77
|
+
@json_res.field(:fields).should == "hello"
|
78
|
+
@json_res.field(:__id__).should == 1234
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should automagically define helpers" do
|
82
|
+
@default_res.type.should == "photo"
|
83
|
+
@default_res.version.should == "1.0"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should protect important methods" do
|
87
|
+
@default_res.fields.should_not == @default_res.field(:fields)
|
88
|
+
@default_res.__id__.should_not == @default_res.field(:__id__)
|
89
|
+
end
|
90
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/oembed'
|
3
|
+
|
4
|
+
module OEmbedSpecHelper
|
5
|
+
EXAMPLE = {
|
6
|
+
:flickr => "http://flickr.com/photos/bees/2362225867/",
|
7
|
+
:viddler => "http://www.viddler.com/explore/cdevroe/videos/424/",
|
8
|
+
:qik => "http://qik.com/video/49565",
|
9
|
+
:vimeo => "http://vimeo.com/3100878",
|
10
|
+
:pownce => "http://pownce.com/mmalone/notes/1756545/",
|
11
|
+
:rev3 => "http://revision3.com/diggnation/2008-04-17xsanned/",
|
12
|
+
:hulu => "http://www.hulu.com/watch/4569/firefly-serenity#x-0,vepisode,1",
|
13
|
+
:google_video => "http://video.google.com/videoplay?docid=8372603330420559198",
|
14
|
+
}
|
15
|
+
|
16
|
+
def example_url(site)
|
17
|
+
return "http://fake.com/" if site == :fake
|
18
|
+
EXAMPLE[site]
|
19
|
+
end
|
20
|
+
|
21
|
+
def all_example_urls(*fallback)
|
22
|
+
results = EXAMPLE.values
|
23
|
+
|
24
|
+
# By default don't return example_urls that won't be recognized by
|
25
|
+
# the included default providers
|
26
|
+
results.delete(example_url(:google_video))
|
27
|
+
|
28
|
+
# If requested, return URLs that should work with various fallback providers
|
29
|
+
fallback.each do |f|
|
30
|
+
case f
|
31
|
+
when OEmbed::Providers::OohEmbed
|
32
|
+
results << example_url(:google_video)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
results
|
37
|
+
end
|
38
|
+
|
39
|
+
def valid_response(format)
|
40
|
+
case format
|
41
|
+
when :object
|
42
|
+
{
|
43
|
+
"type" => "photo",
|
44
|
+
"version" => "1.0",
|
45
|
+
"fields" => "hello",
|
46
|
+
"__id__" => 1234
|
47
|
+
}
|
48
|
+
when :json
|
49
|
+
<<-JSON
|
50
|
+
{
|
51
|
+
"type": "photo",
|
52
|
+
"version": "1.0",
|
53
|
+
"fields": "hello",
|
54
|
+
"__id__": 1234
|
55
|
+
}
|
56
|
+
JSON
|
57
|
+
when :xml
|
58
|
+
<<-XML
|
59
|
+
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
60
|
+
<oembed>
|
61
|
+
<type>photo</type>
|
62
|
+
<version>1.0</version>
|
63
|
+
<fields>hello</fields>
|
64
|
+
<__id__>1234</__id__>
|
65
|
+
</oembed>
|
66
|
+
XML
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-oembed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 7
|
8
|
+
- 0
|
9
|
+
version: 0.7.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Magnus Holm
|
13
|
+
- Alex Kessinger
|
14
|
+
- Aris Bartee
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-08-19 00:00:00 -05:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: json
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: xml-simple
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
type: :development
|
57
|
+
version_requirements: *id003
|
58
|
+
description: A fork of a fork. @github[voidfiles,judofyr]. judufyr created the project and voidfiles added support for Embedly. This is just the gem
|
59
|
+
email: arisbartee@gmail.com
|
60
|
+
executables: []
|
61
|
+
|
62
|
+
extensions: []
|
63
|
+
|
64
|
+
extra_rdoc_files:
|
65
|
+
- README.md
|
66
|
+
files:
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- VERSION
|
70
|
+
- idea.rb
|
71
|
+
- integration_test/test.rb
|
72
|
+
- integration_test/test_urls.csv
|
73
|
+
- lib/oembed.rb
|
74
|
+
- lib/oembed/embedly_urls.json
|
75
|
+
- lib/oembed/errors.rb
|
76
|
+
- lib/oembed/formatters.rb
|
77
|
+
- lib/oembed/provider.rb
|
78
|
+
- lib/oembed/provider_discovery.rb
|
79
|
+
- lib/oembed/providers.rb
|
80
|
+
- lib/oembed/response.rb
|
81
|
+
- lib/oembed/response/link.rb
|
82
|
+
- lib/oembed/response/photo.rb
|
83
|
+
- lib/oembed/response/rich.rb
|
84
|
+
- lib/oembed/response/video.rb
|
85
|
+
- rails/init.rb
|
86
|
+
- ruby-oembed.gemspec
|
87
|
+
- spec/provider_spec.rb
|
88
|
+
- spec/providers_spec.rb
|
89
|
+
- spec/response_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
has_rdoc: true
|
92
|
+
homepage: http://github.com/arisbartee/ruby-oembed
|
93
|
+
licenses: []
|
94
|
+
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options:
|
97
|
+
- --charset=UTF-8
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
version: "0"
|
114
|
+
requirements: []
|
115
|
+
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 1.3.6
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: oEmbed for Ruby
|
121
|
+
test_files:
|
122
|
+
- spec/provider_spec.rb
|
123
|
+
- spec/providers_spec.rb
|
124
|
+
- spec/response_spec.rb
|
125
|
+
- spec/spec_helper.rb
|