alphaSDK 0.2.0 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,32 +1,41 @@
1
1
  module Gameball
2
- class Player
3
- # include Gameball::Request
4
- def self.initialize_player (customerBody)
5
- Gameball::Utils.validate(customerBody,['playerAttributes','playerUniqueId'],[])
6
- begin
7
- customerBody[:playerAttributes][:joinDate]=customerBody[:playerAttributes][:joinDate].iso8601
8
- customerBody[:playerAttributes][:dateOfBirth]=customerBody[:playerAttributes][:dateOfBirth].iso8601
9
- rescue NoMethodError => exception
10
- p exception
11
- raise Gameball::GameballError.new("Invalid Date Format, Please use Time and Date objects")
12
- end
13
-
14
- res=Gameball::Utils::request("post","/integrations/player",customerBody)
15
- unless res.kind_of? Net::HTTPSuccess
16
- raise Gameball::GameballError.new(res) # use custom message
17
- else
18
- return res
19
- end
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
- def self.get_player_info(playerUniqueId)
22
- body={playerUniqueId:playerUniqueId}
23
- body["bodyHashed"]=Gameball::Utils::hashBody(playerUniqueId:playerUniqueId)
24
- res=Gameball::Utils::request("post","/integrations/Player/Info",body)
25
- unless res.kind_of? Net::HTTPSuccess
26
- raise Gameball::GameballError.new(res) # use custom message
27
- else
28
- return res
29
- end
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
- 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
- raise Gameball::GameballError.new(res.body) # use custom message
11
- else
12
- return true
13
- end
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
- 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
- bodyHashed:hashedBody
8
- }
9
- res=Gameball::Utils::request("post","/integrations/transaction/balance",body)
10
- unless res.kind_of? Net::HTTPSuccess
11
- raise Gameball::GameballError.new(res.body) # use custom message
12
- else
13
- return res
14
- end
15
- end
16
- def self.hold_points(body)
17
- puts body
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
- body=Gameball::Utils::extractAttributesToHash(body)
22
- res=Gameball::Utils::request("post","/integrations/transaction/hold",body)
23
- unless res.kind_of? Net::HTTPSuccess
24
- raise Gameball::GameballError.new(res.body) # use custom message
25
- else
26
- return res
27
- end
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
- def self.redeem_points(body)
30
- # check if attributes are available
31
- Gameball::Utils.validate(body,['holdReference','playerUniqueId','amount','transactionOnClientSystemId','transactionTime'],[])
32
- body=Gameball::Utils::extractAttributesToHash(body)
33
- res=Gameball::Utils::request("post","/integrations/transaction/redeem",body)
34
- unless res.kind_of? Net::HTTPSuccess
35
- raise Gameball::GameballError.new(res.body) # use custom message
36
- else
37
- return res
38
- end
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
- def self.reverse_transaction(body)
41
- Gameball::Utils.validate(body,['reversedTransactionOnClientSystemId','playerUniqueId','transactionOnClientSystemId','transactionTime'],[])
42
- body=Gameball::Utils::extractAttributesToHash(body)
43
- res=Gameball::Utils::request("post","/integrations/transaction/cancel",body)
44
- unless res.kind_of? Net::HTTPSuccess
45
- raise Gameball::GameballError.new(res.body) # use custom message
46
- else
47
- return res
48
- end
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
- def self.reward_points(body)
51
- Gameball::Utils.validate(body,['playerUniqueId','amount','transactionOnClientSystemId','transactionTime'],['playerAttributes'])
52
- body=Gameball::Utils::extractAttributesToHash(body)
53
- res=Gameball::Utils::request("post","/integrations/transaction/reward",body)
54
- unless res.kind_of? Net::HTTPSuccess
55
- raise Gameball::GameballError.new(res.body) # use custom message
56
- else
57
- return true
58
- end
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
- def self.reverse_hold(body)
61
- # check if holdReference is in body else throw error
62
- Gameball::Utils.validate(body,['holdReference','playerUniqueId','transactionTime'],[])
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
- body=Gameball::Utils::extractAttributesToHash(body)
65
- res=Gameball::Utils::request("post","/integrations/transaction/hold",body)
66
- unless res.kind_of? Net::HTTPSuccess
67
- raise Gameball::GameballError.new(res.body) # use custom message
68
- else
69
- return res
70
- end
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
- module Utils
3
- extend self
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
- rescue NoMethodError => exception
31
- raise Gameball::GameballError.new("Invalid Date Formate, Please use Date and Time objects")
32
- end
33
- body["bodyHashed"]=Gameball::Utils::hashBody(playerUniqueId:playerUniqueId,amount:(amount||""),transactionTime:(transactionTime||""))
34
- body
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
- module Utils
3
- extend self
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
- https = Net::HTTP.new(uri.host,uri.port)
12
- https.max_retries=Gameball.max_retries
13
- https.read_timeout=Gameball.read_timeout
14
- https.keep_alive_timeout=Gameball.keep_alive_timeout
15
- https.use_ssl = true
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
- when "get"
22
-
23
- req = Net::HTTP::Get.new(uri.path, initheader = {'Content-Type' =>'application/json'})
24
- when "put"
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
- when "delete"
29
- req = Net::HTTP::Delete.new(uri.path, initheader = {'Content-Type' =>'application/json'})
30
- else
31
- puts "Please Provide a valid verb" # will later throw an exception
32
- end
33
- if body != {}
34
- puts body
35
- # begin
36
- req.body=body.to_json
37
- p req.body
38
- # rescue JSON::ParserError => exception
39
-
40
- # end
41
-
42
- end
43
- req['APIKey']=Gameball.api_key
44
- res=https.request(req)
45
- return res
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
- https = Net::HTTP.new(uri.host,uri.port)
57
- https.max_retries=Gameball.max_retries
58
- https.read_timeout=Gameball.read_timeout
59
- https.keep_alive_timeout=Gameball.keep_alive_timeout
60
- https.use_ssl = true
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
- when "get"
67
-
68
- req = Net::HTTP::Get.new(uri.path, initheader = {'Content-Type' =>'application/json'})
69
- when "put"
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
- when "delete"
74
- req = Net::HTTP::Delete.new(uri.path, initheader = {'Content-Type' =>'application/json'})
75
- else
76
- puts "Please Provide a valid verb" # will later throw an exception
77
- end
78
- if body != {}
79
- puts body
80
- # begin
81
- req.body=body.to_json
82
- p req.body
83
- # rescue JSON::ParserError => exception
84
-
85
- # end
86
-
87
- end
88
- req['APIKey']=Gameball.api_key
89
- Thread.new do
90
- res=https.request(req)
91
- return res
92
- p "I am in thread"+res.body
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