module BlacklightInternetArchive::Response

Public Class Methods

included(base) click to toggle source
# File lib/blacklight_internet_archive/response.rb, line 3
def self.included(base)
  unless base < Hash
    raise ArgumentError, "InternetArchive::Response expects to included only in (sub)classes of Hash; got included in '#{base}' instead."
  end
  base.send(:attr_reader, :request, :response)
end

Public Instance Methods

initialize_response(request, response, result) click to toggle source
# File lib/blacklight_internet_archive/response.rb, line 10
def initialize_response(request, response, result)
  @request = request
  @response = response
  merge!(result)
  if self['response'] && self['response']['docs'].is_a?(::Array)
    docs = PaginatedDocSet.new(self['response']['docs'])
    docs.per_page = request[:params]['rows']
    docs.page_start = request[:params]['start']
    docs.total = self['response']['numFound'].to_s.to_i
    self['response']['docs'] = docs
  end
end
with_indifferent_access() click to toggle source
# File lib/blacklight_internet_archive/response.rb, line 23
    def with_indifferent_access
      if defined?(::BlacklightInternetArchive::HashWithIndifferentAccessWithResponse)
        ::BlacklightInternetArchive::HashWithIndifferentAccessWithResponse.new(request, response, self)
      elsif defined?(ActiveSupport::HashWithIndifferentAccess)
        BlacklightInternetArchive.const_set('HashWithIndifferentAccessWithResponse', Class.new(ActiveSupport::HashWithIndifferentAccess))
        BlacklightInternetArchive::HashWithIndifferentAccessWithResponse.class_eval <<-eos
        include BlacklightInternetArchive::Response

        def initialize(request, response, result)
          super()
          initialize_response(request, response, result)
        end
        eos
        ::BlacklightInternetArchive::HashWithIndifferentAccessWithResponse.new(request, response, self)
      end
    end