Class: Genba::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/genba/client.rb,
lib/genba/client/keys.rb,
lib/genba/client/prices.rb,
lib/genba/client/products.rb,
lib/genba/client/restrictions.rb
Overview
Defined Under Namespace
Classes: Keys, Prices, Products, Restrictions
Constant Summary
collapse
- API_URL =
'https://api.genbagames.com/api'.freeze
Instance Method Summary
collapse
Constructor Details
#initialize(config = {}) ⇒ Client
Desribe the behaviour of the method
Attributes
Options
18
19
20
21
22
|
# File 'lib/genba/client.rb', line 18
def initialize(config = {})
@app_id = config[:app_id]
@username = config[:username]
@api_key = config[:api_key]
end
|
Instance Method Details
#generate_token ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/genba/client.rb', line 24
def generate_token
unless token_valid?
body = { appId: @app_id, signature: genba_signature }
response = RestClient.post(
"#{API_URL}/token",
body,
headers: { accept: 'application/json' }
)
parsed_response = decode_json(response.body)
@id_token = parsed_response['token']
@expires_on = Time.parse(parsed_response['expiration'])
end
raw_token
end
|
#keys ⇒ Object
70
71
72
|
# File 'lib/genba/client.rb', line 70
def keys
Keys.new(self)
end
|
#prices ⇒ Object
62
63
64
|
# File 'lib/genba/client.rb', line 62
def prices
Prices.new(self)
end
|
#products ⇒ Object
58
59
60
|
# File 'lib/genba/client.rb', line 58
def products
Products.new(self)
end
|
#rest_get_with_token(path, query_params = {}, headers = {}) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/genba/client.rb', line 39
def rest_get_with_token(path, query_params = {}, = {})
= token.merge()
[:params] = query_params unless query_params.empty?
response = RestClient.get("#{API_URL}#{path}", )
from_rest_client_response(response)
end
|
#rest_post_with_token(path, body = {}, headers = {}) ⇒ Object
52
53
54
55
56
|
# File 'lib/genba/client.rb', line 52
def rest_post_with_token(path, body = {}, = {})
= token.merge()
response = RestClient.post("#{API_URL}#{path}", encode_json(body), )
from_rest_client_response(response)
end
|
#rest_put_with_token(path, body = {}, headers = {}) ⇒ Object
46
47
48
49
50
|
# File 'lib/genba/client.rb', line 46
def rest_put_with_token(path, body = {}, = {})
= token.merge()
response = RestClient.put("#{API_URL}#{path}", encode_json(body), )
from_rest_client_response(response)
end
|
#restrictions ⇒ Object
66
67
68
|
# File 'lib/genba/client.rb', line 66
def restrictions
Restrictions.new(self)
end
|