class Oembedder::ProviderResponse

Attributes

format[R]

attr_reader :type, :version, :title, :author_name, :author_url, :provider_name, :provider_url, :cache_age, :thumbnail_url, :thumbnail_width, :thumbnail_height, :url, :html, :width, :height

has_error[R]

attr_reader :type, :version, :title, :author_name, :author_url, :provider_name, :provider_url, :cache_age, :thumbnail_url, :thumbnail_width, :thumbnail_height, :url, :html, :width, :height

raw_data[R]

attr_reader :type, :version, :title, :author_name, :author_url, :provider_name, :provider_url, :cache_age, :thumbnail_url, :thumbnail_width, :thumbnail_height, :url, :html, :width, :height

status[R]

attr_reader :type, :version, :title, :author_name, :author_url, :provider_name, :provider_url, :cache_age, :thumbnail_url, :thumbnail_width, :thumbnail_height, :url, :html, :width, :height

Public Class Methods

create(format, faraday_response) click to toggle source
# File lib/oembedder/provider_response.rb, line 6
def self.create(format, faraday_response)
  pr = ProviderResponse.new(format: format)
  pr.handle_status faraday_response
  pr.parse faraday_response.body
  pr
end
new(params = {}) click to toggle source
# File lib/oembedder/provider_response.rb, line 13
def initialize(params = {})
  @has_error = false
  @format = params[:format]
end

Public Instance Methods

handle_status(faraday_response) click to toggle source
# File lib/oembedder/provider_response.rb, line 18
def handle_status(faraday_response)
  @status = faraday_response.status
  @has_error = true unless faraday_response.status == 200
end
method_missing(name) click to toggle source
Calls superclass method
# File lib/oembedder/provider_response.rb, line 27
def method_missing(name)
  if data = find_data(name)
    data
  else
    super
  end
end
parse(response) click to toggle source
# File lib/oembedder/provider_response.rb, line 23
def parse(response)
  @raw_data = response
end

Private Instance Methods

find_data(name) click to toggle source
# File lib/oembedder/provider_response.rb, line 36
def find_data(name)
  case self.format
  when :json
    @raw_data[name.to_s] if @raw_data.has_key?(name.to_s)
  when :xml
    @raw_data['oembed'][name.to_s] if @raw_data['oembed'].has_key?(name.to_s)
  else
    false
  end
end