Class: Extractula::OEmbed::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/extractula/oembed.rb

Constant Summary collapse

FIELDS =
%w{ type version title author_name author_url
provider_name provider_url cache_age thumbnail_url
thumbnail_width thumbnail_height }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/extractula/oembed.rb', line 122

def initialize response
  @doc    = ::JSON.parse(response)
  FIELDS.each { |field| instance_variable_set "@#{field}", @doc[field] }
  unless @type == 'link'
    @width  = @doc['width']
    @height = @doc['height']
    if @type == 'photo'
      @url = @doc['url']
    else
      @html = @doc['html']
    end
  end
  
  def [](field)
    @doc[field]
  end
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



120
121
122
# File 'lib/extractula/oembed.rb', line 120

def height
  @height
end

#htmlObject (readonly)

Returns the value of attribute html.



120
121
122
# File 'lib/extractula/oembed.rb', line 120

def html
  @html
end

#urlObject (readonly)

Returns the value of attribute url.



120
121
122
# File 'lib/extractula/oembed.rb', line 120

def url
  @url
end

#widthObject (readonly)

Returns the value of attribute width.



120
121
122
# File 'lib/extractula/oembed.rb', line 120

def width
  @width
end

Instance Method Details

#[](field) ⇒ Object



135
136
137
# File 'lib/extractula/oembed.rb', line 135

def [](field)
  @doc[field]
end