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
22
# File 'lib/tinyembedly/oembed.rb', line 18

def initialize(options = {})
  @api_key = options.delete(:api_key) || @@api_key
  @url = options.delete(:url)
  @other_params = options
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

#other_paramsObject (readonly)

Returns the value of attribute other_params.



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

def other_params
  @other_params
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



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

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

#paramsObject



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

def params
  { :url => @url, :key => @api_key }.merge(@other_params)
end

#to_hashObject



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

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