alphaSDK 0.2.6 → 0.2.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fce1ae63c92d753f9e6259e1879e31943136eee81eee60ee7282da75a1295da8
4
- data.tar.gz: 9225dc4c5c30c1c31a127dccb540b73db610c9d611f9369b1fb2480accd25f3f
3
+ metadata.gz: 88ef178f4bd2c5c3f18a78e7c36c3bdf6e9f8a0f02aef00e0afe504a10e5a4b3
4
+ data.tar.gz: '05138f7347397ea0cd927cdb7a61bd614a075d60a66708d859122a65395b0064'
5
5
  SHA512:
6
- metadata.gz: d70c86ed0f885b71e485fb725aa52049d42e3d729b25a52fe6c2204b0e1156caa4524e47cf9c001380149b183f31f2c2937796019c081e1fbb44b1cca9b700e8
7
- data.tar.gz: fca1964701315edb2eb1324164819b76311ee30d27e44a72c33db6fa425a235fe6117da8494bc33aa8989b48a527dcf9e11887a43aa55e84b4748a41ab1d989d
6
+ metadata.gz: b4e5be9b8c39c2fe1a46c5277d47ad79014d20a58590a7938398649ec05380c3038c89403db404689fd37f272d61bea747be84a838b63eac2432a767f6be76d4
7
+ data.tar.gz: 8bfc3c8cb91c3a046037d530b62cf0303793afc8bbaa1c8ef72e513ae65437cc73336ff44e3166da6dd2638ad889458ef6083b05b66ed42809e01d87af165a55
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- alphaSDK (0.2.5)
4
+ alphaSDK (0.2.6)
5
5
  rake (>= 12.0)
6
6
  rspec (>= 3.0)
7
7
 
@@ -1,3 +1,4 @@
1
+ # This file is not to be executed, this is for offering examples for the usage of the SDK
1
2
  require "gameball"
2
3
  Gameball.api_key = "7c7636658209418c9a82306a421f76a5"
3
4
  Gameball.api_version = "v2.0"
@@ -1,5 +1,5 @@
1
1
  module Gameball
2
- class GameballError < StandardError
2
+ class GameballError < StandardError # Custom GameballError that inherits from Ruby StandardError
3
3
  def initialize(msg = "Something went wrong while authorizing your request")
4
4
  super(msg)
5
5
  end
@@ -9,42 +9,46 @@ module Gameball
9
9
  body[:transactionTime] = Time.now.utc
10
10
  body["hash"] = Gameball::Utils::hashBody(playerUniqueId: body[:playerUniqueId])
11
11
  res = Gameball::Utils::request("post", "/Integrations/Coupon", body)
12
+ # Check for HTTP Success and throws error if not success
12
13
  unless res.kind_of? Net::HTTPSuccess
13
14
  if res.kind_of? Net::HTTPInternalServerError
14
15
  raise Gameball::GameballError.new("An Internal Server Error has occurred")
15
16
  else
16
- raise Gameball::GameballError.new(res.body) # use custom message
17
+ raise Gameball::GameballError.new(res.body)
17
18
  end
18
19
  else
19
20
  return res
20
21
  end
21
22
  end
22
23
  def self.validate_discount_coupon(body)
24
+ # Validating keys in incoming body
23
25
  Gameball::Utils.validate(body, ["playerUniqueId", "code"])
24
26
  body[:transactionTime] = Time.now.utc
25
-
26
27
  body["hash"] = Gameball::Utils::hashBody(playerUniqueId: body[:playerUniqueId])
27
28
  res = Gameball::Utils::request("post", "/Integrations/Coupon/Validate", body)
29
+ # Check for HTTP Success and throws error if not success
28
30
  unless res.kind_of? Net::HTTPSuccess
29
31
  if res.kind_of? Net::HTTPInternalServerError
30
32
  raise Gameball::GameballError.new("An Internal Server Error has occurred")
31
33
  else
32
- raise Gameball::GameballError.new(res.body) # use custom message
34
+ raise Gameball::GameballError.new(res.body)
33
35
  end
34
36
  else
35
37
  return res
36
38
  end
37
39
  end
38
40
  def self.redeem_discount_coupon(body)
41
+ # Check for HTTP Success and throws error if not success
39
42
  Gameball::Utils.validate(body, ["playerUniqueId", "code"])
40
43
  body[:transactionTime] = Time.now.utc
41
44
  body["hash"] = Gameball::Utils::hashBody(playerUniqueId: body[:playerUniqueId])
42
45
  res = Gameball::Utils::request("post", "/Integrations/Coupon/Redeem", body)
46
+ # Check for HTTP Success and throws error if not success
43
47
  unless res.kind_of? Net::HTTPSuccess
44
48
  if res.kind_of? Net::HTTPInternalServerError
45
49
  raise Gameball::GameballError.new("An Internal Server Error has occurred")
46
50
  else
47
- raise Gameball::GameballError.new(res.body) # use custom message
51
+ raise Gameball::GameballError.new(res.body)
48
52
  end
49
53
  else
50
54
  return true
@@ -1,29 +1,30 @@
1
1
  module Gameball
2
2
  class Event
3
3
  def self.sendEvent(eventBody)
4
+ # Validating keys in incoming body
4
5
  Gameball::Utils.validate(eventBody, ["events", "playerUniqueId"], ["playerAttributes"])
5
6
  res = Gameball::Utils::request("post", "/integrations/event", eventBody)
7
+ # Check for HTTP Success and throws error if not success
6
8
  unless res.kind_of? Net::HTTPSuccess
7
9
  if res.kind_of? Net::HTTPInternalServerError
8
10
  raise Gameball::GameballError.new("An Internal Server Error has occurred")
9
11
  else
10
- raise Gameball::GameballError.new(res.body) # use custom message
12
+ raise Gameball::GameballError.new(res.body)
11
13
  end
12
14
  else
13
15
  return true
14
16
  end
15
17
  end
16
18
  def self.sendEvent_async(eventBody)
19
+ # Validating keys in incoming body
17
20
  Gameball::Utils.validate(eventBody, ["events", "playerUniqueId"], ["playerAttributes"])
18
- if eventBody.has_key?(:playerAttributes)
19
- # Gameball::Utils.validate(eventBody[:playerAttributes],['displayName','firstName','lastName','email','gender','mobileNumber','dateOfBirth','joinDate'],['custom'])
20
- end
21
21
  res = Gameball::Utils::request_async("post", "/integrations/event", eventBody)
22
+ # Check for HTTP Success and throws error if not success
22
23
  unless res.kind_of? Net::HTTPSuccess
23
24
  if res.kind_of? Net::HTTPInternalServerError
24
25
  raise Gameball::GameballError.new("An Internal Server Error has occurred")
25
26
  else
26
- raise Gameball::GameballError.new(res.body) # use custom message
27
+ raise Gameball::GameballError.new(res.body)
27
28
  end
28
29
  else
29
30
  return true
@@ -1,22 +1,22 @@
1
1
  module Gameball
2
2
  class Player
3
- # include Gameball::Request
4
- def self.initialize_player(customerBody)
5
- Gameball::Utils.validate(customerBody, ["playerAttributes", "playerUniqueId"], [])
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
6
7
  begin
7
- customerBody[:playerAttributes][:joinDate] = customerBody[:playerAttributes][:joinDate].iso8601
8
- customerBody[:playerAttributes][:dateOfBirth] = customerBody[:playerAttributes][:dateOfBirth].iso8601
8
+ body[:playerAttributes][:joinDate] = body[:playerAttributes][:joinDate].iso8601
9
+ body[:playerAttributes][:dateOfBirth] = body[:playerAttributes][:dateOfBirth].iso8601
9
10
  rescue NoMethodError => exception
10
- # p exception
11
11
  raise Gameball::GameballError.new("Invalid Date Format, Please use Time and Date objects")
12
12
  end
13
-
14
- res = Gameball::Utils::request("post", "/integrations/player", customerBody)
13
+ # Check for HTTP Success and throws error if not success
14
+ res = Gameball::Utils::request("post", "/integrations/player", body)
15
15
  unless res.kind_of? Net::HTTPSuccess
16
16
  if res.kind_of? Net::HTTPInternalServerError
17
17
  raise Gameball::GameballError.new("An Internal Server Error has occurred")
18
18
  else
19
- raise Gameball::GameballError.new(res.body) # use custom message
19
+ raise Gameball::GameballError.new(res.body)
20
20
  end
21
21
  else
22
22
  return res
@@ -26,11 +26,12 @@ module Gameball
26
26
  body = { playerUniqueId: playerUniqueId }
27
27
  body["hash"] = Gameball::Utils::hashBody(playerUniqueId: playerUniqueId)
28
28
  res = Gameball::Utils::request("post", "/integrations/Player/Info", body)
29
+ # Check for HTTP Success and throws error if not success
29
30
  unless res.kind_of? Net::HTTPSuccess
30
31
  if res.kind_of? Net::HTTPInternalServerError
31
32
  raise Gameball::GameballError.new("An Internal Server Error has occurred")
32
33
  else
33
- raise Gameball::GameballError.new(res.body) # use custom message
34
+ raise Gameball::GameballError.new(res.body)
34
35
  end
35
36
  else
36
37
  return res
@@ -10,7 +10,7 @@ module Gameball
10
10
  if res.kind_of? Net::HTTPInternalServerError
11
11
  raise Gameball::GameballError.new("An Internal Server Error has occurred")
12
12
  else
13
- raise Gameball::GameballError.new(res.body) # use custom message
13
+ raise Gameball::GameballError.new(res.body)
14
14
  end
15
15
  else
16
16
  return true
@@ -7,7 +7,7 @@ module Gameball
7
7
  hash: hashedBody }
8
8
  res = Gameball::Utils::request("post", "/integrations/transaction/balance", body)
9
9
  unless res.kind_of? Net::HTTPSuccess
10
- raise Gameball::GameballError.new(res.body) # use custom message
10
+ raise Gameball::GameballError.new(res.body)
11
11
  else
12
12
  return res
13
13
  end
@@ -24,7 +24,7 @@ module Gameball
24
24
  if res.kind_of? Net::HTTPInternalServerError
25
25
  raise Gameball::GameballError.new("An Internal Server Error has occurred")
26
26
  else
27
- raise Gameball::GameballError.new(res.body) # use custom message
27
+ raise Gameball::GameballError.new(res.body)
28
28
  end
29
29
  else
30
30
  return res
@@ -40,7 +40,7 @@ module Gameball
40
40
  if res.kind_of? Net::HTTPInternalServerError
41
41
  raise Gameball::GameballError.new("An Internal Server Error has occurred")
42
42
  else
43
- raise Gameball::GameballError.new(res.body) # use custom message
43
+ raise Gameball::GameballError.new(res.body)
44
44
  end
45
45
  else
46
46
  return res
@@ -56,7 +56,7 @@ module Gameball
56
56
  if res.kind_of? Net::HTTPInternalServerError
57
57
  raise Gameball::GameballError.new("An Internal Server Error has occurred")
58
58
  else
59
- raise Gameball::GameballError.new(res.body) # use custom message
59
+ raise Gameball::GameballError.new(res.body)
60
60
  end
61
61
  else
62
62
  return res
@@ -72,7 +72,7 @@ module Gameball
72
72
  if res.kind_of? Net::HTTPInternalServerError
73
73
  raise Gameball::GameballError.new("An Internal Server Error has occurred")
74
74
  else
75
- raise Gameball::GameballError.new(res.body) # use custom message
75
+ raise Gameball::GameballError.new(res.body)
76
76
  end
77
77
  else
78
78
  return true
@@ -89,7 +89,7 @@ module Gameball
89
89
  if res.kind_of? Net::HTTPInternalServerError
90
90
  raise Gameball::GameballError.new("An Internal Server Error has occurred")
91
91
  else
92
- raise Gameball::GameballError.new(res.body) # use custom message
92
+ raise Gameball::GameballError.new(res.body)
93
93
  end
94
94
  else
95
95
  return res
@@ -2,7 +2,7 @@ module Gameball
2
2
  module Utils
3
3
  extend self
4
4
 
5
- def hashBody(playerUniqueId:, transactionTime: "", amount: "")
5
+ def hashBody(playerUniqueId:, transactionTime: "", amount: "") # Helper method that hashes the attributes that are sent using SHA1 algorithm
6
6
  # Check if transaction Key is provided else raise Error
7
7
  if !Gameball.transaction_key
8
8
  raise Gameball::GameballError.new("Please provide transaction_key, try Gameball::transaction_key='your_key'") # Raise exception
@@ -13,11 +13,12 @@ module Gameball
13
13
  formatted_time = transactionTime.strftime("%y%m%d%H%M%S")
14
14
  end
15
15
  end
16
+
16
17
  str = playerUniqueId + ":" + formatted_time + ":" + amount.to_s + ":" + Gameball.transaction_key
17
18
  return Digest::SHA1.hexdigest (str)
18
19
  end
19
20
 
20
- def extractAttributesToHash(body)
21
+ def extractAttributesToHash(body) # Helper method that extracts the attributes from the body and pass it to hashing function
21
22
  playerUniqueId = body[:playerUniqueId]
22
23
  amount = body[:amount]
23
24
  transactionTime = body[:transactionTime]
@@ -26,6 +27,7 @@ module Gameball
26
27
  rescue NoMethodError => exception
27
28
  raise Gameball::GameballError.new("Invalid Date Formate, Please use Date and Time objects")
28
29
  end
30
+
29
31
  body["hash"] = Gameball::Utils::hashBody(playerUniqueId: playerUniqueId, amount: (amount || ""), transactionTime: (transactionTime || ""))
30
32
  body
31
33
  end
@@ -3,7 +3,7 @@ module Gameball
3
3
  extend self
4
4
 
5
5
  def request(verb, path, body = {})
6
- #check for api_version and key and throw exceptions
6
+ # check for api_version and key and throw error if not included
7
7
  if !Gameball.api_key
8
8
  raise Gameball::GameballError.new("Please provide the api_key before making a request, try Gameball::api_key='your_key'")
9
9
  end
@@ -28,14 +28,7 @@ module Gameball
28
28
  raise Gameball::GameballException.new("Please provide a valid HTTP Verb") # will later throw an exception
29
29
  end
30
30
  if body != {}
31
- # puts body
32
- # begin
33
31
  req.body = body.to_json
34
- # p req.body
35
- # rescue JSON::ParserError => exception
36
-
37
- # end
38
-
39
32
  end
40
33
  req["APIKey"] = Gameball.api_key
41
34
  res = https.request(req)
@@ -68,23 +61,13 @@ module Gameball
68
61
  puts "Please Provide a valid verb" # will later throw an exception
69
62
  end
70
63
  if body != {}
71
- # puts body
72
- # begin
73
64
  req.body = body.to_json
74
- # p req.body
75
- # rescue JSON::ParserError => exception
76
-
77
- # end
78
-
79
65
  end
80
66
  req["APIKey"] = Gameball.api_key
81
67
  Thread.new do
82
68
  res = https.request(req)
83
69
  return res
84
- p "I am in thread" + res.body
85
70
  end
86
- # thread.join
87
- # return res
88
71
  end
89
72
  end
90
73
  end
@@ -2,15 +2,17 @@ module Gameball
2
2
  module Utils
3
3
  extend self
4
4
 
5
- def validate(hash, required, optional)
5
+ def validate(hash, required, optional) # Method used to validate body parameters by checking optional fields and required fields
6
6
  errors = []
7
+ # Loop on required fields and throw error if field is not in ruby hash
7
8
  required.each do |val|
8
9
  raise Gameball::GameballError.new("Required key: #{val.to_sym.inspect}") unless hash.has_key?(val.to_sym)
9
10
  end
10
- optional = optional + required
11
+ allowed = optional + required
12
+ # Loop on each field in ruby hash and check if it is allowed
11
13
  hash.each_key do |val|
12
- unless optional.include?(val.to_s)
13
- raise Gameball::GameballError.new("Unknown key: #{val.to_sym.inspect}. Valid keys are: #{optional.map(&:inspect).join(", ")}")
14
+ unless allowed.include?(val.to_s)
15
+ raise Gameball::GameballError.new("Unknown key: #{val.to_sym.inspect}. Valid keys are: #{allowed.map(&:inspect).join(", ")}")
14
16
  end
15
17
  end
16
18
  end
@@ -1,3 +1,3 @@
1
1
  module Gameball
2
- VERSION = "0.2.6" # Version of the SDK
2
+ VERSION = "0.2.7" # Version of the SDK
3
3
  end
@@ -3,11 +3,6 @@ Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
3
3
  Gameball::api_version = "v2.0"
4
4
  Gameball::transaction_key = "26e1967d89114388bdd1772587c336c8"
5
5
  # res=Gameball::Transaction.get_player_balance("uniqueKey00")
6
- <<<<<<< HEAD
7
- res = Gameball::Player.initialize_player({ playerUniqueId: "uniquekeys120", playerAttributes: { displayName: "Souidan", firstName: "Souidan1", lastName: "Souidan2", email: "alisouidan@gmail.com",
8
- gender: "Male", mobileNumber: "+201002580909",
9
- dateOfBirth: Date.parse("10/10/2010"), joinDate: Time.now.utc } })
10
- =======
11
6
  # res = Gameball::Player.initialize_player({ playerUniqueId: "uniquekeys120", playerAttributes: { displayName: "Souidan", firstName: "Souidan1", lastName: "Souidan2", email: "alisouidan@gmail.com",
12
7
  # gender: "Male", mobileNumber: "+201002580909",
13
8
  # dateOfBirth: Date.parse("10/10/2010"), joinDate: Time.now.utc } })
@@ -22,7 +17,6 @@ reserve:{rooms:2}
22
17
  }
23
18
  }
24
19
  )
25
- >>>>>>> aece124df52cb5113b88b74b8e8eb5c68bec89ef
26
20
  # res=Gameball::Transaction.hold_points({
27
21
  # playerUniqueId:"uniqueKey00",
28
22
  # amount:2,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alphaSDK
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alsouidan
@@ -54,7 +54,6 @@ files:
54
54
  - LICENSE.txt
55
55
  - README.md
56
56
  - Rakefile
57
- - alphaSDK-0.2.5.gem
58
57
  - bin/console
59
58
  - bin/setup
60
59
  - examples.rb
@@ -72,7 +71,6 @@ files:
72
71
  - lib/gameball/utils/validation.rb
73
72
  - lib/gameball/version.rb
74
73
  - lib/testFile.rb
75
- - unitTests.rb
76
74
  homepage: http://mygemserver.com
77
75
  licenses:
78
76
  - MIT
Binary file
@@ -1,326 +0,0 @@
1
- require "rspec/autorun"
2
- require "./lib/gameball"
3
-
4
- RSpec.describe Gameball::Player do
5
- before (:each) {
6
- Gameball::api_key = nil
7
- Gameball::api_version = nil
8
- }
9
- # Gameball::transaction_key="26e1967d89114388bdd1772587c336c8"
10
- it "Initializes a new Gameball player" do
11
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
12
- Gameball::api_version = "v2.0"
13
- playerUniqueId = rand 50000..10000000
14
- res = Gameball::Player.initialize_player({ playerUniqueId: playerUniqueId, playerAttributes: { displayName: "Souidan", firstName: "Souidan1", lastName: "Souidan2", email: "alisouidan@gmail.com", gender: "Male", mobileNumber: "+201002580909", dateOfBirth: Time.now.utc, joinDate: Time.now.utc } })
15
- expect(res.code).to eq("200")
16
- end
17
- it "Initializes a new Gameball player 2" do
18
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
19
- Gameball::api_version = "v2.0"
20
- playerUniqueId = rand 50000..10000000
21
- res = Gameball::Player.initialize_player({ playerUniqueId: playerUniqueId, playerAttributes: { displayName: "Souidan", firstName: "Souidan1", lastName: "Souidan2",
22
- email: "alisouidan@gmail.com", gender: "Male", mobileNumber: "+201002580909",
23
- dateOfBirth: Time.now.utc, joinDate: Time.now.utc,
24
- custom: {
25
- location: "Miami",
26
- graduationDate: "2018-07-04T21:06:29.158Z",
27
- isMarried: false,
28
- } } })
29
- expect(res.code).to eq("200")
30
- end
31
- it "Gets player info" do
32
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
33
- Gameball::api_version = "v2.0"
34
- Gameball::transaction_key = "26e1967d89114388bdd1772587c336c8"
35
- res = Gameball::Player.get_player_info("player123")
36
- expect(res.code).to eq("200")
37
- end
38
- context "When user doesn't include api_key" do
39
- it "Throws GameballError" do
40
- playerUniqueId = rand 50000..10000000
41
- body = { playerUniqueId: playerUniqueId, playerAttributes: { displayName: "Souidan", firstName: "Souidan1", lastName: "Souidan2", email: "alisouidan@gmail.com", gender: "Male", mobileNumber: "+201002580909", dateOfBirth: Time.now.utc, joinDate: Time.now.utc } }
42
- expect { Gameball::Player.initialize_player(body) }.to raise_error(Gameball::GameballError)
43
- end
44
- end
45
- context "When user doesn't include correct parameters" do
46
- it "Throws GameballError when removing playerUniqueId" do
47
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
48
- Gameball::api_version = "v2.0"
49
- playerUniqueId = rand 50000..10000000
50
- body = { playerAttributes: { displayName: "Souidan", firstName: "Souidan1", lastName: "Souidan2", email: "alisouidan@gmail.com", gender: "Male", mobileNumber: "+201002580909", dateOfBirth: Time.now.utc, joinDate: Time.now.utc } }
51
- expect { Gameball::Player.initialize_player(body) }.to raise_error(Gameball::GameballError)
52
- end
53
- it "Throws GameballError when sending empty body" do
54
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
55
- Gameball::api_version = "v2.0"
56
- playerUniqueId = rand 50000..10000000
57
- body = {}
58
- expect { Gameball::Player.initialize_player(body) }.to raise_error(Gameball::GameballError)
59
- end
60
- end
61
- context "When user includes an incorrect date format" do
62
- it "Throws GameballError" do
63
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
64
- Gameball::api_version = "v2.0"
65
- playerUniqueId = rand 50000..10000000
66
- body = { playerUniqueId: playerUniqueId, playerAttributes: { displayName: "Souidan", firstName: "Souidan1", lastName: "Souidan2", email: "alisouidan@gmail.com", gender: "Male", mobileNumber: "+201002580909", dateOfBirth: "0123", joinDate: Time.now.utc } }
67
- expect { Gameball::Player.initialize_player(body) }.to raise_error(Gameball::GameballError)
68
- end
69
- end
70
- end
71
- RSpec.describe Gameball::Event do
72
- it "create new event" do
73
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
74
- Gameball::api_version = "v2.0"
75
- res = Gameball::Event.sendEvent({
76
- events: {
77
- review: {},
78
- },
79
- playerUniqueId: "player123",
80
- })
81
- expect(res).to eq(true)
82
- end
83
- it "create new event 2" do
84
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
85
- Gameball::api_version = "v2.0"
86
- res = Gameball::Event.sendEvent({
87
- events: {
88
- reserve: {
89
- rooms: 2,
90
- },
91
- },
92
- playerUniqueId: "player123",
93
- playerAttributes: {
94
- displayName: "Jon Snow",
95
- email: "jon.snow@example.com",
96
- dateOfBirth: "1980-09-19T00:00:00.000Z",
97
- joinDate: "2019-09-19T21:06:29.158Z",
98
- },
99
- })
100
- expect(res).to eq(true)
101
- end
102
- it "create new event 3" do
103
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
104
- Gameball::api_version = "v2.0"
105
- res = Gameball::Event.sendEvent({
106
- events: {
107
- reserve: {
108
- rooms: 2,
109
- },
110
- place_order: {
111
- total_amount: "100",
112
- category: [
113
- "electronics",
114
- "cosmetics",
115
- ],
116
- },
117
- review: {},
118
- },
119
- playerUniqueId: " player123",
120
- playerAttributes: {
121
- displayName: " Jon Snow",
122
- email: "jon.snow@example.com",
123
- dateOfBirth: "1980-09-19T00:00:00.000Z",
124
- joinDate: "2019-09-19T21:06:29.158Z",
125
- custom: {
126
- location: "Miami",
127
- graduationDate: "2018-07-04T21:06:29.158Z",
128
- isMarried: false,
129
- },
130
-
131
- },
132
- })
133
- expect(res).to eq(true)
134
- end
135
- it "create new event 4" do
136
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
137
- Gameball::api_version = "v2.0"
138
- res = Gameball::Event.sendEvent({
139
- events: {
140
- place_order: {
141
- total_amount: "100",
142
- category: [
143
- "electronics",
144
- "cosmetics",
145
- ],
146
- },
147
- },
148
- playerUniqueId: "player123",
149
- })
150
- expect(res).to eq(true)
151
- end
152
- # it "create new event with optional parameters" do
153
- # Gameball::api_key="7c7636658209418c9a82306a421f76a5"
154
- # Gameball::api_version="v2.0"
155
- # res=Gameball::Event.sendEvent({
156
- # events:{view_product_page:{customer_id:"123",product_id:"123",product_title:"title",product_vendor:"vendor",shop_name:"shop"}},
157
- # playerUniqueId:"uinqueKeys123",
158
- # playerAttributes:{displayName:"Souidan",firstName:"Souidan1",lastName:"Souidan2",email:"alisouidan@gmail.com",gender:"Male",mobileNumber:"+201002580909",dateOfBirth:"0123",joinDate:Time.now.utc}
159
- # })
160
- # expect(res).to eq(true)
161
- # end
162
- RSpec.describe Gameball::Referral do
163
- it "Creates new player then new referral" do
164
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
165
- Gameball::api_version = "v2.0"
166
- playerUniqueId = rand 50000..10000000
167
- res = Gameball::Player.initialize_player({ playerUniqueId: playerUniqueId, playerAttributes: { displayName: "Souidan", firstName: "Souidan1", lastName: "Souidan2", email: "alisouidan@gmail.com", gender: "Male", mobileNumber: "+201002580909", dateOfBirth: Time.now.utc, joinDate: Time.now.utc } })
168
- playerCode = JSON.parse(res.body)["referralCode"]
169
- res = Gameball::Referral.create_referral({
170
- playerCode: playerCode,
171
- playerUniqueId: playerUniqueId,
172
- })
173
- expect(res).to eq(true)
174
- end
175
- it "Creates new player then new referral with player attributes" do
176
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
177
- Gameball::api_version = "v2.0"
178
- playerUniqueId = rand 50000..10000000
179
- res = Gameball::Player.initialize_player({ playerUniqueId: playerUniqueId, playerAttributes: { displayName: "Souidan", firstName: "Souidan1", lastName: "Souidan2", email: "alisouidan@gmail.com", gender: "Male", mobileNumber: "+201002580909", dateOfBirth: Time.now.utc, joinDate: Time.now.utc } })
180
- playerCode = JSON.parse(res.body)["referralCode"]
181
- res = Gameball::Referral.create_referral({
182
- playerCode: playerCode,
183
- playerUniqueId: playerUniqueId,
184
- playerAttributes: {
185
- displayName: " Jon Snow",
186
- email: "jon.snow@example.com",
187
- dateOfBirth: "1980-09-19T00:00:00.000Z",
188
- joinDate: "2019-09-19T21:06:29.158Z",
189
- custom: {
190
- location: "Miami",
191
- graduationDate: "2018-07-04T21:06:29.158Z",
192
- isMarried: false,
193
- },
194
- },
195
- })
196
- expect(res).to eq(true)
197
- end
198
- end
199
- RSpec.describe Gameball::Transaction do
200
- it "Makes a simple reward" do
201
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
202
- Gameball::transaction_key = "26e1967d89114388bdd1772587c336c8"
203
- Gameball::api_version = "v2.0"
204
- transactionId = rand 50000..10000000
205
- res = Gameball::Transaction.reward_points({
206
- playerUniqueId: "player123",
207
- amount: 100,
208
-
209
- transactionId: transactionId,
210
-
211
- })
212
- expect(res).to eq(true)
213
- end
214
- it "Makes a reward with player attributes" do
215
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
216
- Gameball::transaction_key = "26e1967d89114388bdd1772587c336c8"
217
- Gameball::api_version = "v2.0"
218
- transactionId = rand 50000..10000000
219
- res = Gameball::Transaction.reward_points({
220
- playerUniqueId: "player123",
221
- amount: 100,
222
-
223
- transactionId: transactionId,
224
- playerAttributes: {
225
- displayName: " Jon Snow",
226
- email: "jon.snow@example.com",
227
- dateOfBirth: "1980-09-19T00:00:00.000Z",
228
- joinDate: "2019-09-19T21:06:29.158Z",
229
- custom: {
230
- location: "Miami",
231
- graduationDate: "2018-07-04T21:06:29.158Z",
232
- isMarried: false,
233
- },
234
- },
235
-
236
- })
237
- expect(res).to eq(true)
238
- end
239
- it "Holds points" do
240
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
241
- Gameball::transaction_key = "26e1967d89114388bdd1772587c336c8"
242
- Gameball::api_version = "v2.0"
243
- res = Gameball::Transaction.hold_points({
244
- playerUniqueId: "player123",
245
- amount: 2
246
- })
247
- expect(res.code).to eq("200")
248
- end
249
- it "Redeems points" do
250
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
251
- Gameball::transaction_key = "26e1967d89114388bdd1772587c336c8"
252
- Gameball::api_version = "v2.0"
253
- res = Gameball::Transaction.hold_points({
254
- playerUniqueId: "player123",
255
- amount: 2
256
- })
257
-
258
- holdReference = JSON.parse(res.body)["holdReference"]
259
- transactionId = rand 50000..10000000
260
- res = Gameball::Transaction.redeem_points({
261
- holdReference: holdReference,
262
- playerUniqueId: "player123",
263
- transactionId: transactionId
264
- })
265
- expect(res.code).to eq("200")
266
- end
267
- it "Reverses a transaction" do
268
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
269
- Gameball::transaction_key = "26e1967d89114388bdd1772587c336c8"
270
- Gameball::api_version = "v2.0"
271
- res = Gameball::Transaction.hold_points({
272
- playerUniqueId: "player123",
273
- amount: 2
274
- })
275
- transactionId = rand 50000..10000000
276
-
277
- holdReference = JSON.parse(res.body)["holdReference"]
278
- res = Gameball::Transaction.redeem_points({
279
- holdReference: holdReference,
280
- playerUniqueId: "player123",
281
- transactionId: transactionId
282
- })
283
- res = Gameball::Transaction.reverse_transaction({
284
- playerUniqueId: "player123",
285
- transactionId: transactionId,
286
- reversedTransactionId: transactionId
287
- })
288
- expect(res.code).to eq("200")
289
- end
290
- it "Reverses a hold" do
291
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
292
- Gameball::transaction_key = "26e1967d89114388bdd1772587c336c8"
293
- Gameball::api_version = "v2.0"
294
- res = Gameball::Transaction.hold_points({
295
- playerUniqueId: "player123",
296
- amount: 2 })
297
-
298
- holdReference = JSON.parse(res.body)["holdReference"]
299
- res = Gameball::Transaction.reverse_hold({
300
- playerUniqueId: "player123",
301
- holdReference: holdReference })
302
- expect(res.code).to eq("200")
303
- end
304
- it "Gets a Player's balance" do
305
- Gameball::api_key = "7c7636658209418c9a82306a421f76a5"
306
- Gameball::transaction_key = "26e1967d89114388bdd1772587c336c8"
307
- Gameball::api_version = "v2.0"
308
- res = Gameball::Transaction.get_player_balance("player123")
309
- expect(res.code).to eq("200")
310
- end
311
- end
312
- RSpec.describe Gameball::Action do
313
- it "Sends an action with only an event" do
314
- res= Gameball::Action.send_action({
315
- playerUniqueId: "uniquekeys120",
316
- events:{
317
- review:{},
318
- reserve:{rooms:2}
319
-
320
- }
321
- })
322
- expect(res.code).to eq("200")
323
- end
324
- end
325
-
326
- end