Class: FactorioMods::Api::WebAuthentication

Inherits:
Object
  • Object
show all
Defined in:
lib/factorio_mods/api/web_authentication.rb

Overview

Constant Summary collapse

BASE_URL =
'https://auth.factorio.com'.freeze
API_VERSION =
2

Class Method Summary collapse

Class Method Details

.login(username, password, version = API_VERSION, ownership = false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/factorio_mods/api/web_authentication.rb', line 15

def self.(username, password, version = API_VERSION, ownership = false)
  resp = Net::HTTP.post_form(URI(BASE_URL + '/api-login'),
                             username: username,
                             password: password,
                             api_version: version,
                             require_game_ownership: ownership.to_s)
  resp.value
  data = JSON.parse(resp.body, symbolize_names: true)

  @username = data[:username]
  @token = data[:token]
end

.tokenObject



11
12
13
# File 'lib/factorio_mods/api/web_authentication.rb', line 11

def self.token
  @token
end

.usernameObject



7
8
9
# File 'lib/factorio_mods/api/web_authentication.rb', line 7

def self.username
  @username
end