class Ruze::Gigya

Constants

BASE_URL

Attributes

email[R]
password[R]

Public Class Methods

new(email, password) click to toggle source
# File lib/ruze/gigya.rb, line 8
def initialize(email, password)
  raise ArgumentError unless email.is_a?(String) && password.is_a?(String)

  @email = email
  @password = password
end

Public Instance Methods

jwt() click to toggle source
# File lib/ruze/gigya.rb, line 24
def jwt
  @jwt ||= return_from Net::HTTP.post_form(
    uri('/accounts.getJWT'),
    'ApiKey'      => api_key,
    'login_token' => session_cookie_value,
    'fields'      => 'data.personId,data.gigyaDataCenter',
    'expiration'  => 900
  ), keys: %w[id_token]
end
person_id() click to toggle source
# File lib/ruze/gigya.rb, line 16
def person_id
  @person_id ||= return_from Net::HTTP.post_form(
    uri('/accounts.getAccountInfo'),
    'ApiKey'      => api_key,
    'login_token' => session_cookie_value
  ), keys: %w[data personId]
end

Private Instance Methods

api_key() click to toggle source
# File lib/ruze/gigya.rb, line 45
def api_key
  ENV.fetch('GIGYA_API_KEY')
end
return_from(response, keys:) click to toggle source
# File lib/ruze/gigya.rb, line 53
def return_from(response, keys:)
  unless response.is_a?(Net::HTTPOK)
    caller = caller_locations(1, 1)[0].label
    raise Error, "Error in #{caller}: #{response.message} (#{response.code})"
  end

  json = JSON.parse(response.body)
  unless json['errorCode']&.zero?
    caller = caller_locations(1, 1)[0].label
    raise Error, "Error in #{caller}: #{json['errorDetails']}"
  end

  json.dig(*keys)
end
uri(path) click to toggle source
# File lib/ruze/gigya.rb, line 49
def uri(path)
  URI("#{BASE_URL}#{path}")
end