Module: Relaton::Un::TokenGenerator

Defined in:
lib/relaton/un/token_generator.rb

Defined Under Namespace

Classes: Heap

Constant Summary collapse

WASM_PATH =
File.join(__dir__, "wasm_v_bg.wasm")
DOMAIN =
"documents.un.org"

Class Method Summary collapse

Class Method Details

.generateString

Generates an auth token for the UN documents API. Tokens are cached per-minute since the WASM output changes each minute.

Returns:

  • (String)

    decimal string representation of the i64 token



14
15
16
17
18
19
20
21
# File 'lib/relaton/un/token_generator.rb', line 14

def self.generate
  now = Time.now.utc
  key = [now.year, now.month, now.day, now.hour, now.min]
  return @cached_token if @cached_key == key && @cached_token

  @cached_key = key
  @cached_token = call_wasm(*key)
end