Class: EveApi::Crest

Inherits:
Object
  • Object
show all
Defined in:
lib/eve_api/crest.rb

Constant Summary collapse

BASE_URI =
"https://public-crest.eveonline.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, cache_only = false) ⇒ Crest

Returns a new instance of Crest.



7
8
9
10
# File 'lib/eve_api/crest.rb', line 7

def initialize(path, cache_only = false)
  self.path = path
  self.cache_only = cache_only
end

Instance Attribute Details

#cache_onlyObject

Returns the value of attribute cache_only.



5
6
7
# File 'lib/eve_api/crest.rb', line 5

def cache_only
  @cache_only
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/eve_api/crest.rb', line 5

def path
  @path
end

Instance Method Details

#call(opt = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/eve_api/crest.rb', line 12

def call(opt = {})
  splat = render(opt)

  conn = Faraday.new(:url => BASE_URI) do |faraday|
    faraday.request :url_encoded
    faraday.adapter Faraday.default_adapter
  end

  response = conn.get("/#{splat.join('/')}/")

  case response.status
    when 200
      return JSON.parse(response.body)
    when 404
      raise EAAL::Exception::APINotFoundError.new("The requested API (#{splat}) could not be found.")
    else
      raise EAAL::Exception::HTTPError.new("An HTTP Error occured, body: " + response.body)
  end
end