alphaSDK 0.2.0 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gameball"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/examples.rb
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
# This file is not to be executed, this is for offering examples for the usage of the SDK
|
2
|
+
require "gameball"
|
3
|
+
Gameball.api_key = "7c7636658209418c9a82306a421f76a5"
|
4
|
+
Gameball.api_version = "v2.0"
|
5
|
+
Gameball::transaction_key = "26e1967d89114388bdd1772587c336c8"
|
6
|
+
# Events
|
7
|
+
# Example 1
|
8
|
+
Gameball::Event.send_event({
|
9
|
+
events: {
|
10
|
+
place_order: {
|
11
|
+
total_amount: "100",
|
12
|
+
category: [
|
13
|
+
"electronics",
|
14
|
+
"cosmetics",
|
15
|
+
],
|
16
|
+
},
|
17
|
+
review: {},
|
18
|
+
},
|
19
|
+
playerUniqueId: "player123",
|
20
|
+
})
|
21
|
+
# Example 2
|
22
|
+
Gameball::Event.send_event({
|
23
|
+
events: {
|
24
|
+
reserve: {
|
25
|
+
rooms: 2,
|
26
|
+
},
|
27
|
+
},
|
28
|
+
playerUniqueId: " player123",
|
29
|
+
playerAttributes: {
|
30
|
+
displayName: " Jon Snow",
|
31
|
+
email: "jon.snow@example.com",
|
32
|
+
dateOfBirth: "1980-09-19T00:00:00.000Z",
|
33
|
+
joinDate: "2019-09-19T21:06:29.158Z",
|
34
|
+
},
|
35
|
+
})
|
36
|
+
# Example 3
|
37
|
+
Gameball::Event.send_event({
|
38
|
+
events: {
|
39
|
+
reserve: {
|
40
|
+
rooms: 2,
|
41
|
+
},
|
42
|
+
},
|
43
|
+
playerUniqueId: " player123",
|
44
|
+
playerAttributes: {
|
45
|
+
displayName: " Jon Snow",
|
46
|
+
email: "jon.snow@example.com",
|
47
|
+
dateOfBirth: "1980-09-19T00:00:00.000Z",
|
48
|
+
joinDate: "2019-09-19T21:06:29.158Z",
|
49
|
+
custom: {
|
50
|
+
location: "Miami",
|
51
|
+
graduationDate: "2018-07-04T21:06:29.158Z",
|
52
|
+
isMarried: false,
|
53
|
+
},
|
54
|
+
},
|
55
|
+
})
|
56
|
+
# Referrals
|
57
|
+
# Example 1
|
58
|
+
Gameball::Referral.create_referral({
|
59
|
+
playerCode: "CODE11",
|
60
|
+
playerUniqueId: "player456",
|
61
|
+
})
|
62
|
+
# Example 2
|
63
|
+
Gameball::Referral.create_referral({
|
64
|
+
playerCode: "CODE11",
|
65
|
+
playerUniqueId: "player456",
|
66
|
+
playerAttributes: {
|
67
|
+
displayName: " Tyrion Lannister",
|
68
|
+
firstName: "Tyrion",
|
69
|
+
lastName: "Lannister",
|
70
|
+
email: "tyrion@example.com",
|
71
|
+
gender: "M",
|
72
|
+
dateOfBirth: "1978-01-11T00:00:00.000Z",
|
73
|
+
joinDate: "2019-09-19T21:06:29.158Z",
|
74
|
+
custom: {
|
75
|
+
location: "Miami",
|
76
|
+
graduationDate: "2018-07-04T21:06:29.158Z",
|
77
|
+
isMarried: false,
|
78
|
+
},
|
79
|
+
},
|
80
|
+
})
|
81
|
+
# Reward
|
82
|
+
# Example 1
|
83
|
+
Gameball::Transaction.reward_points({
|
84
|
+
playerUniqueId: "player123",
|
85
|
+
amount: 99.98,
|
86
|
+
transactionId: "tra_123456789"
|
87
|
+
})
|
88
|
+
# Example 2
|
89
|
+
Gameball::Transaction.reward_points({
|
90
|
+
playerUniqueId: "player456",
|
91
|
+
amount: 2500,
|
92
|
+
transactionId: "tra_123456789",
|
93
|
+
playerAttributes: {
|
94
|
+
displayName: " Tyrion Lannister",
|
95
|
+
firstName: "Tyrion",
|
96
|
+
lastName: "Lannister",
|
97
|
+
email: "tyrion@example.com",
|
98
|
+
gender: "M",
|
99
|
+
dateOfBirth: "1978-01-11T00:00:00.000Z",
|
100
|
+
joinDate: "2019-09-19T21:06:29.158Z",
|
101
|
+
custom: {
|
102
|
+
location: "Miami",
|
103
|
+
graduationDate: "2018-07-04T21:06:29.158Z",
|
104
|
+
isMarried: false,
|
105
|
+
},
|
106
|
+
}
|
107
|
+
})
|
108
|
+
# Get Player Balance
|
109
|
+
Gameball::Transaction.get_player_balance("player456")
|
110
|
+
# Hold
|
111
|
+
# Example 1
|
112
|
+
Gameball::Transaction.hold_points({
|
113
|
+
playerUniqueId: "player456",
|
114
|
+
amount: 98.89
|
115
|
+
})
|
116
|
+
# Redeem
|
117
|
+
# Example 1
|
118
|
+
Gameball::Transaction.redeem_points({
|
119
|
+
playerUniqueId: "player456",
|
120
|
+
amount: 10,
|
121
|
+
transactionId: "tra_123456789",
|
122
|
+
holdReference: "2342452352435234"
|
123
|
+
})
|
124
|
+
# Reverse Transaction
|
125
|
+
# Example 1
|
126
|
+
Gameball::Transaction.reverse_transaction({
|
127
|
+
playerUniqueId: "player456",
|
128
|
+
transactionId: "1234567890",
|
129
|
+
reversedTransactionId: "234567891"
|
130
|
+
})
|
131
|
+
Gameball::Transaction.reverse_hold({
|
132
|
+
playerUniqueId: " player456",
|
133
|
+
holdReference: "9245fe4a-d402-451c-b9ed-9c1a04247482"
|
134
|
+
})
|
135
|
+
|
136
|
+
# Action
|
137
|
+
# Example 1
|
138
|
+
Gameball::Action.send_action({
|
139
|
+
playerUniqueId: "your_player_unique_id",
|
140
|
+
events: {
|
141
|
+
review: {},
|
142
|
+
reserve: {
|
143
|
+
rooms: 2
|
144
|
+
}
|
145
|
+
}
|
146
|
+
})
|
147
|
+
# Example 2
|
148
|
+
Gameball::Action.send_action({
|
149
|
+
playerUniqueId: "your_player_unique_id",
|
150
|
+
events: {
|
151
|
+
review: {},
|
152
|
+
reserve: {
|
153
|
+
rooms: 2
|
154
|
+
}
|
155
|
+
},
|
156
|
+
pointsTransaction: {
|
157
|
+
rewardAmount: 2,
|
158
|
+
transactionId: "234567890"
|
159
|
+
}
|
160
|
+
})
|
161
|
+
# Example 3
|
162
|
+
Gameball::Action.send_action({
|
163
|
+
playerUniqueId: "your_player_unique_id",
|
164
|
+
events: {
|
165
|
+
review: {},
|
166
|
+
reserve: {
|
167
|
+
rooms: 2
|
168
|
+
}
|
169
|
+
},
|
170
|
+
pointsTransaction: {
|
171
|
+
rewardAmount: 2,
|
172
|
+
holdReference: "2342452352435234",
|
173
|
+
transactionId: "234567890"
|
174
|
+
}
|
data/gameball.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/gameball/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "alphaSDK"
|
5
|
+
spec.version = Gameball::VERSION
|
6
|
+
spec.authors = ["Alsouidan"]
|
7
|
+
spec.email = ["alsouidan@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "Ruby SDK for Gameball's API"
|
10
|
+
spec.homepage = "https://www.gameball.co/"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
spec.add_dependency 'rake','>= 12.0'
|
14
|
+
spec.add_dependency 'rspec','>= 3.0'
|
15
|
+
# spec.metadata["allowed_push_host"] = "https://github.com/Alsouidan/alphasdk"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "http://mygemserver.com"
|
19
|
+
spec.metadata["changelog_uri"] = "http://mygemserver.com"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
end
|
data/lib/gameball.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
+
# Requiring all dependencies needed
|
1
2
|
require "net/http"
|
2
3
|
require "net/http"
|
3
4
|
require "openssl"
|
4
5
|
require "uri"
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
6
|
+
require "Time"
|
7
|
+
require "digest/sha1"
|
8
|
+
require "json"
|
9
|
+
# Requiring all the other files to help us require this fiel only
|
9
10
|
require_relative "./gameball/utils/request"
|
10
11
|
require_relative "./gameball/utils/helper"
|
11
12
|
require_relative "./gameball/utils/validation"
|
@@ -13,23 +14,23 @@ require_relative "./gameball/models/player"
|
|
13
14
|
require_relative "./gameball/models/event"
|
14
15
|
require_relative "./gameball/models/transaction"
|
15
16
|
require_relative "./gameball/models/referral"
|
17
|
+
require_relative "./gameball/models/coupon"
|
18
|
+
require_relative "./gameball/models/action"
|
16
19
|
require_relative "./gameball/exceptions/gameballException"
|
17
20
|
|
18
|
-
|
19
21
|
module Gameball
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
22
|
+
@api_base = "https://gb-api.azurewebsites.net"
|
23
|
+
@max_retries = 1
|
24
|
+
@read_timeout = 60
|
25
|
+
@keep_alive_timeout = 30
|
26
|
+
@api_version = "v2.0"
|
27
|
+
class << self
|
28
|
+
attr_accessor :api_key
|
29
|
+
attr_accessor :api_version
|
30
|
+
attr_accessor :transaction_key
|
31
|
+
attr_accessor :read_timeout
|
32
|
+
attr_accessor :max_retries
|
33
|
+
attr_reader :keep_alive_timeout
|
34
|
+
attr_reader :api_base
|
35
|
+
end
|
35
36
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Gameball
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
end
|
2
|
+
class GameballError < StandardError # Custom GameballError that inherits from Ruby StandardError
|
3
|
+
def initialize(msg = "Something went wrong while authorizing your request")
|
4
|
+
super(msg)
|
6
5
|
end
|
7
|
-
end
|
6
|
+
end
|
7
|
+
end
|
@@ -1,13 +1,31 @@
|
|
1
1
|
module Gameball
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
class Action
|
3
|
+
def self.send_action(body)
|
4
|
+
# Validating keys in incoming body
|
5
|
+
Gameball::Utils.validate(body, ["playerUniqueId"], ["playerAttributes", "events", "pointsTransaction"])
|
6
|
+
if body.has_key? (:pointsTransaction)
|
7
|
+
# Validating pointsTransaction object in body
|
8
|
+
Gameball::Utils.validate(body[:pointsTransaction], ['transactionId'],['rewardAmount','holdReference'])
|
9
|
+
body[:pointsTransaction][:transactionTime]=Time.now.utc
|
10
|
+
amount=''
|
11
|
+
if body[:pointsTransaction].has_key?(:rewardAmount)
|
12
|
+
amount=body[:pointsTransaction][:rewardAmount]
|
11
13
|
end
|
14
|
+
body[:pointsTransaction]['hash']=Gameball::Utils.hashBody(playerUniqueId:body[:playerUniqueId],transactionTime:body[:pointsTransaction][:transactionTime],amount:amount)
|
15
|
+
body[:pointsTransaction][:transactionTime]=Time.now.utc.iso8601
|
16
|
+
end
|
17
|
+
|
18
|
+
res = Gameball::Utils::request("post", "/Integrations/Action", body)
|
19
|
+
# Check for HTTP Success and throws error if not success
|
20
|
+
unless res.kind_of? Net::HTTPSuccess
|
21
|
+
if res.kind_of? Net::HTTPInternalServerError
|
22
|
+
raise Gameball::GameballError.new("An Internal Server Error has occurred")
|
23
|
+
else
|
24
|
+
raise Gameball::GameballError.new(res.body)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
return res
|
28
|
+
end
|
12
29
|
end
|
13
|
-
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,37 +1,58 @@
|
|
1
1
|
module Gameball
|
2
|
-
|
3
|
-
def self.create_discount_coupon(body)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
2
|
+
class Coupon
|
3
|
+
def self.create_discount_coupon(body)
|
4
|
+
# Validating keys in incoming body
|
5
|
+
Gameball::Utils.validate(body, ["playerUniqueId"], ["startAt", "endsAt", "entitledCollectionIds", "entitledProductIds",
|
6
|
+
"oncePerCustomer", "prerequisiteQuantityRange", "prerequisiteShippingPriceRange", "prerequisiteSubtotalRange",
|
7
|
+
"prerequisiteCollectionIds", "prerequisiteProductIds", "code", "usageLimit", "value", "valueType", "cap"])
|
8
|
+
|
9
|
+
body[:transactionTime] = Time.now.utc
|
10
|
+
body["hash"] = Gameball::Utils::hashBody(playerUniqueId: body[:playerUniqueId])
|
11
|
+
res = Gameball::Utils::request("post", "/Integrations/Coupon", body)
|
12
|
+
# Check for HTTP Success and throws error if not success
|
13
|
+
unless res.kind_of? Net::HTTPSuccess
|
14
|
+
if res.kind_of? Net::HTTPInternalServerError
|
15
|
+
raise Gameball::GameballError.new("An Internal Server Error has occurred")
|
16
|
+
else
|
17
|
+
raise Gameball::GameballError.new(res.body)
|
18
|
+
end
|
19
|
+
else
|
20
|
+
return res
|
21
|
+
end
|
14
22
|
end
|
15
23
|
def self.validate_discount_coupon(body)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
# Validating keys in incoming body
|
25
|
+
Gameball::Utils.validate(body, ["playerUniqueId", "code"])
|
26
|
+
body[:transactionTime] = Time.now.utc
|
27
|
+
body["hash"] = Gameball::Utils::hashBody(playerUniqueId: body[:playerUniqueId])
|
28
|
+
res = Gameball::Utils::request("post", "/Integrations/Coupon/Validate", 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)
|
23
35
|
end
|
36
|
+
else
|
37
|
+
return res
|
38
|
+
end
|
24
39
|
end
|
25
40
|
def self.redeem_discount_coupon(body)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
41
|
+
# Check for HTTP Success and throws error if not success
|
42
|
+
Gameball::Utils.validate(body, ["playerUniqueId", "code"])
|
43
|
+
body[:transactionTime] = Time.now.utc
|
44
|
+
body["hash"] = Gameball::Utils::hashBody(playerUniqueId: body[:playerUniqueId])
|
45
|
+
res = Gameball::Utils::request("post", "/Integrations/Coupon/Redeem", body)
|
46
|
+
# Check for HTTP Success and throws error if not success
|
47
|
+
unless res.kind_of? Net::HTTPSuccess
|
48
|
+
if res.kind_of? Net::HTTPInternalServerError
|
49
|
+
raise Gameball::GameballError.new("An Internal Server Error has occurred")
|
50
|
+
else
|
51
|
+
raise Gameball::GameballError.new(res.body)
|
33
52
|
end
|
53
|
+
else
|
54
|
+
return true
|
55
|
+
end
|
34
56
|
end
|
35
|
-
|
36
|
-
|
37
|
-
end
|
57
|
+
end
|
58
|
+
end
|
@@ -1,29 +1,34 @@
|
|
1
1
|
module Gameball
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
return true
|
14
|
-
end
|
2
|
+
class Event
|
3
|
+
def self.sendEvent(eventBody)
|
4
|
+
# Validating keys in incoming body
|
5
|
+
Gameball::Utils.validate(eventBody, ["events", "playerUniqueId"], ["playerAttributes"])
|
6
|
+
res = Gameball::Utils::request("post", "/integrations/event", eventBody)
|
7
|
+
# Check for HTTP Success and throws error if not success
|
8
|
+
unless res.kind_of? Net::HTTPSuccess
|
9
|
+
if res.kind_of? Net::HTTPInternalServerError
|
10
|
+
raise Gameball::GameballError.new("An Internal Server Error has occurred")
|
11
|
+
else
|
12
|
+
raise Gameball::GameballError.new(res.body)
|
15
13
|
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
else
|
15
|
+
return true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
def self.sendEvent_async(eventBody)
|
19
|
+
# Validating keys in incoming body
|
20
|
+
Gameball::Utils.validate(eventBody, ["events", "playerUniqueId"], ["playerAttributes"])
|
21
|
+
res = Gameball::Utils::request_async("post", "/integrations/event", eventBody)
|
22
|
+
# Check for HTTP Success and throws error if not success
|
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)
|
27
28
|
end
|
29
|
+
else
|
30
|
+
return true
|
31
|
+
end
|
28
32
|
end
|
29
|
-
end
|
33
|
+
end
|
34
|
+
end
|