Class: Genba::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/genba/client.rb,
lib/genba/client/keys.rb,
lib/genba/client/prices.rb,
lib/genba/client/reports.rb,
lib/genba/client/products.rb,
lib/genba/client/restrictions.rb,
lib/genba/client/direct_entitlements.rb

Overview

Genba API Client

Defined Under Namespace

Classes: DirectEntitlements, Keys, Prices, Products, Reports, Restrictions

Constant Summary collapse

API_URL =
'https://api.genbagames.com/api'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_id:, username:, api_key:, customer_account_id:) ⇒ Client

Desribe the behaviour of the method

Attributes

  • config - Genba API credential attribute

Options



20
21
22
23
24
25
# File 'lib/genba/client.rb', line 20

def initialize(app_id:, username:, api_key:, customer_account_id:)
  @app_id = app_id.strip
  @username = username.strip
  @api_key = api_key.strip
   = .strip
end

Instance Attribute Details

#customer_account_idObject

Returns the value of attribute customer_account_id.



6
7
8
# File 'lib/genba/client.rb', line 6

def 
  
end

Instance Method Details

#direct_entitlementsObject



85
86
87
# File 'lib/genba/client.rb', line 85

def direct_entitlements
  DirectEntitlements.new(self)
end

#generate_tokenObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/genba/client.rb', line 27

def generate_token
  unless token_valid?
    body = { appId: @app_id, signature: genba_signature }
    response = RestClient.post(
      "#{API_URL}/token",
      body,
      headers: { accept: 'application/json', 'Content-Type': 'application/json' }
    )
    parsed_response = decode_json(response.body)
    @id_token = parsed_response['token']
    @expires_on = Time.parse(parsed_response['expiration'])
  end
  raw_token
end

#keysObject



81
82
83
# File 'lib/genba/client.rb', line 81

def keys
  Keys.new(self)
end

#pricesObject



73
74
75
# File 'lib/genba/client.rb', line 73

def prices
  Prices.new(self)
end

#productsObject



69
70
71
# File 'lib/genba/client.rb', line 69

def products
  Products.new(self)
end

#reportsObject



89
90
91
# File 'lib/genba/client.rb', line 89

def reports
  Reports.new(self)
end

#rest_get_with_token(path, query_params = {}, headers = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/genba/client.rb', line 42

def rest_get_with_token(path, query_params = {}, headers = {})
  genba_headers = token.merge(headers)
  Genba::Util.log_debug "API Headers: #{genba_headers.inspect}"
  api_url = "#{API_URL}#{path}"
  api_url += "?#{query_params.to_query}" unless query_params.empty?
  Genba::Util.log_info "api_url: #{api_url}"
  response = RestClient.get(api_url, genba_headers)
  from_rest_client_response(response)
end

#rest_post_with_token(path, body = {}, headers = {}) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/genba/client.rb', line 60

def rest_post_with_token(path, body = {}, headers = {})
  genba_headers = token.merge(headers)
  Genba::Util.log_debug "API Headers: #{genba_headers.inspect}"
  Genba::Util.log_info "api_url: #{API_URL}#{path}"
  Genba::Util.log_info "body: #{body}"
  response = RestClient.post("#{API_URL}#{path}", encode_json(body), genba_headers)
  from_rest_client_response(response)
end

#rest_put_with_token(path, body = {}, headers = {}) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/genba/client.rb', line 52

def rest_put_with_token(path, body = {}, headers = {})
  genba_headers = token.merge(headers)
  Genba::Util.log_debug "API Headers: #{genba_headers.inspect}"
  Genba::Util.log_info "api_url: #{API_URL}#{path}"
  response = RestClient.put("#{API_URL}#{path}", encode_json(body), genba_headers)
  from_rest_client_response(response)
end

#restrictionsObject



77
78
79
# File 'lib/genba/client.rb', line 77

def restrictions
  Restrictions.new(self)
end