Class: Esi::Calls::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/esi/calls/base.rb

Overview

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

Constant Summary collapse

CACHE_NAMESPACE =
'esi'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#paramsHash

Returns request params.

Returns:

  • (Hash)

    request params



56
57
58
# File 'lib/esi/calls/base.rb', line 56

def params
  @params || {}
end

#pathObject

Returns the value of attribute path.



15
16
17
# File 'lib/esi/calls/base.rb', line 15

def path
  @path
end

Instance Method Details

#cache_keyString

Returns an unique key based on the endpoint and params which is used for caching

Returns:

  • (String)

    cache key



20
21
22
23
24
25
# 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

#methodSymbol

Returns the request HTTP method to use

Returns:

  • (Symbol)

    request method



29
30
31
# File 'lib/esi/calls/base.rb', line 29

def method
  @method ||= :get
end

#pageInteger

Returns page number.

Returns:

  • (Integer)

    page number



45
46
47
# File 'lib/esi/calls/base.rb', line 45

def page
  params[:page] || 1
end

#page=(page) ⇒ Object

Parameters:

  • page (Integer)

    page number



40
41
42
# File 'lib/esi/calls/base.rb', line 40

def page=(page)
  params[:page] = page
end

#paginated?Boolean

Returns whether the endpoint supports pagination

Returns:

  • (Boolean)


51
52
53
# File 'lib/esi/calls/base.rb', line 51

def paginated?
  @paginated
end

#urlString

Returns the generated endpoint URL including any parameters

Returns:

  • (String)

    request URI



35
36
37
# File 'lib/esi/calls/base.rb', line 35

def url
  Esi.generate_url(path, params)
end