class Theguardian::Api::Item

Public Class Methods

new(*params) click to toggle source
Calls superclass method
# File lib/theguardian/api/item.rb, line 4
def initialize(*params)
        content = params.first["content"] ? params.first.merge(params.first["content"]["fields"] ) : params.first
        item_params = params.first["fields"] || content

        super(item_params, params.last)
end
process(params) click to toggle source
# File lib/theguardian/api/item.rb, line 11
def self.process(params)
        connection = Theguardian::Connection.new(resource: params.delete(:id))
        self.new(connection.get(self.process_params(params)), recurse_over_arrays: true)
end
process_params(params) click to toggle source
# File lib/theguardian/api/item.rb, line 20
def self.process_params(params)
        # The item id
        theguardian_api_params = { id: params[:id] }

        # The show fields
        theguardian_api_params.merge!({ "show-fields" => params[:fields] || "all" }) 

        theguardian_api_params.reject{ |_, value| value.nil? }
end

Public Instance Methods

fetch() click to toggle source
# File lib/theguardian/api/item.rb, line 16
def fetch
        self.class.process({ id: URI(self.apiUrl).path })
end