alphaSDK 0.2.0 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +36 -0
- data/LICENSE.txt +21 -0
- data/README.md +259 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/examples.rb +174 -0
- data/gameball.gemspec +29 -0
- data/lib/gameball.rb +21 -20
- data/lib/gameball/exceptions/gameballException.rb +5 -5
- data/lib/gameball/models/action.rb +28 -10
- data/lib/gameball/models/coupon.rb +50 -29
- data/lib/gameball/models/event.rb +30 -25
- data/lib/gameball/models/player.rb +37 -28
- data/lib/gameball/models/referral.rb +24 -20
- data/lib/gameball/models/transaction.rb +90 -64
- data/lib/gameball/utils/helper.rb +30 -34
- data/lib/gameball/utils/request.rb +65 -91
- data/lib/gameball/utils/validation.rb +13 -11
- data/lib/gameball/version.rb +3 -0
- data/lib/testFile.rb +24 -16
- metadata +57 -12
- data/lib/gameball/models/gameballResponse.rb +0 -0
@@ -1,32 +1,41 @@
|
|
1
1
|
module Gameball
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
2
|
+
class Player
|
3
|
+
def self.initialize_player(body)
|
4
|
+
# Validating keys in incoming body
|
5
|
+
Gameball::Utils.validate(body, ["playerAttributes", "playerUniqueId"], [])
|
6
|
+
# .iso8601 Throws an exception if not invoked on a valid date object, so it is used to check if the dates are valid
|
7
|
+
begin
|
8
|
+
body[:playerAttributes][:joinDate] = body[:playerAttributes][:joinDate].iso8601
|
9
|
+
body[:playerAttributes][:dateOfBirth] = body[:playerAttributes][:dateOfBirth].iso8601
|
10
|
+
rescue NoMethodError => exception
|
11
|
+
raise Gameball::GameballError.new("Invalid Date Format, Please use Time and Date objects")
|
12
|
+
end
|
13
|
+
# Check for HTTP Success and throws error if not success
|
14
|
+
res = Gameball::Utils::request("post", "/integrations/player", body)
|
15
|
+
unless res.kind_of? Net::HTTPSuccess
|
16
|
+
if res.kind_of? Net::HTTPInternalServerError
|
17
|
+
raise Gameball::GameballError.new("An Internal Server Error has occurred")
|
18
|
+
else
|
19
|
+
raise Gameball::GameballError.new(res.body)
|
20
20
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
else
|
22
|
+
return res
|
23
|
+
end
|
24
|
+
end
|
25
|
+
def self.get_player_info(playerUniqueId)
|
26
|
+
body = { playerUniqueId: playerUniqueId }
|
27
|
+
body["hash"] = Gameball::Utils::hashBody(playerUniqueId: playerUniqueId)
|
28
|
+
res = Gameball::Utils::request("post", "/integrations/Player/Info", body)
|
29
|
+
# Check for HTTP Success and throws error if not success
|
30
|
+
unless res.kind_of? Net::HTTPSuccess
|
31
|
+
if res.kind_of? Net::HTTPInternalServerError
|
32
|
+
raise Gameball::GameballError.new("An Internal Server Error has occurred")
|
33
|
+
else
|
34
|
+
raise Gameball::GameballError.new(res.body)
|
30
35
|
end
|
36
|
+
else
|
37
|
+
return res
|
38
|
+
end
|
31
39
|
end
|
32
|
-
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,23 +1,27 @@
|
|
1
1
|
module Gameball
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
def self.create_referral_async(body)
|
16
|
-
Gameball::Utils.validate(body,['playerUniqueId','playerCode'],['playerAttributes'])
|
17
|
-
if body.has_key?(:playerAttributes)
|
18
|
-
# Gameball::Utils.validate(body[:playerAttributes],['displayName','firstName','lastName','email','gender','mobileNumber','dateOfBirth','joinDate'],['custom'])
|
19
|
-
end
|
20
|
-
Gameball::Utils::request_async("post","/integrations/referral",body)
|
2
|
+
class Referral
|
3
|
+
def self.create_referral(body)
|
4
|
+
Gameball::Utils.validate(body, ["playerUniqueId", "playerCode"], ["playerAttributes"])
|
5
|
+
if body.has_key?(:playerAttributes)
|
6
|
+
# Gameball::Utils.validate(body[:playerAttributes],['displayName','firstName','lastName','email','gender','mobileNumber','dateOfBirth','joinDate'],['custom'])
|
7
|
+
end
|
8
|
+
res = Gameball::Utils::request("post", "/integrations/referral", body)
|
9
|
+
unless res.kind_of? Net::HTTPSuccess
|
10
|
+
if res.kind_of? Net::HTTPInternalServerError
|
11
|
+
raise Gameball::GameballError.new("An Internal Server Error has occurred")
|
12
|
+
else
|
13
|
+
raise Gameball::GameballError.new(res.body)
|
21
14
|
end
|
15
|
+
else
|
16
|
+
return true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
def self.create_referral_async(body)
|
20
|
+
Gameball::Utils.validate(body, ["playerUniqueId", "playerCode"], ["playerAttributes"])
|
21
|
+
if body.has_key?(:playerAttributes)
|
22
|
+
# Gameball::Utils.validate(body[:playerAttributes],['displayName','firstName','lastName','email','gender','mobileNumber','dateOfBirth','joinDate'],['custom'])
|
23
|
+
end
|
24
|
+
Gameball::Utils::request_async("post", "/integrations/referral", body)
|
22
25
|
end
|
23
|
-
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,73 +1,99 @@
|
|
1
1
|
module Gameball
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# check if attributes are available
|
19
|
-
Gameball::Utils.validate(body,['playerUniqueId','amount','transactionTime'],['otp'])
|
2
|
+
class Transaction
|
3
|
+
# include Gameball::Utils
|
4
|
+
def self.get_player_balance(playerId)
|
5
|
+
hashedBody = Gameball::Utils::hashBody(playerUniqueId: playerId)
|
6
|
+
body = { playerUniqueId: playerId,
|
7
|
+
hash: hashedBody }
|
8
|
+
res = Gameball::Utils::request("post", "/integrations/transaction/balance", body)
|
9
|
+
unless res.kind_of? Net::HTTPSuccess
|
10
|
+
raise Gameball::GameballError.new(res.body)
|
11
|
+
else
|
12
|
+
return res
|
13
|
+
end
|
14
|
+
end
|
15
|
+
def self.hold_points(body)
|
16
|
+
# puts body
|
17
|
+
# check if attributes are available
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
Gameball::Utils.validate(body, ["playerUniqueId", "amount"], ["otp"])
|
20
|
+
body[:transactionTime] = Time.now.utc
|
21
|
+
body = Gameball::Utils::extractAttributesToHash(body)
|
22
|
+
res = Gameball::Utils::request("post", "/integrations/transaction/hold", body)
|
23
|
+
unless res.kind_of? Net::HTTPSuccess
|
24
|
+
if res.kind_of? Net::HTTPInternalServerError
|
25
|
+
raise Gameball::GameballError.new("An Internal Server Error has occurred")
|
26
|
+
else
|
27
|
+
raise Gameball::GameballError.new(res.body)
|
28
28
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
else
|
30
|
+
return res
|
31
|
+
end
|
32
|
+
end
|
33
|
+
def self.redeem_points(body)
|
34
|
+
# check if attributes are available
|
35
|
+
Gameball::Utils.validate(body, ["holdReference", "playerUniqueId", "transactionId"], [])
|
36
|
+
body[:transactionTime] = Time.now.utc
|
37
|
+
body = Gameball::Utils::extractAttributesToHash(body)
|
38
|
+
res = Gameball::Utils::request("post", "/integrations/transaction/redeem", body)
|
39
|
+
unless res.kind_of? Net::HTTPSuccess
|
40
|
+
if res.kind_of? Net::HTTPInternalServerError
|
41
|
+
raise Gameball::GameballError.new("An Internal Server Error has occurred")
|
42
|
+
else
|
43
|
+
raise Gameball::GameballError.new(res.body)
|
39
44
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
else
|
46
|
+
return res
|
47
|
+
end
|
48
|
+
end
|
49
|
+
def self.reverse_transaction(body)
|
50
|
+
Gameball::Utils.validate(body, ["reversedTransactionId", "playerUniqueId", "transactionId"], [])
|
51
|
+
body[:transactionTime] = Time.now.utc
|
52
|
+
|
53
|
+
body = Gameball::Utils::extractAttributesToHash(body)
|
54
|
+
res = Gameball::Utils::request("post", "/integrations/transaction/cancel", body)
|
55
|
+
unless res.kind_of? Net::HTTPSuccess
|
56
|
+
if res.kind_of? Net::HTTPInternalServerError
|
57
|
+
raise Gameball::GameballError.new("An Internal Server Error has occurred")
|
58
|
+
else
|
59
|
+
raise Gameball::GameballError.new(res.body)
|
49
60
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
61
|
+
else
|
62
|
+
return res
|
63
|
+
end
|
64
|
+
end
|
65
|
+
def self.reward_points(body)
|
66
|
+
Gameball::Utils.validate(body, ["playerUniqueId", "amount", "transactionId"], ["playerAttributes"])
|
67
|
+
body[:transactionTime] = Time.now.utc
|
68
|
+
|
69
|
+
body = Gameball::Utils::extractAttributesToHash(body)
|
70
|
+
res = Gameball::Utils::request("post", "/integrations/transaction/reward", body)
|
71
|
+
unless res.kind_of? Net::HTTPSuccess
|
72
|
+
if res.kind_of? Net::HTTPInternalServerError
|
73
|
+
raise Gameball::GameballError.new("An Internal Server Error has occurred")
|
74
|
+
else
|
75
|
+
raise Gameball::GameballError.new(res.body)
|
59
76
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
77
|
+
else
|
78
|
+
return true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
def self.reverse_hold(body)
|
82
|
+
# check if holdReference is in body else throw error
|
83
|
+
Gameball::Utils.validate(body, ["holdReference", "playerUniqueId"], [])
|
84
|
+
body[:transactionTime] = Time.now.utc
|
63
85
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
86
|
+
body = Gameball::Utils::extractAttributesToHash(body)
|
87
|
+
res = Gameball::Utils::request("post", "/integrations/transaction/hold", body)
|
88
|
+
unless res.kind_of? Net::HTTPSuccess
|
89
|
+
if res.kind_of? Net::HTTPInternalServerError
|
90
|
+
raise Gameball::GameballError.new("An Internal Server Error has occurred")
|
91
|
+
else
|
92
|
+
raise Gameball::GameballError.new(res.body)
|
71
93
|
end
|
94
|
+
else
|
95
|
+
return res
|
96
|
+
end
|
72
97
|
end
|
73
|
-
end
|
98
|
+
end
|
99
|
+
end
|
@@ -1,39 +1,35 @@
|
|
1
1
|
module Gameball
|
2
|
-
|
3
|
-
|
4
|
-
def hashBody(playerUniqueId:,transactionTime:"",amount:"")
|
5
|
-
# Check if transaction Key is provided else raise Exc
|
6
|
-
if !Gameball.transaction_key
|
7
|
-
raise Gameball::GameballError.new("Please provide transaction_key, try Gameball::transaction_key='your_key'") # Raise exception
|
8
|
-
else
|
9
|
-
if transactionTime==""
|
10
|
-
formatted_time=""
|
11
|
-
else
|
12
|
-
# begin
|
13
|
-
formatted_time=transactionTime.strftime("%y%m%d%H%M%S")
|
14
|
-
# rescue => exception
|
15
|
-
|
16
|
-
# end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
str=playerUniqueId+":"+formatted_time+":"+amount.to_s+":"+Gameball.transaction_key
|
20
|
-
puts str
|
21
|
-
return Digest::SHA1.hexdigest (str)
|
22
|
-
end
|
23
|
-
def extractAttributesToHash(body)
|
24
|
-
playerUniqueId=body[:playerUniqueId]
|
25
|
-
amount=body[:amount]
|
26
|
-
transactionTime=body[:transactionTime]
|
27
|
-
begin
|
28
|
-
body[:transactionTime]=transactionTime.iso8601
|
2
|
+
module Utils
|
3
|
+
extend self
|
29
4
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
5
|
+
def hashBody(playerUniqueId:, transactionTime: "", amount: "") # Helper method that hashes the attributes that are sent using SHA1 algorithm
|
6
|
+
# Check if transaction Key is provided else raise Error
|
7
|
+
if !Gameball.transaction_key
|
8
|
+
raise Gameball::GameballError.new("Please provide transaction_key, try Gameball::transaction_key='your_key'") # Raise exception
|
9
|
+
else
|
10
|
+
if transactionTime == ""
|
11
|
+
formatted_time = ""
|
12
|
+
else
|
13
|
+
formatted_time = transactionTime.strftime("%y%m%d%H%M%S")
|
35
14
|
end
|
36
|
-
|
15
|
+
end
|
16
|
+
|
17
|
+
str = playerUniqueId + ":" + formatted_time + ":" + amount.to_s + ":" + Gameball.transaction_key
|
18
|
+
return Digest::SHA1.hexdigest (str)
|
19
|
+
end
|
20
|
+
|
21
|
+
def extractAttributesToHash(body) # Helper method that extracts the attributes from the body and pass it to hashing function
|
22
|
+
playerUniqueId = body[:playerUniqueId]
|
23
|
+
amount = body[:amount]
|
24
|
+
transactionTime = body[:transactionTime]
|
25
|
+
begin
|
26
|
+
body[:transactionTime] = transactionTime.iso8601
|
27
|
+
rescue NoMethodError => exception
|
28
|
+
raise Gameball::GameballError.new("Invalid Date Formate, Please use Date and Time objects")
|
29
|
+
end
|
37
30
|
|
31
|
+
body["hash"] = Gameball::Utils::hashBody(playerUniqueId: playerUniqueId, amount: (amount || ""), transactionTime: (transactionTime || ""))
|
32
|
+
body
|
38
33
|
end
|
39
|
-
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,99 +1,73 @@
|
|
1
1
|
module Gameball
|
2
|
-
|
3
|
-
|
4
|
-
def request(verb,path,body={})
|
5
|
-
#check for api_version and key and throw exceptions
|
6
|
-
if !Gameball.api_key
|
7
|
-
raise Gameball::GameballError.new("Please provide the api_key before making a request, try Gameball::api_key='your_key'")
|
8
|
-
end
|
9
|
-
uri=URI(Gameball.api_base+'/api'+'/'+Gameball.api_version+path)
|
2
|
+
module Utils
|
3
|
+
extend self
|
10
4
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
case verb.downcase
|
18
|
-
when "post"
|
19
|
-
req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
|
5
|
+
def request(verb, path, body = {})
|
6
|
+
# check for api_version and key and throw error if not included
|
7
|
+
if !Gameball.api_key
|
8
|
+
raise Gameball::GameballError.new("Please provide the api_key before making a request, try Gameball::api_key='your_key'")
|
9
|
+
end
|
10
|
+
uri = URI(Gameball.api_base + "/api" + "/" + Gameball.api_version + path)
|
20
11
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
req = Net::HTTP::Put.new(uri.path, initheader = {'Content-Type' =>'application/json'})
|
12
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
13
|
+
https.max_retries = Gameball.max_retries
|
14
|
+
https.read_timeout = Gameball.read_timeout
|
15
|
+
https.keep_alive_timeout = Gameball.keep_alive_timeout
|
16
|
+
https.use_ssl = true
|
27
17
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
def request_async(verb,path,body={})
|
50
|
-
#check for api_version and key and throw exceptions
|
51
|
-
if !Gameball.api_key
|
52
|
-
raise Gameball::GameballError.new("Please provide the api_key before making a request, try Gameball::api_key='your_key'")
|
53
|
-
end
|
54
|
-
uri=URI(Gameball.api_base+'/api'+'/'+Gameball.api_version+path)
|
18
|
+
case verb.downcase
|
19
|
+
when "post"
|
20
|
+
req = Net::HTTP::Post.new(uri.path, initheader = { "Content-Type" => "application/json" })
|
21
|
+
when "get"
|
22
|
+
req = Net::HTTP::Get.new(uri.path, initheader = { "Content-Type" => "application/json" })
|
23
|
+
when "put"
|
24
|
+
req = Net::HTTP::Put.new(uri.path, initheader = { "Content-Type" => "application/json" })
|
25
|
+
when "delete"
|
26
|
+
req = Net::HTTP::Delete.new(uri.path, initheader = { "Content-Type" => "application/json" })
|
27
|
+
else
|
28
|
+
raise Gameball::GameballException.new("Please provide a valid HTTP Verb") # will later throw an exception
|
29
|
+
end
|
30
|
+
if body != {}
|
31
|
+
req.body = body.to_json
|
32
|
+
end
|
33
|
+
req["APIKey"] = Gameball.api_key
|
34
|
+
res = https.request(req)
|
35
|
+
return res
|
36
|
+
end
|
55
37
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
case verb.downcase
|
63
|
-
when "post"
|
64
|
-
req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
|
38
|
+
def request_async(verb, path, body = {})
|
39
|
+
#check for api_version and key and throw exceptions
|
40
|
+
if !Gameball.api_key
|
41
|
+
raise Gameball::GameballError.new("Please provide the api_key before making a request, try Gameball::api_key='your_key'")
|
42
|
+
end
|
43
|
+
uri = URI(Gameball.api_base + "/api" + "/" + Gameball.api_version + path)
|
65
44
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
req = Net::HTTP::Put.new(uri.path, initheader = {'Content-Type' =>'application/json'})
|
45
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
46
|
+
https.max_retries = Gameball.max_retries
|
47
|
+
https.read_timeout = Gameball.read_timeout
|
48
|
+
https.keep_alive_timeout = Gameball.keep_alive_timeout
|
49
|
+
https.use_ssl = true
|
72
50
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
94
|
-
# thread.join
|
95
|
-
# return res
|
96
|
-
end
|
51
|
+
case verb.downcase
|
52
|
+
when "post"
|
53
|
+
req = Net::HTTP::Post.new(uri.path, initheader = { "Content-Type" => "application/json" })
|
54
|
+
when "get"
|
55
|
+
req = Net::HTTP::Get.new(uri.path, initheader = { "Content-Type" => "application/json" })
|
56
|
+
when "put"
|
57
|
+
req = Net::HTTP::Put.new(uri.path, initheader = { "Content-Type" => "application/json" })
|
58
|
+
when "delete"
|
59
|
+
req = Net::HTTP::Delete.new(uri.path, initheader = { "Content-Type" => "application/json" })
|
60
|
+
else
|
61
|
+
puts "Please Provide a valid verb" # will later throw an exception
|
62
|
+
end
|
63
|
+
if body != {}
|
64
|
+
req.body = body.to_json
|
65
|
+
end
|
66
|
+
req["APIKey"] = Gameball.api_key
|
67
|
+
Thread.new do
|
68
|
+
res = https.request(req)
|
69
|
+
return res
|
70
|
+
end
|
97
71
|
end
|
98
|
-
|
99
|
-
end
|
72
|
+
end
|
73
|
+
end
|