class Esi::Calls::Base

Base parent class used for all API calls. Provides basic functionality and state for caching and request initialization

Constants

CACHE_NAMESPACE

Attributes

params[W]
path[RW]

Public Instance Methods

cache_key() click to toggle source

Returns an unique key based on the endpoint and params which is used for caching @return [String] cache key

# File lib/esi/calls/base.rb, line 20
def cache_key
  @cache_key ||= begin
    checksum = Digest::MD5.hexdigest("#{path.gsub(%r{^\/}, '')}:#{sorted_params}")
    "#{CACHE_NAMESPACE}:#{checksum}"
  end
end
method() click to toggle source

Returns the request HTTP method to use @return [Symbol] request method

# File lib/esi/calls/base.rb, line 29
def method
  @method ||= :get
end
page() click to toggle source

@return [Integer] page number

# File lib/esi/calls/base.rb, line 45
def page
  params[:page] || 1
end
page=(page) click to toggle source

@param page [Integer] page number

# File lib/esi/calls/base.rb, line 40
def page=(page)
  params[:page] = page
end
paginated?() click to toggle source

Returns whether the endpoint supports pagination @return [Boolean]

# File lib/esi/calls/base.rb, line 51
def paginated?
  @paginated
end
params() click to toggle source

@return [Hash] request params

# File lib/esi/calls/base.rb, line 56
def params
  @params || {}
end
url() click to toggle source

Returns the generated endpoint URL including any parameters @return [String] request URI

# File lib/esi/calls/base.rb, line 35
def url
  Esi.generate_url(path, params)
end

Private Instance Methods

sorted_params() click to toggle source

Transforms the params hash into a sorted array @return [Array] sorted array of params

# File lib/esi/calls/base.rb, line 64
def sorted_params
  sorted = {}
  params.each do |k, v|
    sorted[k] = v.respond_to?(:sort) ? v.sort : v
  end
  sorted.sort
end