Class: XIVAPI::Client

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/xivapi.rb

Overview

Client for making requests to XIVAPI

Constant Summary

Constants included from Request

Request::ALL_CHARACTER_DATA, Request::LODESTONE_LIMIT

Constants included from HTTP

HTTP::API_BASE, HTTP::STAGING_API_BASE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Request

#character, #character_search, #character_verified?, #content, #free_company, #free_company_search, #linkshell, #linkshell_search, #lore, #patch_list, #pvp_team, #pvp_team_search, #search, #servers

Methods included from HTTP

#request

Constructor Details

#initialize(api_key: nil, language: :en, staging: false) ⇒ Client

Initializes a new client for querying XIVAPI

Parameters:

  • api_key (String)

    API key provided by XIVAPI

  • language (String)

    Requested response langauge

  • staging (true, false)

    Whether or not to query the staging API instead of production



34
35
36
37
38
39
# File 'lib/xivapi.rb', line 34

def initialize(api_key: nil, language: :en, staging: false)
  @api_key = api_key

  self.language = language
  self.staging = staging
end

Instance Attribute Details

#api_keyString

Returns The API key

Returns:

  • (String)

    The API key



25
26
27
# File 'lib/xivapi.rb', line 25

def api_key
  @api_key
end

#stagingtrue, false

Returns Whether or not to query the staging API instead of production

Returns:

  • (true, false)

    Whether or not to query the staging API instead of production



28
29
30
# File 'lib/xivapi.rb', line 28

def staging
  @staging
end

Instance Method Details

#default_paramsHash

Returns The default parameters for the client

Returns:

  • (Hash)

    The default parameters for the client



55
56
57
# File 'lib/xivapi.rb', line 55

def default_params
  { private_key: @api_key, language: @language }
end

#languageString

Returns The language

Returns:

  • (String)

    The language



42
43
44
# File 'lib/xivapi.rb', line 42

def language
  @language
end

#language=(language) ⇒ Object

Returns The language

Parameters:

  • language (String, Symbol)

    The language to set for the client

Returns:

  • The language

Raises:

  • (ArgumentError)


48
49
50
51
52
# File 'lib/xivapi.rb', line 48

def language=(language)
  lang = language.to_s.downcase
  raise ArgumentError, 'Unsupported language' unless LANGUAGE_OPTIONS.include?(lang)
  @language = lang
end