gameball 1.0.0
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 +7 -0
- 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 +258 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config.rb +4 -0
- data/examples.rb +173 -0
- data/gameball.gemspec +29 -0
- data/lib/gameball.rb +36 -0
- data/lib/gameball/exceptions/gameballException.rb +7 -0
- data/lib/gameball/models/action.rb +31 -0
- data/lib/gameball/models/coupon.rb +58 -0
- data/lib/gameball/models/event.rb +34 -0
- data/lib/gameball/models/player.rb +41 -0
- data/lib/gameball/models/referral.rb +27 -0
- data/lib/gameball/models/transaction.rb +99 -0
- data/lib/gameball/utils/helper.rb +35 -0
- data/lib/gameball/utils/request.rb +73 -0
- data/lib/gameball/utils/validation.rb +20 -0
- data/lib/gameball/version.rb +3 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 95b6f1f38aa23e523c6ebb65b53cc5e7025cb2d60a24cd586bb77f89a0424db4
|
4
|
+
data.tar.gz: b88767ef592e63801ffe9c7c9423641d5518b17521a54c10b89d32e0cb87dad8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 16f7bc73fbc3c2965f05a158f460c6cdf4188248499ef9c8ef0b2f81df83be80124eae2399f9460250528566fa011b63701bf52543d12ff7a29b2130e5da29c7
|
7
|
+
data.tar.gz: 797cd765e8ddcae291d9bef2d3263b7ce31381c346dd02f967bde4715c716b31a4a0e93dd73ab0217fae3ab73057f418217765933104648bbdf2a13cf1740480
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at https://www.gameball.co/. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
alphaSDK (0.2.8)
|
5
|
+
rake (>= 12.0)
|
6
|
+
rspec (>= 3.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
rake (12.0.0)
|
13
|
+
rspec (3.9.0)
|
14
|
+
rspec-core (~> 3.9.0)
|
15
|
+
rspec-expectations (~> 3.9.0)
|
16
|
+
rspec-mocks (~> 3.9.0)
|
17
|
+
rspec-core (3.9.2)
|
18
|
+
rspec-support (~> 3.9.3)
|
19
|
+
rspec-expectations (3.9.2)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.9.0)
|
22
|
+
rspec-mocks (3.9.1)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.9.0)
|
25
|
+
rspec-support (3.9.3)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
x64-mingw32
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
alphaSDK!
|
32
|
+
rake (>= 12.0)
|
33
|
+
rspec (>= 3.0)
|
34
|
+
|
35
|
+
BUNDLED WITH
|
36
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Alplayer
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,258 @@
|
|
1
|
+
# Gameball Ruby SDK
|
2
|
+
|
3
|
+
The Gameball Ruby SDK provides convenient access to the Gameball API from applications written in the Ruby language.
|
4
|
+
|
5
|
+
## Documentation
|
6
|
+
|
7
|
+
Please refer to the [Gameball API docs](https://docs.gameball.co).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
You don't need this source code unless you want to modify the SDK. If you just
|
12
|
+
want to use the SDK, just run:
|
13
|
+
|
14
|
+
```sh
|
15
|
+
gem install gameballSDK
|
16
|
+
```
|
17
|
+
|
18
|
+
### Requirements
|
19
|
+
|
20
|
+
- Ruby 2.3+ and Gem 3.0+
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
The SDK needs to be configured with your account's API & Transaction keys available in your [Gameball Dashboard](https://help.gameball.co/en/articles/3467114-get-your-account-integration-details-api-key-and-transaction-key)
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'gameball'
|
28
|
+
|
29
|
+
Gameball.api_key="api_key"
|
30
|
+
Gameball.transaction_key="transaction_key"
|
31
|
+
```
|
32
|
+
|
33
|
+
### Example
|
34
|
+
|
35
|
+
#### Sending an Event
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
# Example 1
|
39
|
+
Gameball::Event.send_event({
|
40
|
+
events:{
|
41
|
+
place_order:{
|
42
|
+
total_amount:"100",
|
43
|
+
category:[
|
44
|
+
"electronics",
|
45
|
+
"cosmetics"
|
46
|
+
]
|
47
|
+
},
|
48
|
+
review:{}
|
49
|
+
},
|
50
|
+
playerUniqueId:"player123"
|
51
|
+
})
|
52
|
+
# Example 2
|
53
|
+
Gameball::Event.send_event({
|
54
|
+
events:{
|
55
|
+
reserve:{
|
56
|
+
rooms:2
|
57
|
+
}
|
58
|
+
},
|
59
|
+
playerUniqueId:" player123",
|
60
|
+
playerAttributes:{
|
61
|
+
displayName:" Jon Snow",
|
62
|
+
email:"jon.snow@example.com",
|
63
|
+
dateOfBirth:"1980-09-19T00:00:00.000Z",
|
64
|
+
joinDate:"2019-09-19T21:06:29.158Z"
|
65
|
+
}
|
66
|
+
})
|
67
|
+
# Example 3
|
68
|
+
Gameball::Event.send_event({
|
69
|
+
events:{
|
70
|
+
reserve:{
|
71
|
+
rooms:2
|
72
|
+
}
|
73
|
+
},
|
74
|
+
playerUniqueId:" player123",
|
75
|
+
playerAttributes:{
|
76
|
+
displayName:" Jon Snow",
|
77
|
+
email:"jon.snow@example.com",
|
78
|
+
dateOfBirth:"1980-09-19T00:00:00.000Z",
|
79
|
+
joinDate:"2019-09-19T21:06:29.158Z",
|
80
|
+
custom:{
|
81
|
+
location:"Miami",
|
82
|
+
graduationDate:"2018-07-04T21:06:29.158Z",
|
83
|
+
isMarried:false
|
84
|
+
}
|
85
|
+
}
|
86
|
+
})
|
87
|
+
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
#### Create a new Referral
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
Gameball::Referral.create_referral({
|
95
|
+
playerCode:"CODE11",
|
96
|
+
playerUniqueId:"player456"
|
97
|
+
}
|
98
|
+
)
|
99
|
+
# Example 2
|
100
|
+
Gameball::Referral.create_referral({
|
101
|
+
playerCode:"CODE11",
|
102
|
+
playerUniqueId:"player456",
|
103
|
+
playerAttributes:{
|
104
|
+
displayName:" Tyrion Lannister",
|
105
|
+
firstName:"Tyrion",
|
106
|
+
lastName:"Lannister",
|
107
|
+
email:"tyrion@example.com",
|
108
|
+
gender:"M",
|
109
|
+
dateOfBirth:"1978-01-11T00:00:00.000Z",
|
110
|
+
joinDate:"2019-09-19T21:06:29.158Z",
|
111
|
+
custom:{
|
112
|
+
location:"Miami",
|
113
|
+
graduationDate:"2018-07-04T21:06:29.158Z",
|
114
|
+
isMarried:false
|
115
|
+
}
|
116
|
+
}
|
117
|
+
}
|
118
|
+
)
|
119
|
+
```
|
120
|
+
|
121
|
+
#### Reward Examples
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
# Example 1
|
125
|
+
Gameball::Transaction.reward_points({
|
126
|
+
playerUniqueId:"player123",
|
127
|
+
amount:99.98,
|
128
|
+
transactionId:"tra_123456789"
|
129
|
+
})
|
130
|
+
# Example 2
|
131
|
+
Gameball::Transaction.reward_points({
|
132
|
+
playerUniqueId:"player456",
|
133
|
+
amount:2500,
|
134
|
+
transactionId:"tra_123456789",
|
135
|
+
playerAttributes:{
|
136
|
+
displayName:" Tyrion Lannister",
|
137
|
+
firstName:"Tyrion",
|
138
|
+
lastName:"Lannister",
|
139
|
+
email:"tyrion@example.com",
|
140
|
+
gender:"M",
|
141
|
+
dateOfBirth:"1978-01-11T00:00:00.000Z",
|
142
|
+
joinDate:"2019-09-19T21:06:29.158Z",
|
143
|
+
custom:{
|
144
|
+
location:"Miami",
|
145
|
+
graduationDate:"2018-07-04T21:06:29.158Z",
|
146
|
+
isMarried:false
|
147
|
+
}
|
148
|
+
}
|
149
|
+
}
|
150
|
+
)
|
151
|
+
```
|
152
|
+
|
153
|
+
#### Get Player Balance Example
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
Gameball::Transaction.get_player_balance("player456")
|
157
|
+
```
|
158
|
+
|
159
|
+
#### Hold Points Example
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
Gameball::Transaction.hold_points({
|
163
|
+
playerUniqueId:"player456",
|
164
|
+
amount:98.89
|
165
|
+
}
|
166
|
+
)
|
167
|
+
```
|
168
|
+
|
169
|
+
#### Redeem Example
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
Gameball::Transaction.redeem_points({
|
173
|
+
playerUniqueId:"player456",
|
174
|
+
amount:10,
|
175
|
+
transactionId:"tra_123456789",
|
176
|
+
holdReference:"2342452352435234",
|
177
|
+
})
|
178
|
+
```
|
179
|
+
|
180
|
+
#### Reverse Transaction Example
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
Gameball::Transaction.reverse_transaction({
|
184
|
+
playerUniqueId:"player456",
|
185
|
+
transactionId:"1234567890",
|
186
|
+
reversedTransactionId:"234567891"
|
187
|
+
}
|
188
|
+
)
|
189
|
+
```
|
190
|
+
|
191
|
+
#### Reverse Hold Example
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
Gameball::Transaction.reverse_hold({
|
195
|
+
playerUniqueId:" player456",
|
196
|
+
holdReference:"9245fe4a-d402-451c-b9ed-9c1a04247482"
|
197
|
+
}
|
198
|
+
)
|
199
|
+
```
|
200
|
+
|
201
|
+
### Actions
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
# Example 1
|
205
|
+
Gameball::Action.send_action({
|
206
|
+
playerUniqueId: "your_player_unique_id",
|
207
|
+
events: {
|
208
|
+
review: {},
|
209
|
+
reserve: {
|
210
|
+
rooms: 2
|
211
|
+
}
|
212
|
+
}
|
213
|
+
})
|
214
|
+
# Example 2
|
215
|
+
Gameball::Action.send_action({
|
216
|
+
playerUniqueId: "your_player_unique_id",
|
217
|
+
events: {
|
218
|
+
review: {},
|
219
|
+
reserve: {
|
220
|
+
rooms: 2
|
221
|
+
}
|
222
|
+
},
|
223
|
+
pointsTransaction: {
|
224
|
+
rewardAmount: 2,
|
225
|
+
transactionId: "234567890"
|
226
|
+
}
|
227
|
+
})
|
228
|
+
# Example 3
|
229
|
+
Gameball::Action.send_action({
|
230
|
+
playerUniqueId: "your_player_unique_id",
|
231
|
+
events: {
|
232
|
+
review: {},
|
233
|
+
reserve: {
|
234
|
+
rooms: 2
|
235
|
+
}
|
236
|
+
},
|
237
|
+
pointsTransaction: {
|
238
|
+
rewardAmount: 2,
|
239
|
+
holdReference: "2342452352435234",
|
240
|
+
transactionId: "234567890"
|
241
|
+
}
|
242
|
+
```
|
243
|
+
|
244
|
+
### Testing
|
245
|
+
|
246
|
+
To test run in the terminal `bundle exec rspec spec`
|
247
|
+
|
248
|
+
### Handling exceptions
|
249
|
+
|
250
|
+
Unsuccessful requests raise exceptions. The raised exception will reflect the sort of error that occurred with appropriate message and error code . Please refer to the [Gameball API docs](https://docs.gameball.co).
|
251
|
+
|
252
|
+
## Contribution
|
253
|
+
|
254
|
+
The master branch of this repository contains the latest stable release of the SDK.
|
255
|
+
|
256
|
+
## Contact
|
257
|
+
|
258
|
+
For usage questions\suggestions drop us an email at support[ at ]gameball.co. Please report any bugs as issues.
|
data/Rakefile
ADDED
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/config.rb
ADDED
data/examples.rb
ADDED
@@ -0,0 +1,173 @@
|
|
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 = "api_key"
|
4
|
+
Gameball::transaction_key = "transaction_key"
|
5
|
+
# Events
|
6
|
+
# Example 1
|
7
|
+
Gameball::Event.send_event({
|
8
|
+
events: {
|
9
|
+
place_order: {
|
10
|
+
total_amount: "100",
|
11
|
+
category: [
|
12
|
+
"electronics",
|
13
|
+
"cosmetics",
|
14
|
+
],
|
15
|
+
},
|
16
|
+
review: {},
|
17
|
+
},
|
18
|
+
playerUniqueId: "player123",
|
19
|
+
})
|
20
|
+
# Example 2
|
21
|
+
Gameball::Event.send_event({
|
22
|
+
events: {
|
23
|
+
reserve: {
|
24
|
+
rooms: 2,
|
25
|
+
},
|
26
|
+
},
|
27
|
+
playerUniqueId: " player123",
|
28
|
+
playerAttributes: {
|
29
|
+
displayName: " Jon Snow",
|
30
|
+
email: "jon.snow@example.com",
|
31
|
+
dateOfBirth: "1980-09-19T00:00:00.000Z",
|
32
|
+
joinDate: "2019-09-19T21:06:29.158Z",
|
33
|
+
},
|
34
|
+
})
|
35
|
+
# Example 3
|
36
|
+
Gameball::Event.send_event({
|
37
|
+
events: {
|
38
|
+
reserve: {
|
39
|
+
rooms: 2,
|
40
|
+
},
|
41
|
+
},
|
42
|
+
playerUniqueId: " player123",
|
43
|
+
playerAttributes: {
|
44
|
+
displayName: " Jon Snow",
|
45
|
+
email: "jon.snow@example.com",
|
46
|
+
dateOfBirth: "1980-09-19T00:00:00.000Z",
|
47
|
+
joinDate: "2019-09-19T21:06:29.158Z",
|
48
|
+
custom: {
|
49
|
+
location: "Miami",
|
50
|
+
graduationDate: "2018-07-04T21:06:29.158Z",
|
51
|
+
isMarried: false,
|
52
|
+
},
|
53
|
+
},
|
54
|
+
})
|
55
|
+
# Referrals
|
56
|
+
# Example 1
|
57
|
+
Gameball::Referral.create_referral({
|
58
|
+
playerCode: "CODE11",
|
59
|
+
playerUniqueId: "player456",
|
60
|
+
})
|
61
|
+
# Example 2
|
62
|
+
Gameball::Referral.create_referral({
|
63
|
+
playerCode: "CODE11",
|
64
|
+
playerUniqueId: "player456",
|
65
|
+
playerAttributes: {
|
66
|
+
displayName: " Tyrion Lannister",
|
67
|
+
firstName: "Tyrion",
|
68
|
+
lastName: "Lannister",
|
69
|
+
email: "tyrion@example.com",
|
70
|
+
gender: "M",
|
71
|
+
dateOfBirth: "1978-01-11T00:00:00.000Z",
|
72
|
+
joinDate: "2019-09-19T21:06:29.158Z",
|
73
|
+
custom: {
|
74
|
+
location: "Miami",
|
75
|
+
graduationDate: "2018-07-04T21:06:29.158Z",
|
76
|
+
isMarried: false,
|
77
|
+
},
|
78
|
+
},
|
79
|
+
})
|
80
|
+
# Reward
|
81
|
+
# Example 1
|
82
|
+
Gameball::Transaction.reward_points({
|
83
|
+
playerUniqueId: "player123",
|
84
|
+
amount: 99.98,
|
85
|
+
transactionId: "tra_123456789"
|
86
|
+
})
|
87
|
+
# Example 2
|
88
|
+
Gameball::Transaction.reward_points({
|
89
|
+
playerUniqueId: "player456",
|
90
|
+
amount: 2500,
|
91
|
+
transactionId: "tra_123456789",
|
92
|
+
playerAttributes: {
|
93
|
+
displayName: " Tyrion Lannister",
|
94
|
+
firstName: "Tyrion",
|
95
|
+
lastName: "Lannister",
|
96
|
+
email: "tyrion@example.com",
|
97
|
+
gender: "M",
|
98
|
+
dateOfBirth: "1978-01-11T00:00:00.000Z",
|
99
|
+
joinDate: "2019-09-19T21:06:29.158Z",
|
100
|
+
custom: {
|
101
|
+
location: "Miami",
|
102
|
+
graduationDate: "2018-07-04T21:06:29.158Z",
|
103
|
+
isMarried: false,
|
104
|
+
},
|
105
|
+
}
|
106
|
+
})
|
107
|
+
# Get Player Balance
|
108
|
+
Gameball::Transaction.get_player_balance("player456")
|
109
|
+
# Hold
|
110
|
+
# Example 1
|
111
|
+
Gameball::Transaction.hold_points({
|
112
|
+
playerUniqueId: "player456",
|
113
|
+
amount: 98.89
|
114
|
+
})
|
115
|
+
# Redeem
|
116
|
+
# Example 1
|
117
|
+
Gameball::Transaction.redeem_points({
|
118
|
+
playerUniqueId: "player456",
|
119
|
+
amount: 10,
|
120
|
+
transactionId: "tra_123456789",
|
121
|
+
holdReference: "2342452352435234"
|
122
|
+
})
|
123
|
+
# Reverse Transaction
|
124
|
+
# Example 1
|
125
|
+
Gameball::Transaction.reverse_transaction({
|
126
|
+
playerUniqueId: "player456",
|
127
|
+
transactionId: "1234567890",
|
128
|
+
reversedTransactionId: "234567891"
|
129
|
+
})
|
130
|
+
Gameball::Transaction.reverse_hold({
|
131
|
+
playerUniqueId: " player456",
|
132
|
+
holdReference: "9245fe4a-d402-451c-b9ed-9c1a04247482"
|
133
|
+
})
|
134
|
+
|
135
|
+
# Action
|
136
|
+
# Example 1
|
137
|
+
Gameball::Action.send_action({
|
138
|
+
playerUniqueId: "your_player_unique_id",
|
139
|
+
events: {
|
140
|
+
review: {},
|
141
|
+
reserve: {
|
142
|
+
rooms: 2
|
143
|
+
}
|
144
|
+
}
|
145
|
+
})
|
146
|
+
# Example 2
|
147
|
+
Gameball::Action.send_action({
|
148
|
+
playerUniqueId: "your_player_unique_id",
|
149
|
+
events: {
|
150
|
+
review: {},
|
151
|
+
reserve: {
|
152
|
+
rooms: 2
|
153
|
+
}
|
154
|
+
},
|
155
|
+
pointsTransaction: {
|
156
|
+
rewardAmount: 2,
|
157
|
+
transactionId: "234567890"
|
158
|
+
}
|
159
|
+
})
|
160
|
+
# Example 3
|
161
|
+
Gameball::Action.send_action({
|
162
|
+
playerUniqueId: "your_player_unique_id",
|
163
|
+
events: {
|
164
|
+
review: {},
|
165
|
+
reserve: {
|
166
|
+
rooms: 2
|
167
|
+
}
|
168
|
+
},
|
169
|
+
pointsTransaction: {
|
170
|
+
rewardAmount: 2,
|
171
|
+
holdReference: "2342452352435234",
|
172
|
+
transactionId: "234567890"
|
173
|
+
}
|
data/gameball.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/gameball/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "gameball"
|
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
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Requiring all dependencies needed
|
2
|
+
require "net/http"
|
3
|
+
require "net/http"
|
4
|
+
require "openssl"
|
5
|
+
require "uri"
|
6
|
+
require "Time"
|
7
|
+
require "digest/sha1"
|
8
|
+
require "json"
|
9
|
+
# Requiring all the other files to help us require this field only
|
10
|
+
require_relative "./gameball/utils/request"
|
11
|
+
require_relative "./gameball/utils/helper"
|
12
|
+
require_relative "./gameball/utils/validation"
|
13
|
+
require_relative "./gameball/models/player"
|
14
|
+
require_relative "./gameball/models/event"
|
15
|
+
require_relative "./gameball/models/transaction"
|
16
|
+
require_relative "./gameball/models/referral"
|
17
|
+
require_relative "./gameball/models/coupon"
|
18
|
+
require_relative "./gameball/models/action"
|
19
|
+
require_relative "./gameball/exceptions/gameballException"
|
20
|
+
|
21
|
+
module Gameball
|
22
|
+
@api_base = "https://api.gameball.co/"
|
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_reader :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
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Gameball
|
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]
|
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
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Gameball
|
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
|
22
|
+
end
|
23
|
+
def self.validate_discount_coupon(body)
|
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)
|
35
|
+
end
|
36
|
+
else
|
37
|
+
return res
|
38
|
+
end
|
39
|
+
end
|
40
|
+
def self.redeem_discount_coupon(body)
|
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)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
return true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Gameball
|
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)
|
13
|
+
end
|
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)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
return true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Gameball
|
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
|
+
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)
|
35
|
+
end
|
36
|
+
else
|
37
|
+
return res
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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
|
+
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)
|
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)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,99 @@
|
|
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
|
+
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
|
18
|
+
|
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
|
+
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)
|
44
|
+
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)
|
60
|
+
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)
|
76
|
+
end
|
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
|
85
|
+
|
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)
|
93
|
+
end
|
94
|
+
else
|
95
|
+
return res
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Gameball
|
2
|
+
module Utils
|
3
|
+
extend self
|
4
|
+
|
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")
|
14
|
+
end
|
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
|
30
|
+
|
31
|
+
body["hash"] = Gameball::Utils::hashBody(playerUniqueId: playerUniqueId, amount: (amount || ""), transactionTime: (transactionTime || ""))
|
32
|
+
body
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Gameball
|
2
|
+
module Utils
|
3
|
+
extend self
|
4
|
+
|
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)
|
11
|
+
|
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
|
17
|
+
|
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
|
37
|
+
|
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)
|
44
|
+
|
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
|
50
|
+
|
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
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Gameball
|
2
|
+
module Utils
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def validate(hash, required, optional) # Method used to validate body parameters by checking optional fields and required fields
|
6
|
+
errors = []
|
7
|
+
# Loop on required fields and throw error if field is not in ruby hash
|
8
|
+
required.each do |val|
|
9
|
+
raise Gameball::GameballError.new("Required key: #{val.to_sym.inspect}") unless hash.has_key?(val.to_sym)
|
10
|
+
end
|
11
|
+
allowed = optional + required
|
12
|
+
# Loop on each field in ruby hash and check if it is allowed
|
13
|
+
hash.each_key do |val|
|
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(", ")}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gameball
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alsouidan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '12.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '12.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- alsouidan@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- bin/console
|
58
|
+
- bin/setup
|
59
|
+
- config.rb
|
60
|
+
- examples.rb
|
61
|
+
- gameball.gemspec
|
62
|
+
- lib/gameball.rb
|
63
|
+
- lib/gameball/exceptions/gameballException.rb
|
64
|
+
- lib/gameball/models/action.rb
|
65
|
+
- lib/gameball/models/coupon.rb
|
66
|
+
- lib/gameball/models/event.rb
|
67
|
+
- lib/gameball/models/player.rb
|
68
|
+
- lib/gameball/models/referral.rb
|
69
|
+
- lib/gameball/models/transaction.rb
|
70
|
+
- lib/gameball/utils/helper.rb
|
71
|
+
- lib/gameball/utils/request.rb
|
72
|
+
- lib/gameball/utils/validation.rb
|
73
|
+
- lib/gameball/version.rb
|
74
|
+
homepage: https://www.gameball.co/
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata:
|
78
|
+
homepage_uri: https://www.gameball.co/
|
79
|
+
source_code_uri: http://mygemserver.com
|
80
|
+
changelog_uri: http://mygemserver.com
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.3.0
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubygems_version: 3.0.3
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Ruby SDK for Gameball's API
|
100
|
+
test_files: []
|