pummel 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,125 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe OEmbed::Providers 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}")
9
+
10
+ @flickr << "http://*.flickr.com/*"
11
+ @qik << "http://qik.com/video/*"
12
+ @qik << "http://qik.com/*"
13
+ end
14
+
15
+ it "should register providers" do
16
+ OEmbed::Providers.register(@flickr, @qik)
17
+ urls = OEmbed::Providers.urls.dup
18
+
19
+ @flickr.urls.each do |regexp|
20
+ urls.delete(regexp).should == @flickr
21
+ end
22
+
23
+ @qik.urls.each do |regexp|
24
+ urls.delete(regexp).should == @qik
25
+ end
26
+
27
+ urls.length.should == 0
28
+ end
29
+
30
+ it "should find by URLs" do
31
+ OEmbed::Providers.find(example_url(:flickr)).should == @flickr
32
+ OEmbed::Providers.find(example_url(:qik)).should == @qik
33
+ end
34
+
35
+ it "should unregister providers" do
36
+ OEmbed::Providers.unregister(@flickr)
37
+ urls = OEmbed::Providers.urls.dup
38
+
39
+ @qik.urls.each do |regexp|
40
+ urls.delete(regexp).should == @qik
41
+ end
42
+
43
+ urls.length.should == 0
44
+ end
45
+
46
+ it "should use the OEmbed::ProviderDiscovery fallback provider correctly" do
47
+ url = example_url(:vimeo)
48
+
49
+ # None of the registered providers should match
50
+ all_example_urls.each do |url|
51
+ provider = OEmbed::Providers.find(url)
52
+ provider.should_not_receive(:raw)
53
+ provider.should_not_receive(:get)
54
+ end
55
+
56
+ # Register the fallback
57
+ OEmbed::Providers.register_fallback(OEmbed::ProviderDiscovery)
58
+
59
+ provider = OEmbed::ProviderDiscovery
60
+ provider.should_receive(:raw).
61
+ with(url, {}).
62
+ and_return(valid_response(:raw))
63
+ provider.should_receive(:get).
64
+ with(url, {}).
65
+ and_return(valid_response(:object))
66
+ #asdf
67
+
68
+
69
+ end
70
+
71
+ it "should bridge #get and #raw to the right provider" do
72
+ OEmbed::Providers.register_all
73
+ all_example_urls.each do |url|
74
+ provider = OEmbed::Providers.find(url)
75
+ provider.should_receive(:raw).
76
+ with(url, {})
77
+ provider.should_receive(:get).
78
+ with(url, {})
79
+ OEmbed::Providers.raw(url)
80
+ OEmbed::Providers.get(url)
81
+ end
82
+ end
83
+
84
+ it "should raise an error if no embeddable content is found" do
85
+ ["http://fake.com/", example_url(:google_video)].each do |url|
86
+ proc { OEmbed::Providers.get(url) }.should raise_error(OEmbed::NotFound)
87
+ proc { OEmbed::Providers.raw(url) }.should raise_error(OEmbed::NotFound)
88
+ end
89
+ end
90
+
91
+ it "should register fallback providers" do
92
+ OEmbed::Providers.register_fallback(OEmbed::Providers::Hulu)
93
+ OEmbed::Providers.register_fallback(OEmbed::Providers::OohEmbed)
94
+
95
+ OEmbed::Providers.fallback.should == [OEmbed::ProviderDiscovery, OEmbed::Providers::Hulu, OEmbed::Providers::OohEmbed]
96
+ end
97
+
98
+ it "should fallback to the appropriate provider when URL isn't found" do
99
+ url = example_url(:google_video)
100
+
101
+ provider = OEmbed::Providers.fallback.last
102
+ provider.should_receive(:raw).
103
+ with(url, {}).
104
+ and_return(valid_response(:raw))
105
+ provider.should_receive(:get).
106
+ with(url, {}).
107
+ and_return(valid_response(:object))
108
+
109
+ OEmbed::Providers.fallback.each do |p|
110
+ next if p == provider
111
+ p.should_receive(:raw).and_raise(OEmbed::NotFound)
112
+ p.should_receive(:get).and_raise(OEmbed::NotFound)
113
+ end
114
+
115
+ OEmbed::Providers.raw(url)
116
+ OEmbed::Providers.get(url)
117
+ end
118
+
119
+ it "should still raise an error if no embeddable content is found" do
120
+ ["http://fake.com/"].each do |url|
121
+ proc { OEmbed::Providers.get(url) }.should raise_error(OEmbed::NotFound)
122
+ proc { OEmbed::Providers.raw(url) }.should raise_error(OEmbed::NotFound)
123
+ end
124
+ end
125
+ end
@@ -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
@@ -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,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pummel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Colin Shea
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-16 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sinatra
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: riot
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: yard
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: Given an RSS feed, make a tumblr-like site out of it. Uses Sinatra & Rack, inspired by Dumble.
46
+ email: colin@evaryont.me
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.md
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - VERSION
61
+ - config.ru
62
+ - public/body.png
63
+ - public/favicon.ico
64
+ - public/style.css
65
+ - pummel.gemspec
66
+ - pummel.rb
67
+ - templates/index.erb
68
+ - vendor/ruby-oembed/idea.rb
69
+ - vendor/ruby-oembed/lib/oembed.rb
70
+ - vendor/ruby-oembed/lib/oembed/errors.rb
71
+ - vendor/ruby-oembed/lib/oembed/formatters.rb
72
+ - vendor/ruby-oembed/lib/oembed/provider.rb
73
+ - vendor/ruby-oembed/lib/oembed/provider_discovery.rb
74
+ - vendor/ruby-oembed/lib/oembed/providers.rb
75
+ - vendor/ruby-oembed/lib/oembed/response.rb
76
+ - vendor/ruby-oembed/lib/oembed/response/link.rb
77
+ - vendor/ruby-oembed/lib/oembed/response/photo.rb
78
+ - vendor/ruby-oembed/lib/oembed/response/rich.rb
79
+ - vendor/ruby-oembed/lib/oembed/response/video.rb
80
+ - vendor/ruby-oembed/spec/provider_spec.rb
81
+ - vendor/ruby-oembed/spec/providers_spec.rb
82
+ - vendor/ruby-oembed/spec/response_spec.rb
83
+ - vendor/ruby-oembed/spec/spec_helper.rb
84
+ has_rdoc: true
85
+ homepage: http://github.com/evaryont/pummel
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options:
90
+ - --charset=UTF-8
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ version:
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ version:
105
+ requirements: []
106
+
107
+ rubyforge_project:
108
+ rubygems_version: 1.3.5
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Auto-tumble your RSS feed!
112
+ test_files: []
113
+