Method: NexusMods#initialize

Defined in:
lib/nexus_mods.rb

#initialize(api_key: nil, game_domain_name: 'skyrimspecialedition', mod_id: 1, file_id: 1, api_cache_expiry: {}, api_cache_file: "#{Dir.tmpdir}/nexus_mods_api_cache.json", logger: Logger.new($stdout), log_level: :info) ⇒ NexusMods

Constructor

Parameters
  • api_key (String or nil): The API key to be used, or nil for another authentication [default: nil]

  • game_domain_name (String): Game domain name to query by default [default: ‘skyrimspecialedition’]

  • mod_id (Integer): Mod to query by default [default: 1]

  • file_id (Integer): File to query by default [default: 1]

  • api_cache_expiry (Hash<Symbol,Integer>): Expiry times in seconds, per expiry key. Possible keys are:

    • games: Expiry associated to queries on games [default: 1 day]

    • mod: Expiry associated to queries on mod [default: 1 day]

    • mod_files: Expiry associated to queries on mod files [default: 1 day]

  • api_cache_file (String): File used to store the NexusMods API cache, or nil for no cache [default: “#Dir.tmpdir/nexus_mods_api_cache.json”]

  • logger (Logger): The logger to be used for log messages [default: Logger.new(STDOUT)]

  • log_level (Symbol): The logger level to be set [default: :info]



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/nexus_mods.rb', line 50

def initialize(
  api_key: nil,
  game_domain_name: 'skyrimspecialedition',
  mod_id: 1,
  file_id: 1,
  api_cache_expiry: {},
  api_cache_file: "#{Dir.tmpdir}/nexus_mods_api_cache.json",
  logger: Logger.new($stdout),
  log_level: :info
)
  @game_domain_name = game_domain_name
  @mod_id = mod_id
  @file_id = file_id
  @logger = logger
  @logger.level = log_level
  @premium = false
  @api_client = ApiClient.new(
    api_key:,
    api_cache_expiry:,
    api_cache_file:,
    logger:
  )

  # Check that the key is correct and know if the user is premium
  begin
    @premium = @api_client.api('users/validate')['is_premium?']
  rescue LimitsExceededError
    raise
  rescue ApiError
    raise InvalidApiKeyError, 'Invalid API key'
  end
end