Class: Tinyembedly::Oembed

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/tinyembedly/oembed.rb

Constant Summary collapse

@@api_key =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Oembed

Returns a new instance of Oembed.



18
19
20
21
# File 'lib/tinyembedly/oembed.rb', line 18

def initialize(options = {})
  @api_key = options[:api_key] || @@api_key
  @url = options[:url]
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



6
7
8
# File 'lib/tinyembedly/oembed.rb', line 6

def api_key
  @api_key
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/tinyembedly/oembed.rb', line 6

def response
  @response
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/tinyembedly/oembed.rb', line 6

def url
  @url
end

Class Method Details

.api_key=(value) ⇒ Object



9
10
11
# File 'lib/tinyembedly/oembed.rb', line 9

def self.api_key=(value)
  @@api_key = value
end

.to_hash(url) ⇒ Object



13
14
15
16
# File 'lib/tinyembedly/oembed.rb', line 13

def self.to_hash(url)
  oembed = Oembed.new(:url => url)
  oembed.to_hash
end

Instance Method Details

#get_oembedObject



33
34
35
# File 'lib/tinyembedly/oembed.rb', line 33

def get_oembed
  self.class.get(endpoint, :query => params)
end

#paramsObject



37
38
39
# File 'lib/tinyembedly/oembed.rb', line 37

def params
  { :url => @url, :key => @api_key }
end

#to_hashObject



23
24
25
26
27
28
29
30
31
# File 'lib/tinyembedly/oembed.rb', line 23

def to_hash
  response = get_oembed
  case response.code
  when 200
    response.parsed_response
  else
    raise ResponseError.new(response)
  end
end