Class: Esirb::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/esirb/client.rb

Constant Summary collapse

BASE_URL =
"https://esi.evetech.net"
DEFAULT_HEADERS =
{
  "Accept" => "application/json",
  "Accept-Language" => "en",
  "If-Modified-Since" => "",
  "If-None-Match" => "",
  "X-Tenant" => "tranquility",
  "X-Compatibility-Date" => "2026-06-09"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token: nil, tenant: "tranquility", language: "en", cache: true, cache_store: nil, raise_errors: true) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
25
26
27
# File 'lib/esirb/client.rb', line 20

def initialize(token: nil, tenant: "tranquility", language: "en", cache: true, cache_store: nil, raise_errors: true)
  @token = token
  @tenant = tenant
  @language = language
  @cache = cache
  @cache_store = cache_store
  @raise_errors = raise_errors
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



47
48
49
# File 'lib/esirb/client.rb', line 47

def method_missing(m, *args, &block)
  @path = Path.new(client: self).send(m.to_sym, *args)
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



18
19
20
# File 'lib/esirb/client.rb', line 18

def cache
  @cache
end

#cache_storeObject (readonly)

Returns the value of attribute cache_store.



18
19
20
# File 'lib/esirb/client.rb', line 18

def cache_store
  @cache_store
end

#languageObject (readonly)

Returns the value of attribute language.



18
19
20
# File 'lib/esirb/client.rb', line 18

def language
  @language
end

#pathObject (readonly)

Returns the value of attribute path.



18
19
20
# File 'lib/esirb/client.rb', line 18

def path
  @path
end

#raise_errorsObject (readonly)

Returns the value of attribute raise_errors.



18
19
20
# File 'lib/esirb/client.rb', line 18

def raise_errors
  @raise_errors
end

#tenantObject (readonly)

Returns the value of attribute tenant.



18
19
20
# File 'lib/esirb/client.rb', line 18

def tenant
  @tenant
end

#tokenObject (readonly)

Returns the value of attribute token.



18
19
20
# File 'lib/esirb/client.rb', line 18

def token
  @token
end

Instance Method Details

#connectionObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/esirb/client.rb', line 29

def connection
  @connection ||= Faraday.new(BASE_URL) do |c|
    c.request :authorization, "Bearer", token if token

    if cache
      c.use :http_cache,
        store: cache_store,
        strategy: Faraday::HttpCache::Strategies::ByUrl,
        serializer: Marshal
    end

    c.request :json
    c.headers = DEFAULT_HEADERS
    c.response :raise_error if raise_errors
    c.response :json, content_type: "application/json"
  end
end