Class: Oembedder::Base
- Inherits:
-
Object
- Object
- Oembedder::Base
- Defined in:
- lib/oembedder/base.rb
Instance Attribute Summary collapse
-
#providers ⇒ Object
Returns the value of attribute providers.
Class Method Summary collapse
Instance Method Summary collapse
- #find_provider(target) ⇒ Object
- #get(url, params = {}) ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
37 38 39 |
# File 'lib/oembedder/base.rb', line 37 def initialize self.providers = [] end |
Instance Attribute Details
#providers ⇒ Object
Returns the value of attribute providers.
3 4 5 |
# File 'lib/oembedder/base.rb', line 3 def providers @providers end |
Class Method Details
.create_dailymotion ⇒ Object
23 24 25 26 27 28 |
# File 'lib/oembedder/base.rb', line 23 def self.create_dailymotion dm = Provider.new(format_type: 'querystring') dm.set_endpoint('http://www.dailymotion.com/services/oembed') dm.set_schemes(['http://www.dailymotion.com/video/*']) dm end |
.create_vimeo ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/oembedder/base.rb', line 13 def self.create_vimeo vimeo = Provider.new vimeo.set_endpoint('http://vimeo.com/api/oembed.json') vimeo.set_schemes( ['http://vimeo.com/*', 'http://vimeo.com/channels/*/*', 'http://vimeo.com/groups/*/videos/*']) vimeo end |
.create_youtube ⇒ Object
30 31 32 33 34 35 |
# File 'lib/oembedder/base.rb', line 30 def self.create_youtube youtube = Provider.new(format_type: 'querystring') youtube.set_endpoint('http://www.youtube.com/oembed') youtube.set_schemes(['http://www.youtube.com/watch?v=*']) youtube end |
.setup ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/oembedder/base.rb', line 5 def self.setup = Base.new .providers << create_vimeo .providers << create_dailymotion .providers << create_youtube end |
Instance Method Details
#find_provider(target) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/oembedder/base.rb', line 46 def find_provider(target) self.providers.each do |pv| return pv if pv.match_scheme? target end false end |
#get(url, params = {}) ⇒ Object
41 42 43 44 |
# File 'lib/oembedder/base.rb', line 41 def get(url, params = {}) provider = self.find_provider(url) provider.get(ConsumerRequest.new(url, params)) if provider end |