Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial Import.

  • Loading branch information...
commit 5b4c6ef00b9fa7fba0cd660b6f06c9ceeb1b25d4 0 parents
@hypomodern hypomodern authored
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
3  .rspec
@@ -0,0 +1,3 @@
+--color
+--format nested
+
1  .rvmrc
@@ -0,0 +1 @@
+rvm use --create 1.9.3@oembedr_gem
3  CHANGELOG.md
@@ -0,0 +1,3 @@
+# 1.0.0 (2012-01-17)
+
+* Hello world: initial release
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in oembedr.gemspec
+gemspec
12 Guardfile
@@ -0,0 +1,12 @@
+guard 'bundler' do
+ watch('Gemfile')
+ # Uncomment next line if Gemfile contain `gemspec' command
+ # watch(/^.+\.gemspec/)
+end
+
+
+guard 'rspec', version: 2, cli: '--color --format nested', all_on_start: true, all_after_pass: true do
+ watch('spec/spec_helper.rb') { "spec" }
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+end
20 LICENSE.txt
@@ -0,0 +1,20 @@
+Copyright (c) 2012 Matthew Wilson
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56 README.md
@@ -0,0 +1,56 @@
+## OEmbedr
+
+Lightweight, Flexible OEmbed Consumer Library.
+
+### Installation
+
+`gem install oembedr`
+
+or in your `Gemfile`
+
+```ruby
+gem 'oembedr'
+```
+
+### Goals
+
+Make consuming oembed from **any source** simple and easy. Uses fast http and fast json parsing by default thanks to Faraday and MultiJSON.
+
+### Usage
+
+`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.
+
+*N.B.* XML is not supported yet. I've no idea why you might **need** it, but it's on the todo list :).
+
+```ruby
+response = OEmbedr.fetch("http://www.youtube.com/watch?v=BxhqVrbixZc")
+response.body # => { "type" => "video", ... }
+# Now you can do whatever you want!
+```
+
+#### Configuration
+
+```ruby
+Oembedr.configure do |configuration|
+ configuration.user_agent = "MyCoolApp Oembed Client v2.51"
+ configuration.adapter = :excon # default :typhoeus
+end
+```
+
+### Recommendations
+
+Use a fast http library, like excon or typhoeus. Use yajl-ruby.
+
+## Contributing to oembedr
+
+* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
+* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
+* Fork the project
+* Start a feature/bugfix branch
+* Commit and push until you are happy with your contribution
+* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
+* 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.
+
+## Copyright
+
+Copyright (c) 2012 Matthew Wilson. MIT-license: see LICENSE.txt for further details.
7 Rakefile
@@ -0,0 +1,7 @@
+require "bundler/gem_tasks"
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new('spec')
+
+# If you want to make this the default task
+task :default => :spec
27 lib/oembedr.rb
@@ -0,0 +1,27 @@
+require "oembedr/version"
+require "oembedr/configuration"
+require "oembedr/client"
+require "oembedr/providers"
+require "typhoeus"
+
+module Oembedr
+ extend Configuration
+ extend Providers
+
+ # Convience method: fetch me an oembed!
+ #
+ # Example:
+ # Oembedr.fetch("http://www.youtube.com/watch?v=b9XsTtFu64Y")
+ # Oembedr.fetch("http://www.youtube.com/watch?v=b9XsTtFu64Y",
+ # :params => { :maxwidth => "150", :maxheight => "100" })
+ #
+ # @return Faraday::Response or raises error
+ def self.fetch url, options = {}
+ client = Oembedr::Client.new(url)
+ if client.ready?
+ client.get(options)
+ else
+ false
+ end
+ end
+end
58 lib/oembedr/client.rb
@@ -0,0 +1,58 @@
+require "oembedr/parsed_url"
+require "faraday_middleware"
+
+module Oembedr
+ class Client
+ attr_accessor :resource_url, :parsed_url
+
+ def initialize url
+ self.resource_url = url
+ self.parsed_url = ParsedUrl.new(url)
+
+ end
+
+ # Sets up a Faraday::Connection object
+ #
+ # @param options [optional]
+ #
+ # @return Faraday::Connection
+ def connection options = {}
+ the_options = {
+ :headers => {
+ "Accept" => "application/json",
+ "User-Agent" => Oembedr.user_agent
+ },
+ :url => parsed_url.host
+ }.merge(options)
+
+ Faraday.new(the_options) do |builder|
+ builder.use Faraday::Request::UrlEncoded
+ builder.use Faraday::Response::ParseJson
+ builder.use Faraday::Response::RaiseError
+ builder.adapter Oembedr.adapter
+ end
+ end
+
+ # Requests the oembeddable resource
+ #
+ # @return Faraday::Response
+ def get options = {}
+ additional_params = options.delete(:params) || {}
+ connection(options).get do |req|
+ req.url parsed_url.path
+ req.params = additional_params.merge({
+ :url => resource_url,
+ :format => "json"
+ })
+ end
+ end
+
+ # Returns a boolean true/false if we can process this request
+ #
+ # @return Boolean
+ def ready?
+ !!parsed_url.host
+ end
+
+ end
+end
30 lib/oembedr/configuration.rb
@@ -0,0 +1,30 @@
+module Oembedr
+ module Configuration
+ # Set a custom User-Agent string (default: Oembedr [Rubygem] #{version})
+ attr_accessor :user_agent
+
+ # Select a different http library for Faraday to use (default: Typhoeus)
+ attr_accessor :adapter
+
+ # Yield self to be able to configure Oembedr
+ #
+ # Example:
+ #
+ # Oembedr.configure do |configuration|
+ # configuration.user_agent = "MyCoolApp Oembed Client v2.51"
+ # configuration.adapter = :excon
+ # end
+ def configure
+ yield self
+ end
+
+ def user_agent
+ @user_agent || "Oembedr Gem #{Oembedr::VERSION}"
+ end
+
+ def adapter
+ @adapter || :typhoeus
+ end
+
+ end
+end
42 lib/oembedr/parsed_url.rb
@@ -0,0 +1,42 @@
+require "oembedr/providers"
+require "uri"
+
+module Oembedr
+ class ParsedUrl
+ attr_accessor :raw_url, :url
+
+ include Oembedr::Providers
+
+ # TODO: support xml at some point :)
+ def initialize the_url
+ self.raw_url = the_url
+ endpoint = service_endpoint(raw_url)
+ if endpoint
+ self.url = URI.parse(endpoint.gsub(/\{format\}/, "json"))
+ else
+ self.url = false
+ end
+ end
+
+ # Returns the scheme and host portion of the uri, intelligently concatenated
+ #
+ # Examples
+ #
+ # self.new("https://twitter.com/#!/hypomodern").host # => "https://twitter.com"
+ # self.new("http://youtu.be/v/234543").host # => "http://youtube.com"
+ #
+ # @return url [String]
+ def host
+ return false unless url
+ url.scheme + "://" + url.host
+ end
+
+ # Returns the path portion of the uri
+ #
+ # @return path [String]
+ def path
+ return false unless url
+ url.path
+ end
+ end
+end
47 lib/oembedr/providers.rb
@@ -0,0 +1,47 @@
+module Oembedr
+ module Providers
+
+ # from ruby-oembed with a couple more I know of from user feedback :).
+ LIST = {
+ /(yotu\.be|youtube)/ => "http://www.youtube.com/oembed",
+ /(flic\.kr|flickr)/ => "http://www.flickr.com/services/oembed/",
+ /viddler/ => "http://lab.viddler.com/services/oembed/",
+ /qik/ => "http://qik.com/api/oembed.{format}",
+ /revision3/ => "http://revision3.com/api/oembed/",
+ /hulu/ => "http://www.hulu.com/api/oembed.{format}",
+ /vimeo/ => "http://www.vimeo.com/api/oembed.{format}",
+ /instagr.am/ => "http://api.instagram.com/oembed",
+ /slideshare/ => "http://www.slideshare.net/api/oembed/2",
+ /(mlg\.tv|tv\.majorleaguegaming)/ => "http://tv.majorleaguegaming.com/oembed",
+ /yfrog/ => "http://www.yfrog.com/api/oembed",
+ /blip\.tv/ => "http://blip.tv/oembed/",
+ /opera\.com/ => 'http://my.opera.com/service/oembed',
+ /skitch\.com/ => 'http://skitch.com/oembed',
+ /twitch\.tv/ => false, # OMG! Support OEmbed!
+ /twitter\.com/ => 'https://api.twitter.com/1/statuses/oembed.{format}',
+ # ...
+ }
+
+ # Locate the correct service endpoint for the given resource URL.
+ #
+ # @param url [String] a fully-qualified URL to an oembeddable resource
+ #
+ # @return the url, or false if no known endpoint.
+ def service_endpoint url
+ endpoint = LIST.find do |(pattern, endpoint)|
+ pattern.match(url)
+ end
+ endpoint ? endpoint.last : false
+ end
+
+ # Return a boolean true or false if we can handle the given domain
+ #
+ # @param url [String] a fully-qualified URL to an oembeddable resource
+ #
+ # @return Boolean
+ def known_service? url
+ !!service_endpoint(url)
+ end
+
+ end
+end
3  lib/oembedr/version.rb
@@ -0,0 +1,3 @@
+module Oembedr
+ VERSION = "0.0.1"
+end
34 oembedr.gemspec
@@ -0,0 +1,34 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "oembedr/version"
+
+Gem::Specification.new do |s|
+ s.name = "oembedr"
+ s.version = Oembedr::VERSION
+ s.authors = ["Matt Wilson"]
+ s.email = ["mhw@hypomodern.com"]
+ s.homepage = ""
+ s.summary = %q{Lightweight, Flexible OEmbed Consumer Library}
+ s.description = %q{oembedr aims to make consuming oembed resources easy}
+
+ # s.rubyforge_project = "oembedr"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ s.add_development_dependency "rspec"
+ s.add_development_dependency "yajl-ruby"
+ s.add_development_dependency "typhoeus"
+ s.add_development_dependency "vcr", "~> 2.0.0.rc1"
+ s.add_development_dependency "fakeweb"
+ s.add_development_dependency "guard"
+ s.add_development_dependency "guard-rspec"
+ s.add_development_dependency "guard-bundler"
+
+ s.add_dependency "multi_json"
+ s.add_dependency "faraday"
+ s.add_dependency "faraday_middleware"
+end
109 spec/fixtures/client.yml
@@ -0,0 +1,109 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: http://www.youtube.com/oembed?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Db9XsTtFu64Y&format=json
+ body: ''
+ headers:
+ Accept:
+ - application/json
+ User-Agent:
+ - Oembedr Gem 0.0.1
+ response:
+ status:
+ code: 200
+ message:
+ headers:
+ Date:
+ - Tue, 17 Jan 2012 21:08:22 GMT
+ Server:
+ - Apache
+ X-Content-Type-Options:
+ - nosniff
+ Expires:
+ - Tue, 27 Apr 1971 19:44:06 EST
+ Cache-Control:
+ - no-cache
+ Content-Type:
+ - application/json
+ Transfer-Encoding:
+ - chunked
+ body: ! '{"provider_url": "http:\/\/www.youtube.com\/", "title": "Dead Prez -
+ Turn Off The Radio @ Dave Chappelle''s Block Party", "html": "\u003ciframe width=\"480\"
+ height=\"270\" src=\"http:\/\/www.youtube.com\/embed\/b9XsTtFu64Y?fs=1\u0026feature=oembed\"
+ frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e", "author_name":
+ "InfamousBIG", "height": 270, "thumbnail_width": 480, "width": 480, "version":
+ "1.0", "author_url": "http:\/\/www.youtube.com\/user\/InfamousBIG", "provider_name":
+ "YouTube", "thumbnail_url": "http:\/\/i3.ytimg.com\/vi\/b9XsTtFu64Y\/hqdefault.jpg",
+ "type": "video", "thumbnail_height": 360}'
+ http_version:
+ recorded_at: Tue, 17 Jan 2012 21:08:21 GMT
+- request:
+ method: get
+ uri: http://www.youtube.com/oembed?url=http%3A%2F%2Fwww.youtube.com%2Ffoobar%3Fqq%3D12314332&format=json
+ body: ''
+ headers:
+ Accept:
+ - application/json
+ User-Agent:
+ - Oembedr Gem 0.0.1
+ response:
+ status:
+ code: 404
+ message:
+ headers:
+ Date:
+ - Tue, 17 Jan 2012 21:08:22 GMT
+ Server:
+ - Apache
+ X-Content-Type-Options:
+ - nosniff
+ Expires:
+ - Tue, 27 Apr 1971 19:44:06 EST
+ Cache-Control:
+ - no-cache
+ Content-Type:
+ - text/html; charset=utf-8
+ Transfer-Encoding:
+ - chunked
+ body: 404 Not Found
+ http_version:
+ recorded_at: Tue, 17 Jan 2012 21:08:21 GMT
+- request:
+ method: get
+ uri: http://www.youtube.com/oembed?maxwidth=150&maxheight=100&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQi_AAqi0RZM&format=json
+ body: ''
+ headers:
+ Accept:
+ - application/json
+ User-Agent:
+ - Oembedr Gem 0.0.1
+ response:
+ status:
+ code: 200
+ message:
+ headers:
+ Date:
+ - Tue, 17 Jan 2012 21:08:22 GMT
+ Server:
+ - Apache
+ X-Content-Type-Options:
+ - nosniff
+ Expires:
+ - Tue, 27 Apr 1971 19:44:06 EST
+ Cache-Control:
+ - no-cache
+ Content-Type:
+ - application/json
+ Transfer-Encoding:
+ - chunked
+ body: ! '{"provider_url": "http:\/\/www.youtube.com\/", "title": "Twilio''s definitive
+ brogramming primer", "html": "\u003ciframe width=\"133\" height=\"100\" src=\"http:\/\/www.youtube.com\/embed\/Qi_AAqi0RZM?fs=1\u0026feature=oembed\"
+ frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e", "author_name":
+ "TeamTwilio", "height": 100, "thumbnail_width": 480, "width": 133, "version":
+ "1.0", "author_url": "http:\/\/www.youtube.com\/user\/TeamTwilio", "provider_name":
+ "YouTube", "thumbnail_url": "http:\/\/i2.ytimg.com\/vi\/Qi_AAqi0RZM\/hqdefault.jpg",
+ "type": "video", "thumbnail_height": 360}'
+ http_version:
+ recorded_at: Tue, 17 Jan 2012 21:08:21 GMT
+recorded_with: VCR 2.0.0.rc1
52 spec/oembedr/client_spec.rb
@@ -0,0 +1,52 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+module Oembedr
+ describe Client do
+ let(:valid_resource_url) { "http://www.youtube.com/watch?v=b9XsTtFu64Y" }
+ let(:client) { Client.new(valid_resource_url) }
+
+ describe "initialization" do
+ it "requires a resource url as a parameter" do
+ lambda { Client.new }.should raise_error(ArgumentError)
+ end
+ it "cracks the url into a ParsedUrl object" do
+ client.parsed_url.should be_a_kind_of(ParsedUrl)
+ end
+ end
+
+ describe "#connection" do
+ it "returns a Faraday::Connection object" do
+ client.connection.should be_a_kind_of(Faraday::Connection)
+ end
+ it "sets some basic attributes on the connection" do
+ conn = client.connection
+ conn.headers.should == {
+ "Accept" => "application/json",
+ "User-Agent" => "Oembedr Gem #{Oembedr::VERSION}"
+ }
+ conn.host.should == "www.youtube.com"
+ end
+ end
+
+ use_vcr_cassette "client", :record => :new_episodes
+
+ describe "#get" do
+ it "requests data and parses that JSON" do
+ response = client.get
+ response.body["type"].should == "video"
+ response.body["html"].should_not be_empty
+ end
+ it "raises an appropriate error if there is a problem" do
+ client = Client.new("http://www.youtube.com/foobar?qq=12314332")
+ lambda { client.get }.should raise_error(Faraday::Error::ResourceNotFound)
+ end
+ it "passes through any additional parameters (e.g. size constraints)" do
+ client = Client.new("http://www.youtube.com/watch?v=Qi_AAqi0RZM")
+ response = client.get({:params => { :maxwidth => "150", :maxheight => "100" }})
+ response.body["width"].should <= 150
+ response.body["height"].should <= 100
+ end
+ end
+
+ end
+end
47 spec/oembedr/parsed_url_spec.rb
@@ -0,0 +1,47 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+module Oembedr
+ describe ParsedUrl do
+ let(:valid_resource_url) { "http://www.youtube.com/watch?v=b9XsTtFu64Y" }
+ let(:parser) { ParsedUrl.new(valid_resource_url) }
+ let(:trololo_parser) { ParsedUrl.new("http://trolololo.com") }
+ let(:complex_url_parser) {
+ ParsedUrl.new("https://twitter.com/hypomodern/status/158203918323695616")
+ }
+
+ it "includes the Providers module" do
+ parser.class.included_modules.should include(Oembedr::Providers)
+ end
+
+ describe "#url" do
+ it "is set to the results of URI.parse on the appropriate service endpoint" do
+ parser.url.should be_a_kind_of(URI::HTTP)
+ parser.url.host.should == "www.youtube.com"
+ parser.url.path.should == "/oembed"
+ end
+ it "is set to false if there is no known endpoint" do
+ trololo_parser.url.should be_false
+ end
+ end
+
+ describe "#host" do
+ it "returns an intelligent hostname (including the scheme) instead of just the domain" do
+ parser.host.should == "http://www.youtube.com"
+ complex_url_parser.host.should == "https://api.twitter.com"
+ end
+ it "returns false if there wasn't a valid URL" do
+ trololo_parser.host.should be_false
+ end
+ end
+
+ describe "#path" do
+ it "returns the path portion of the url" do
+ parser.path.should == "/oembed"
+ end
+ it "returns false if there wasn't a valid URL" do
+ trololo_parser.path.should be_false
+ end
+ end
+
+ end
+end
50 spec/oembedr/providers_spec.rb
@@ -0,0 +1,50 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+module Oembedr
+ describe Providers do
+
+ describe "#service_endpoint" do
+ it "matches the given URL to a known endpoint" do
+ endpoint = Oembedr.service_endpoint("http://www.youtube.com/watch?v=b9XsTtFu64Y")
+ endpoint.should_not be_false
+ end
+ it "returns false if there is no known endpoint" do
+ Oembedr.service_endpoint("http://www.madeupdomainthatwedontsupportyet.com/foos/324").should be_false
+ end
+ end
+
+ describe "#known_service?" do
+ it "should return a boolean yes or no if we can handle the given url" do
+ Oembedr.known_service?("http://www.youtube.com/watch?v=b9XsTtFu64Y").should be_true
+ Oembedr.known_service?("http://www.noserviceherenosir.com/foos/324").should be_false
+ end
+ end
+
+ context "testing ALL THE THINGS" do
+ {
+ "http://www.youtube.com/watch?v=b9XsTtFu64Y" => "http://www.youtube.com/oembed",
+ "http://www.flickr.com/photos/puzzlemaster/6693154925/in/photostream" => "http://www.flickr.com/services/oembed/",
+ "http://www.viddler.com/v/a802f490" => "http://lab.viddler.com/services/oembed/",
+ "http://qik.com/video/15944" => "http://qik.com/api/oembed.{format}",
+ "http://revision3.com/tbhs/holidaycontroller" => "http://revision3.com/api/oembed/",
+ "http://www.hulu.com/watch/319756/the-daily-show-with-jon-stewart-mon-jan-16-2012" => "http://www.hulu.com/api/oembed.{format}",
+ "http://vimeo.com/35055590" => "http://www.vimeo.com/api/oembed.{format}",
+ "http://instagr.am/p/BUG/" => "http://api.instagram.com/oembed",
+ "http://www.slideshare.net/alwynlau/martin-luther-king-jr-quote-presentation" => "http://www.slideshare.net/api/oembed/2",
+ "http://tv.majorleaguegaming.com/videos/80344-the-year-in-starcraft-2" => "http://tv.majorleaguegaming.com/oembed",
+ "http://yfrog.com/hsyu9ymj" => "http://www.yfrog.com/api/oembed",
+ "http://blip.tv/cablekooks/fox-news-anchor-john-stossel-wants-people-to-stop-voting-5883656" => "http://blip.tv/oembed/",
+ "http://opera.com" => 'http://my.opera.com/service/oembed',
+ "http://skitch.com/hannaolsen/rq33h/vday" => 'http://skitch.com/oembed',
+ "http://www.twitch.tv/i_like_turtlez" => false, # OMG! Support OEmbed!
+ "https://twitter.com/hypomodern/status/158203918323695616" => 'https://api.twitter.com/1/statuses/oembed.{format}'
+ }.each do |(test_url, expected_value)|
+ it "should match #{test_url} to #{expected_value}" do
+ Oembedr.service_endpoint(test_url).should == expected_value
+ end
+
+ end
+ end
+
+ end
+end
23 spec/oembedr_spec.rb
@@ -0,0 +1,23 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+describe Oembedr do
+ let(:test_url) { "http://www.youtube.com/watch?v=b9XsTtFu64Y" }
+ let(:mock_client) { mock(Oembedr::Client, :ready? => true) }
+
+ describe "#fetch" do
+ it "leverages the Client class to retrieve an oembeddable resource from the given url" do
+ Oembedr::Client.stub!(:new).and_return(mock_client)
+ mock_client.should_receive(:get).with({})
+ Oembedr.fetch test_url
+ end
+ it "passes any options through correctly" do
+ Oembedr::Client.stub!(:new).and_return(mock_client)
+ mock_client.should_receive(:get).with({ :maxwidth => 350 })
+ Oembedr.fetch test_url, { :maxwidth => 350 }
+ end
+ it "returns false if there is no known service for the given URI" do
+ Oembedr.fetch("http://jasdfasdfas.com").should be_false
+ end
+ end
+
+end
14 spec/spec_helper.rb
@@ -0,0 +1,14 @@
+require 'rubygems'
+require 'bundler/setup'
+
+require 'oembedr' # and any other gems you need
+require 'vcr'
+
+RSpec.configure do |c|
+ c.extend VCR::RSpec::Macros
+end
+
+VCR.configure do |c|
+ c.cassette_library_dir = 'spec/fixtures'
+ c.hook_into :faraday
+end
Please sign in to comment.
Something went wrong with that request. Please try again.