Class: EOAT::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/eoat/request.rb

Overview

Request class. Returns an instance of the class-result from the cache or performs http request.

Examples:

EOAT::Request.new(
    'https://api.eveonline.com',
    '/eve/CharacterInfo.xml.aspx?characterID=208974814',
    EOAT::Result::EveType::Result
).get

Returns:

  • The instance of the class specified in the attributes.

Raises:

  • [EOAT::Exception::HTTP404Error] the request path not found

  • [EOAT::Exception::HTTPError] response status code is not 200, 404. Contain status code and response headers

  • [EOAT::Exception::EveApiError] if response status code is 0. Contain a parsed error page message and error code

Author:

Instance Method Summary collapse

Constructor Details

#initialize(host, uri, result_class) ⇒ Request

Returns a new instance of Request.

Parameters:

  • host (String)

    the request host string

  • uri (String)

    the request query string

  • result_class (Class)

    the class to contain result of request



25
26
27
28
29
# File 'lib/eoat/request.rb', line 25

def initialize(host, uri, result_class)
  @host = host
  @uri = uri
  @result = result_class
end

Instance Method Details

#getObject

Method-collector of private methods. Performs basic algorithm of output.



32
33
34
35
36
37
38
39
40
41
# File 'lib/eoat/request.rb', line 32

def get
  cache = cache_get
  if cache
    cache
  else
    result = @result.new(http_request)
    cache_save(result)
    result
  end
end