Class: Oembedder::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/oembedder/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



37
38
39
# File 'lib/oembedder/base.rb', line 37

def initialize
  self.providers = []
end

Instance Attribute Details

#providersObject

Returns the value of attribute providers.



3
4
5
# File 'lib/oembedder/base.rb', line 3

def providers
  @providers
end

Class Method Details

.create_dailymotionObject



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_vimeoObject



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_youtubeObject



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

.setupObject



5
6
7
8
9
10
11
# File 'lib/oembedder/base.rb', line 5

def self.setup
  oembed = Base.new
  oembed.providers << create_vimeo
  oembed.providers << create_dailymotion
  oembed.providers << create_youtube
  oembed
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