class OhMyEmbed::Response
Attributes
attributes[R]
provider[R]
Public Class Methods
new(provider, url, data = {})
click to toggle source
Initialize the OhMyEmbed::Response
@param [OhMyEmbed::Provider] provider @param [String] url @param [Hash] data
# File lib/oh_my_embed/response.rb, line 13 def initialize(provider, url, data = {}) @provider = provider @url = url @attributes = data end
Public Instance Methods
attribute(field_name)
click to toggle source
Get a single attribute from the raw response
@param [String|Symbol] field_name @return [mixed]
# File lib/oh_my_embed/response.rb, line 23 def attribute(field_name) @attributes.fetch(field_name.to_s, nil) end
embed()
click to toggle source
Get the embed informations
@return [Hash] :html, :width, :height
# File lib/oh_my_embed/response.rb, line 99 def embed html = attribute(mapping['embed.html']) { html: html, url: html ? nil : url, width: attribute(mapping['embed.width']), height: attribute(mapping['embed.height']), }.compact end
provider_name()
click to toggle source
Get the oembed provider name
@return [String]
# File lib/oh_my_embed/response.rb, line 37 def provider_name attribute(mapping['provider_name']) || @provider.provider_name end
provider_url()
click to toggle source
Get the provider url
@return [String]
# File lib/oh_my_embed/response.rb, line 44 def provider_url attribute(mapping['provider_url']) || @provider.endpoint end
thumbnail()
click to toggle source
Get the thumbnail informations
@return [Hash] :url, :width, :height
# File lib/oh_my_embed/response.rb, line 82 def thumbnail thumbnail_url = attribute(mapping['thumbnail.url']) if thumbnail_url { url: thumbnail_url, width: attribute(mapping['thumbnail.width']), height: attribute(mapping['thumbnail.height']), } else nil end end
title()
click to toggle source
Get the title
@return [String]
# File lib/oh_my_embed/response.rb, line 58 def title attribute(mapping['title']) end
to_h()
click to toggle source
Return the Hash representation of this response
@return [Hash] :type, :provider_name, :provider_url, :url, :author, :thumbnail, :embed
# File lib/oh_my_embed/response.rb, line 113 def to_h %i{ type provider_name provider_url url title author thumbnail embed }.map do |key| [key, self.send(key)] end.to_h end
type()
click to toggle source
Get the oembed type of the response
@return [String] one of :photo, :video, :rich, :link
# File lib/oh_my_embed/response.rb, line 30 def type attribute(mapping['type']).to_sym end
url()
click to toggle source
Get the content url
@return [String]
# File lib/oh_my_embed/response.rb, line 51 def url attribute(mapping['url']) || @url end