oembedr 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format nested
3
+
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create 1.9.3@oembedr_gem
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 1.0.0 (2012-01-17)
2
+
3
+ * Hello world: initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in oembedr.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,12 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ # Uncomment next line if Gemfile contain `gemspec' command
4
+ # watch(/^.+\.gemspec/)
5
+ end
6
+
7
+
8
+ guard 'rspec', version: 2, cli: '--color --format nested', all_on_start: true, all_after_pass: true do
9
+ watch('spec/spec_helper.rb') { "spec" }
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Matthew Wilson
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,56 @@
1
+ ## OEmbedr
2
+
3
+ Lightweight, Flexible OEmbed Consumer Library.
4
+
5
+ ### Installation
6
+
7
+ `gem install oembedr`
8
+
9
+ or in your `Gemfile`
10
+
11
+ ```ruby
12
+ gem 'oembedr'
13
+ ```
14
+
15
+ ### Goals
16
+
17
+ Make consuming oembed from **any source** simple and easy. Uses fast http and fast json parsing by default thanks to Faraday and MultiJSON.
18
+
19
+ ### Usage
20
+
21
+ `Oembedr` just returns the raw Faraday response object on success. On failure, it raises an appropriate error, e.g. `Faraday::Error::ResourceNotFound` for 404s. It parses the JSON for you.
22
+
23
+ *N.B.* XML is not supported yet. I've no idea why you might **need** it, but it's on the todo list :).
24
+
25
+ ```ruby
26
+ response = OEmbedr.fetch("http://www.youtube.com/watch?v=BxhqVrbixZc")
27
+ response.body # => { "type" => "video", ... }
28
+ # Now you can do whatever you want!
29
+ ```
30
+
31
+ #### Configuration
32
+
33
+ ```ruby
34
+ Oembedr.configure do |configuration|
35
+ configuration.user_agent = "MyCoolApp Oembed Client v2.51"
36
+ configuration.adapter = :excon # default :typhoeus
37
+ end
38
+ ```
39
+
40
+ ### Recommendations
41
+
42
+ Use a fast http library, like excon or typhoeus. Use yajl-ruby.
43
+
44
+ ## Contributing to oembedr
45
+
46
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
47
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
48
+ * Fork the project
49
+ * Start a feature/bugfix branch
50
+ * Commit and push until you are happy with your contribution
51
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
52
+ * 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.
53
+
54
+ ## Copyright
55
+
56
+ Copyright (c) 2012 Matthew Wilson. MIT-license: see LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ # If you want to make this the default task
7
+ task :default => :spec
data/lib/oembedr.rb ADDED
@@ -0,0 +1,27 @@
1
+ require "oembedr/version"
2
+ require "oembedr/configuration"
3
+ require "oembedr/client"
4
+ require "oembedr/providers"
5
+ require "typhoeus"
6
+
7
+ module Oembedr
8
+ extend Configuration
9
+ extend Providers
10
+
11
+ # Convience method: fetch me an oembed!
12
+ #
13
+ # Example:
14
+ # Oembedr.fetch("http://www.youtube.com/watch?v=b9XsTtFu64Y")
15
+ # Oembedr.fetch("http://www.youtube.com/watch?v=b9XsTtFu64Y",
16
+ # :params => { :maxwidth => "150", :maxheight => "100" })
17
+ #
18
+ # @return Faraday::Response or raises error
19
+ def self.fetch url, options = {}
20
+ client = Oembedr::Client.new(url)
21
+ if client.ready?
22
+ client.get(options)
23
+ else
24
+ false
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,58 @@
1
+ require "oembedr/parsed_url"
2
+ require "faraday_middleware"
3
+
4
+ module Oembedr
5
+ class Client
6
+ attr_accessor :resource_url, :parsed_url
7
+
8
+ def initialize url
9
+ self.resource_url = url
10
+ self.parsed_url = ParsedUrl.new(url)
11
+
12
+ end
13
+
14
+ # Sets up a Faraday::Connection object
15
+ #
16
+ # @param options [optional]
17
+ #
18
+ # @return Faraday::Connection
19
+ def connection options = {}
20
+ the_options = {
21
+ :headers => {
22
+ "Accept" => "application/json",
23
+ "User-Agent" => Oembedr.user_agent
24
+ },
25
+ :url => parsed_url.host
26
+ }.merge(options)
27
+
28
+ Faraday.new(the_options) do |builder|
29
+ builder.use Faraday::Request::UrlEncoded
30
+ builder.use Faraday::Response::ParseJson
31
+ builder.use Faraday::Response::RaiseError
32
+ builder.adapter Oembedr.adapter
33
+ end
34
+ end
35
+
36
+ # Requests the oembeddable resource
37
+ #
38
+ # @return Faraday::Response
39
+ def get options = {}
40
+ additional_params = options.delete(:params) || {}
41
+ connection(options).get do |req|
42
+ req.url parsed_url.path
43
+ req.params = additional_params.merge({
44
+ :url => resource_url,
45
+ :format => "json"
46
+ })
47
+ end
48
+ end
49
+
50
+ # Returns a boolean true/false if we can process this request
51
+ #
52
+ # @return Boolean
53
+ def ready?
54
+ !!parsed_url.host
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,30 @@
1
+ module Oembedr
2
+ module Configuration
3
+ # Set a custom User-Agent string (default: Oembedr [Rubygem] #{version})
4
+ attr_accessor :user_agent
5
+
6
+ # Select a different http library for Faraday to use (default: Typhoeus)
7
+ attr_accessor :adapter
8
+
9
+ # Yield self to be able to configure Oembedr
10
+ #
11
+ # Example:
12
+ #
13
+ # Oembedr.configure do |configuration|
14
+ # configuration.user_agent = "MyCoolApp Oembed Client v2.51"
15
+ # configuration.adapter = :excon
16
+ # end
17
+ def configure
18
+ yield self
19
+ end
20
+
21
+ def user_agent
22
+ @user_agent || "Oembedr Gem #{Oembedr::VERSION}"
23
+ end
24
+
25
+ def adapter
26
+ @adapter || :typhoeus
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ require "oembedr/providers"
2
+ require "uri"
3
+
4
+ module Oembedr
5
+ class ParsedUrl
6
+ attr_accessor :raw_url, :url
7
+
8
+ include Oembedr::Providers
9
+
10
+ # TODO: support xml at some point :)
11
+ def initialize the_url
12
+ self.raw_url = the_url
13
+ endpoint = service_endpoint(raw_url)
14
+ if endpoint
15
+ self.url = URI.parse(endpoint.gsub(/\{format\}/, "json"))
16
+ else
17
+ self.url = false
18
+ end
19
+ end
20
+
21
+ # Returns the scheme and host portion of the uri, intelligently concatenated
22
+ #
23
+ # Examples
24
+ #
25
+ # self.new("https://twitter.com/#!/hypomodern").host # => "https://twitter.com"
26
+ # self.new("http://youtu.be/v/234543").host # => "http://youtube.com"
27
+ #
28
+ # @return url [String]
29
+ def host
30
+ return false unless url
31
+ url.scheme + "://" + url.host
32
+ end
33
+
34
+ # Returns the path portion of the uri
35
+ #
36
+ # @return path [String]
37
+ def path
38
+ return false unless url
39
+ url.path
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,47 @@
1
+ module Oembedr
2
+ module Providers
3
+
4
+ # from ruby-oembed with a couple more I know of from user feedback :).
5
+ LIST = {
6
+ /(yotu\.be|youtube)/ => "http://www.youtube.com/oembed",
7
+ /(flic\.kr|flickr)/ => "http://www.flickr.com/services/oembed/",
8
+ /viddler/ => "http://lab.viddler.com/services/oembed/",
9
+ /qik/ => "http://qik.com/api/oembed.{format}",
10
+ /revision3/ => "http://revision3.com/api/oembed/",
11
+ /hulu/ => "http://www.hulu.com/api/oembed.{format}",
12
+ /vimeo/ => "http://www.vimeo.com/api/oembed.{format}",
13
+ /instagr.am/ => "http://api.instagram.com/oembed",
14
+ /slideshare/ => "http://www.slideshare.net/api/oembed/2",
15
+ /(mlg\.tv|tv\.majorleaguegaming)/ => "http://tv.majorleaguegaming.com/oembed",
16
+ /yfrog/ => "http://www.yfrog.com/api/oembed",
17
+ /blip\.tv/ => "http://blip.tv/oembed/",
18
+ /opera\.com/ => 'http://my.opera.com/service/oembed',
19
+ /skitch\.com/ => 'http://skitch.com/oembed',
20
+ /twitch\.tv/ => false, # OMG! Support OEmbed!
21
+ /twitter\.com/ => 'https://api.twitter.com/1/statuses/oembed.{format}',
22
+ # ...
23
+ }
24
+
25
+ # Locate the correct service endpoint for the given resource URL.
26
+ #
27
+ # @param url [String] a fully-qualified URL to an oembeddable resource
28
+ #
29
+ # @return the url, or false if no known endpoint.
30
+ def service_endpoint url
31
+ endpoint = LIST.find do |(pattern, endpoint)|
32
+ pattern.match(url)
33
+ end
34
+ endpoint ? endpoint.last : false
35
+ end
36
+
37
+ # Return a boolean true or false if we can handle the given domain
38
+ #
39
+ # @param url [String] a fully-qualified URL to an oembeddable resource
40
+ #
41
+ # @return Boolean
42
+ def known_service? url
43
+ !!service_endpoint(url)
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Oembedr
2
+ VERSION = "0.0.2"
3
+ end
data/oembedr.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "oembedr/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "oembedr"
7
+ s.version = Oembedr::VERSION
8
+ s.authors = ["Matt Wilson"]
9
+ s.email = ["mhw@hypomodern.com"]
10
+ s.homepage = "https://github.com/agoragames/oembedr"
11
+ s.summary = %q{Lightweight, Flexible OEmbed Consumer Library}
12
+ s.description = %q{oembedr aims to make consuming oembed resources easy}
13
+
14
+ # s.rubyforge_project = "oembedr"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ s.add_development_dependency "yajl-ruby"
24
+ s.add_development_dependency "typhoeus"
25
+ s.add_development_dependency "vcr", "~> 2.0.0.rc1"
26
+ s.add_development_dependency "fakeweb"
27
+ s.add_development_dependency "guard"
28
+ s.add_development_dependency "guard-rspec"
29
+ s.add_development_dependency "guard-bundler"
30
+
31
+ s.add_dependency "multi_json"
32
+ s.add_dependency "faraday"
33
+ s.add_dependency "faraday_middleware"
34
+ end
@@ -0,0 +1,109 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://www.youtube.com/oembed?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Db9XsTtFu64Y&format=json
6
+ body: ''
7
+ headers:
8
+ Accept:
9
+ - application/json
10
+ User-Agent:
11
+ - Oembedr Gem 0.0.1
12
+ response:
13
+ status:
14
+ code: 200
15
+ message:
16
+ headers:
17
+ Date:
18
+ - Tue, 17 Jan 2012 21:08:22 GMT
19
+ Server:
20
+ - Apache
21
+ X-Content-Type-Options:
22
+ - nosniff
23
+ Expires:
24
+ - Tue, 27 Apr 1971 19:44:06 EST
25
+ Cache-Control:
26
+ - no-cache
27
+ Content-Type:
28
+ - application/json
29
+ Transfer-Encoding:
30
+ - chunked
31
+ body: ! '{"provider_url": "http:\/\/www.youtube.com\/", "title": "Dead Prez -
32
+ Turn Off The Radio @ Dave Chappelle''s Block Party", "html": "\u003ciframe width=\"480\"
33
+ height=\"270\" src=\"http:\/\/www.youtube.com\/embed\/b9XsTtFu64Y?fs=1\u0026feature=oembed\"
34
+ frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e", "author_name":
35
+ "InfamousBIG", "height": 270, "thumbnail_width": 480, "width": 480, "version":
36
+ "1.0", "author_url": "http:\/\/www.youtube.com\/user\/InfamousBIG", "provider_name":
37
+ "YouTube", "thumbnail_url": "http:\/\/i3.ytimg.com\/vi\/b9XsTtFu64Y\/hqdefault.jpg",
38
+ "type": "video", "thumbnail_height": 360}'
39
+ http_version:
40
+ recorded_at: Tue, 17 Jan 2012 21:08:21 GMT
41
+ - request:
42
+ method: get
43
+ uri: http://www.youtube.com/oembed?url=http%3A%2F%2Fwww.youtube.com%2Ffoobar%3Fqq%3D12314332&format=json
44
+ body: ''
45
+ headers:
46
+ Accept:
47
+ - application/json
48
+ User-Agent:
49
+ - Oembedr Gem 0.0.1
50
+ response:
51
+ status:
52
+ code: 404
53
+ message:
54
+ headers:
55
+ Date:
56
+ - Tue, 17 Jan 2012 21:08:22 GMT
57
+ Server:
58
+ - Apache
59
+ X-Content-Type-Options:
60
+ - nosniff
61
+ Expires:
62
+ - Tue, 27 Apr 1971 19:44:06 EST
63
+ Cache-Control:
64
+ - no-cache
65
+ Content-Type:
66
+ - text/html; charset=utf-8
67
+ Transfer-Encoding:
68
+ - chunked
69
+ body: 404 Not Found
70
+ http_version:
71
+ recorded_at: Tue, 17 Jan 2012 21:08:21 GMT
72
+ - request:
73
+ method: get
74
+ uri: http://www.youtube.com/oembed?maxwidth=150&maxheight=100&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQi_AAqi0RZM&format=json
75
+ body: ''
76
+ headers:
77
+ Accept:
78
+ - application/json
79
+ User-Agent:
80
+ - Oembedr Gem 0.0.1
81
+ response:
82
+ status:
83
+ code: 200
84
+ message:
85
+ headers:
86
+ Date:
87
+ - Tue, 17 Jan 2012 21:08:22 GMT
88
+ Server:
89
+ - Apache
90
+ X-Content-Type-Options:
91
+ - nosniff
92
+ Expires:
93
+ - Tue, 27 Apr 1971 19:44:06 EST
94
+ Cache-Control:
95
+ - no-cache
96
+ Content-Type:
97
+ - application/json
98
+ Transfer-Encoding:
99
+ - chunked
100
+ body: ! '{"provider_url": "http:\/\/www.youtube.com\/", "title": "Twilio''s definitive
101
+ brogramming primer", "html": "\u003ciframe width=\"133\" height=\"100\" src=\"http:\/\/www.youtube.com\/embed\/Qi_AAqi0RZM?fs=1\u0026feature=oembed\"
102
+ frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e", "author_name":
103
+ "TeamTwilio", "height": 100, "thumbnail_width": 480, "width": 133, "version":
104
+ "1.0", "author_url": "http:\/\/www.youtube.com\/user\/TeamTwilio", "provider_name":
105
+ "YouTube", "thumbnail_url": "http:\/\/i2.ytimg.com\/vi\/Qi_AAqi0RZM\/hqdefault.jpg",
106
+ "type": "video", "thumbnail_height": 360}'
107
+ http_version:
108
+ recorded_at: Tue, 17 Jan 2012 21:08:21 GMT
109
+ recorded_with: VCR 2.0.0.rc1
@@ -0,0 +1,52 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module Oembedr
4
+ describe Client do
5
+ let(:valid_resource_url) { "http://www.youtube.com/watch?v=b9XsTtFu64Y" }
6
+ let(:client) { Client.new(valid_resource_url) }
7
+
8
+ describe "initialization" do
9
+ it "requires a resource url as a parameter" do
10
+ lambda { Client.new }.should raise_error(ArgumentError)
11
+ end
12
+ it "cracks the url into a ParsedUrl object" do
13
+ client.parsed_url.should be_a_kind_of(ParsedUrl)
14
+ end
15
+ end
16
+
17
+ describe "#connection" do
18
+ it "returns a Faraday::Connection object" do
19
+ client.connection.should be_a_kind_of(Faraday::Connection)
20
+ end
21
+ it "sets some basic attributes on the connection" do
22
+ conn = client.connection
23
+ conn.headers.should == {
24
+ "Accept" => "application/json",
25
+ "User-Agent" => "Oembedr Gem #{Oembedr::VERSION}"
26
+ }
27
+ conn.host.should == "www.youtube.com"
28
+ end
29
+ end
30
+
31
+ use_vcr_cassette "client", :record => :new_episodes
32
+
33
+ describe "#get" do
34
+ it "requests data and parses that JSON" do
35
+ response = client.get
36
+ response.body["type"].should == "video"
37
+ response.body["html"].should_not be_empty
38
+ end
39
+ it "raises an appropriate error if there is a problem" do
40
+ client = Client.new("http://www.youtube.com/foobar?qq=12314332")
41
+ lambda { client.get }.should raise_error(Faraday::Error::ResourceNotFound)
42
+ end
43
+ it "passes through any additional parameters (e.g. size constraints)" do
44
+ client = Client.new("http://www.youtube.com/watch?v=Qi_AAqi0RZM")
45
+ response = client.get({:params => { :maxwidth => "150", :maxheight => "100" }})
46
+ response.body["width"].should <= 150
47
+ response.body["height"].should <= 100
48
+ end
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module Oembedr
4
+ describe ParsedUrl do
5
+ let(:valid_resource_url) { "http://www.youtube.com/watch?v=b9XsTtFu64Y" }
6
+ let(:parser) { ParsedUrl.new(valid_resource_url) }
7
+ let(:trololo_parser) { ParsedUrl.new("http://trolololo.com") }
8
+ let(:complex_url_parser) {
9
+ ParsedUrl.new("https://twitter.com/hypomodern/status/158203918323695616")
10
+ }
11
+
12
+ it "includes the Providers module" do
13
+ parser.class.included_modules.should include(Oembedr::Providers)
14
+ end
15
+
16
+ describe "#url" do
17
+ it "is set to the results of URI.parse on the appropriate service endpoint" do
18
+ parser.url.should be_a_kind_of(URI::HTTP)
19
+ parser.url.host.should == "www.youtube.com"
20
+ parser.url.path.should == "/oembed"
21
+ end
22
+ it "is set to false if there is no known endpoint" do
23
+ trololo_parser.url.should be_false
24
+ end
25
+ end
26
+
27
+ describe "#host" do
28
+ it "returns an intelligent hostname (including the scheme) instead of just the domain" do
29
+ parser.host.should == "http://www.youtube.com"
30
+ complex_url_parser.host.should == "https://api.twitter.com"
31
+ end
32
+ it "returns false if there wasn't a valid URL" do
33
+ trololo_parser.host.should be_false
34
+ end
35
+ end
36
+
37
+ describe "#path" do
38
+ it "returns the path portion of the url" do
39
+ parser.path.should == "/oembed"
40
+ end
41
+ it "returns false if there wasn't a valid URL" do
42
+ trololo_parser.path.should be_false
43
+ end
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module Oembedr
4
+ describe Providers do
5
+
6
+ describe "#service_endpoint" do
7
+ it "matches the given URL to a known endpoint" do
8
+ endpoint = Oembedr.service_endpoint("http://www.youtube.com/watch?v=b9XsTtFu64Y")
9
+ endpoint.should_not be_false
10
+ end
11
+ it "returns false if there is no known endpoint" do
12
+ Oembedr.service_endpoint("http://www.madeupdomainthatwedontsupportyet.com/foos/324").should be_false
13
+ end
14
+ end
15
+
16
+ describe "#known_service?" do
17
+ it "should return a boolean yes or no if we can handle the given url" do
18
+ Oembedr.known_service?("http://www.youtube.com/watch?v=b9XsTtFu64Y").should be_true
19
+ Oembedr.known_service?("http://www.noserviceherenosir.com/foos/324").should be_false
20
+ end
21
+ end
22
+
23
+ context "testing ALL THE THINGS" do
24
+ {
25
+ "http://www.youtube.com/watch?v=b9XsTtFu64Y" => "http://www.youtube.com/oembed",
26
+ "http://www.flickr.com/photos/puzzlemaster/6693154925/in/photostream" => "http://www.flickr.com/services/oembed/",
27
+ "http://www.viddler.com/v/a802f490" => "http://lab.viddler.com/services/oembed/",
28
+ "http://qik.com/video/15944" => "http://qik.com/api/oembed.{format}",
29
+ "http://revision3.com/tbhs/holidaycontroller" => "http://revision3.com/api/oembed/",
30
+ "http://www.hulu.com/watch/319756/the-daily-show-with-jon-stewart-mon-jan-16-2012" => "http://www.hulu.com/api/oembed.{format}",
31
+ "http://vimeo.com/35055590" => "http://www.vimeo.com/api/oembed.{format}",
32
+ "http://instagr.am/p/BUG/" => "http://api.instagram.com/oembed",
33
+ "http://www.slideshare.net/alwynlau/martin-luther-king-jr-quote-presentation" => "http://www.slideshare.net/api/oembed/2",
34
+ "http://tv.majorleaguegaming.com/videos/80344-the-year-in-starcraft-2" => "http://tv.majorleaguegaming.com/oembed",
35
+ "http://yfrog.com/hsyu9ymj" => "http://www.yfrog.com/api/oembed",
36
+ "http://blip.tv/cablekooks/fox-news-anchor-john-stossel-wants-people-to-stop-voting-5883656" => "http://blip.tv/oembed/",
37
+ "http://opera.com" => 'http://my.opera.com/service/oembed',
38
+ "http://skitch.com/hannaolsen/rq33h/vday" => 'http://skitch.com/oembed',
39
+ "http://www.twitch.tv/i_like_turtlez" => false, # OMG! Support OEmbed!
40
+ "https://twitter.com/hypomodern/status/158203918323695616" => 'https://api.twitter.com/1/statuses/oembed.{format}'
41
+ }.each do |(test_url, expected_value)|
42
+ it "should match #{test_url} to #{expected_value}" do
43
+ Oembedr.service_endpoint(test_url).should == expected_value
44
+ end
45
+
46
+ end
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Oembedr do
4
+ let(:test_url) { "http://www.youtube.com/watch?v=b9XsTtFu64Y" }
5
+ let(:mock_client) { mock(Oembedr::Client, :ready? => true) }
6
+
7
+ describe "#fetch" do
8
+ it "leverages the Client class to retrieve an oembeddable resource from the given url" do
9
+ Oembedr::Client.stub!(:new).and_return(mock_client)
10
+ mock_client.should_receive(:get).with({})
11
+ Oembedr.fetch test_url
12
+ end
13
+ it "passes any options through correctly" do
14
+ Oembedr::Client.stub!(:new).and_return(mock_client)
15
+ mock_client.should_receive(:get).with({ :maxwidth => 350 })
16
+ Oembedr.fetch test_url, { :maxwidth => 350 }
17
+ end
18
+ it "returns false if there is no known service for the given URI" do
19
+ Oembedr.fetch("http://jasdfasdfas.com").should be_false
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'oembedr' # and any other gems you need
5
+ require 'vcr'
6
+
7
+ RSpec.configure do |c|
8
+ c.extend VCR::RSpec::Macros
9
+ end
10
+
11
+ VCR.configure do |c|
12
+ c.cassette_library_dir = 'spec/fixtures'
13
+ c.hook_into :faraday
14
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oembedr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Wilson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &2164342700 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2164342700
25
+ - !ruby/object:Gem::Dependency
26
+ name: yajl-ruby
27
+ requirement: &2164339500 !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: *2164339500
36
+ - !ruby/object:Gem::Dependency
37
+ name: typhoeus
38
+ requirement: &2164338500 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2164338500
47
+ - !ruby/object:Gem::Dependency
48
+ name: vcr
49
+ requirement: &2164337200 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.0.rc1
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2164337200
58
+ - !ruby/object:Gem::Dependency
59
+ name: fakeweb
60
+ requirement: &2164336240 !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: *2164336240
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard
71
+ requirement: &2164334940 !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: *2164334940
80
+ - !ruby/object:Gem::Dependency
81
+ name: guard-rspec
82
+ requirement: &2164333700 !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: *2164333700
91
+ - !ruby/object:Gem::Dependency
92
+ name: guard-bundler
93
+ requirement: &2164331340 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *2164331340
102
+ - !ruby/object:Gem::Dependency
103
+ name: multi_json
104
+ requirement: &2164328280 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: *2164328280
113
+ - !ruby/object:Gem::Dependency
114
+ name: faraday
115
+ requirement: &2164327160 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :runtime
122
+ prerelease: false
123
+ version_requirements: *2164327160
124
+ - !ruby/object:Gem::Dependency
125
+ name: faraday_middleware
126
+ requirement: &2164326060 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: *2164326060
135
+ description: oembedr aims to make consuming oembed resources easy
136
+ email:
137
+ - mhw@hypomodern.com
138
+ executables: []
139
+ extensions: []
140
+ extra_rdoc_files: []
141
+ files:
142
+ - .gitignore
143
+ - .rspec
144
+ - .rvmrc
145
+ - CHANGELOG.md
146
+ - Gemfile
147
+ - Guardfile
148
+ - LICENSE.txt
149
+ - README.md
150
+ - Rakefile
151
+ - lib/oembedr.rb
152
+ - lib/oembedr/client.rb
153
+ - lib/oembedr/configuration.rb
154
+ - lib/oembedr/parsed_url.rb
155
+ - lib/oembedr/providers.rb
156
+ - lib/oembedr/version.rb
157
+ - oembedr.gemspec
158
+ - spec/fixtures/client.yml
159
+ - spec/oembedr/client_spec.rb
160
+ - spec/oembedr/parsed_url_spec.rb
161
+ - spec/oembedr/providers_spec.rb
162
+ - spec/oembedr_spec.rb
163
+ - spec/spec_helper.rb
164
+ homepage: https://github.com/agoragames/oembedr
165
+ licenses: []
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubyforge_project:
184
+ rubygems_version: 1.8.15
185
+ signing_key:
186
+ specification_version: 3
187
+ summary: Lightweight, Flexible OEmbed Consumer Library
188
+ test_files:
189
+ - spec/fixtures/client.yml
190
+ - spec/oembedr/client_spec.rb
191
+ - spec/oembedr/parsed_url_spec.rb
192
+ - spec/oembedr/providers_spec.rb
193
+ - spec/oembedr_spec.rb
194
+ - spec/spec_helper.rb