Class: Oembed::Media

Inherits:
Providers show all
Defined in:
lib/oembed/media.rb

Instance Attribute Summary collapse

Attributes inherited from Providers

#sites

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Media

Returns a new instance of Media.



7
8
9
10
11
12
# File 'lib/oembed/media.rb', line 7

def initialize(url)
  @format = 'json'
  @url = url
  @sites = Oembed::Providers.new.sites 
  get_info
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



5
6
7
# File 'lib/oembed/media.rb', line 5

def format
  @format
end

#htmlObject

Returns the value of attribute html.



5
6
7
# File 'lib/oembed/media.rb', line 5

def html
  @html
end

#media_urlObject

Returns the value of attribute media_url.



5
6
7
# File 'lib/oembed/media.rb', line 5

def media_url
  @media_url
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/oembed/media.rb', line 5

def title
  @title
end

Instance Method Details

#get_infoObject



14
15
16
17
18
19
# File 'lib/oembed/media.rb', line 14

def get_info
  find_provider
  url = URI.parse(@base_url + @url)
  http_get = Net::HTTP.get(url)
  set_attributes(http_get)
end

#set_attributes(att) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/oembed/media.rb', line 21

def set_attributes(att)
  parsed_data = JSON.parse(att)
  @title = parsed_data['title']
  @media_url = parsed_data['url']
  @format = parsed_data['type']
  @html = parsed_data['html'] if @format == 'video'
end