Class: RawgApi::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rawg_api/configuration.rb

Constant Summary collapse

DEFAULT_API_ENDPOINT =
'https://api.rawg.io/api'
DEFAULT_APP_NAME =
'Rawg.io Ruby Client (rawg_api)'
DEFAULT_PAGE_SIZE =
50

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



19
20
21
22
23
24
25
26
# File 'lib/rawg_api/configuration.rb', line 19

def initialize
  @endpoint ||= DEFAULT_API_ENDPOINT
  @app_name ||= DEFAULT_APP_NAME
  @page_size ||= DEFAULT_PAGE_SIZE
  ::ApiStruct::Settings.configure do |config|
    config.endpoints = build_config[:endpoints]
  end
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



17
18
19
# File 'lib/rawg_api/configuration.rb', line 17

def app_name
  @app_name
end

#endpointObject

Returns the value of attribute endpoint.



17
18
19
# File 'lib/rawg_api/configuration.rb', line 17

def endpoint
  @endpoint
end

#headersObject

Returns the value of attribute headers.



17
18
19
# File 'lib/rawg_api/configuration.rb', line 17

def headers
  @headers
end

#page_sizeObject

Returns the value of attribute page_size.



17
18
19
# File 'lib/rawg_api/configuration.rb', line 17

def page_size
  @page_size
end

Instance Method Details

#api_headersObject



39
40
41
# File 'lib/rawg_api/configuration.rb', line 39

def api_headers
  (headers || {}).merge({'User-Agent': @app_name})
end

#build_configObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/rawg_api/configuration.rb', line 28

def build_config
  {
      endpoints: {
          rawg_api: {
              root: @endpoint,
              headers: api_headers
          }
      }
  }
end