zombie_battleground-api 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/Gemfile.lock +29 -11
- data/README.md +4 -0
- data/Rakefile +62 -5
- data/lib/zombie_battleground/api.rb +108 -8
- data/lib/zombie_battleground/api/client.rb +157 -23
- data/lib/zombie_battleground/api/errors.rb +28 -0
- data/lib/zombie_battleground/api/models/card.rb +272 -32
- data/lib/zombie_battleground/api/models/deck.rb +234 -46
- data/lib/zombie_battleground/api/models/match.rb +211 -33
- data/lib/zombie_battleground/api/models/simple_card.rb +47 -11
- data/lib/zombie_battleground/api/requests/get_card_request.rb +45 -10
- data/lib/zombie_battleground/api/requests/get_cards_request.rb +203 -27
- data/lib/zombie_battleground/api/requests/get_deck_request.rb +43 -13
- data/lib/zombie_battleground/api/requests/get_decks_request.rb +141 -23
- data/lib/zombie_battleground/api/requests/get_match_request.rb +43 -13
- data/lib/zombie_battleground/api/requests/get_matches_request.rb +125 -21
- data/lib/zombie_battleground/api/requests/request_helper.rb +24 -10
- data/lib/zombie_battleground/api/responses/get_card_response.rb +50 -16
- data/lib/zombie_battleground/api/responses/get_cards_response.rb +103 -33
- data/lib/zombie_battleground/api/responses/get_deck_response.rb +49 -17
- data/lib/zombie_battleground/api/responses/get_decks_response.rb +103 -33
- data/lib/zombie_battleground/api/responses/get_match_response.rb +49 -17
- data/lib/zombie_battleground/api/responses/get_matches_response.rb +103 -33
- data/lib/zombie_battleground/api/responses/response_helper.rb +32 -16
- data/lib/zombie_battleground/api/validation_helper.rb +497 -0
- data/lib/zombie_battleground/api/version.rb +5 -1
- data/zombie_battleground-api.gemspec +6 -0
- metadata +71 -1
@@ -6,39 +6,217 @@ require 'zombie_battleground/api/validation_helper'
|
|
6
6
|
|
7
7
|
module ZombieBattleground
|
8
8
|
class Api
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
match.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
9
|
+
class Models
|
10
|
+
##
|
11
|
+
# Validator for Match
|
12
|
+
class Match
|
13
|
+
include ActiveModel::Validations
|
14
|
+
include ZombieBattleground::Api::ValidationHelper
|
15
|
+
|
16
|
+
##
|
17
|
+
# @!attribute [r] id
|
18
|
+
# the Match's id
|
19
|
+
#
|
20
|
+
# @return [Integer]
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
# match.id #=> 1
|
24
|
+
#
|
25
|
+
# @api public
|
26
|
+
attr_reader :id
|
27
|
+
|
28
|
+
##
|
29
|
+
# @!attribute [r] created_at
|
30
|
+
# the Match's created_at time
|
31
|
+
#
|
32
|
+
# @return [Time]
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# match.created_at #=> Time
|
36
|
+
#
|
37
|
+
# @api public
|
38
|
+
attr_reader :created_at
|
39
|
+
|
40
|
+
##
|
41
|
+
# @!attribute [r] updated_at
|
42
|
+
# the Match's updated_at time
|
43
|
+
#
|
44
|
+
# @return [Time]
|
45
|
+
#
|
46
|
+
# @example
|
47
|
+
# match.updated_at #=> Time
|
48
|
+
#
|
49
|
+
# @api public
|
50
|
+
attr_reader :updated_at
|
51
|
+
|
52
|
+
##
|
53
|
+
# @!attribute [r] player1_id
|
54
|
+
# the Match's player1_id
|
55
|
+
#
|
56
|
+
# @return [String]
|
57
|
+
#
|
58
|
+
# @example
|
59
|
+
# match.player1_id #=> "ZombieSlayer_16601"
|
60
|
+
#
|
61
|
+
# @api public
|
62
|
+
attr_reader :player1_id
|
63
|
+
|
64
|
+
##
|
65
|
+
# @!attribute [r] player2_id
|
66
|
+
# the Match's player2_id
|
67
|
+
#
|
68
|
+
# @return [String]
|
69
|
+
#
|
70
|
+
# @example
|
71
|
+
# match.player2_id #=> "ZombieSlayer_50758"
|
72
|
+
#
|
73
|
+
# @api public
|
74
|
+
attr_reader :player2_id
|
75
|
+
|
76
|
+
##
|
77
|
+
# @!attribute [r] player1_accepted
|
78
|
+
# the Match's player1_accepted
|
79
|
+
#
|
80
|
+
# @return [Boolean]
|
81
|
+
#
|
82
|
+
# @example
|
83
|
+
# match.player1_accepted #=> true
|
84
|
+
#
|
85
|
+
# @api public
|
86
|
+
attr_reader :player1_accepted
|
87
|
+
|
88
|
+
##
|
89
|
+
# @!attribute [r] player2_accepted
|
90
|
+
# the Match's player2_accepted
|
91
|
+
#
|
92
|
+
# @return [Boolean]
|
93
|
+
#
|
94
|
+
# @example
|
95
|
+
# match.player2_accepted #=> true
|
96
|
+
#
|
97
|
+
# @api public
|
98
|
+
attr_reader :player2_accepted
|
99
|
+
|
100
|
+
##
|
101
|
+
# @!attribute [r] player1_deck_id
|
102
|
+
# the Match's player1_deck_id
|
103
|
+
#
|
104
|
+
# @return [Integer]
|
105
|
+
#
|
106
|
+
# @example
|
107
|
+
# match.player1_deck_id #=> 1
|
108
|
+
#
|
109
|
+
# @api public
|
110
|
+
attr_reader :player1_deck_id
|
111
|
+
|
112
|
+
##
|
113
|
+
# @!attribute [r] player2_deck_id
|
114
|
+
# the Match's player2_deck_id
|
115
|
+
#
|
116
|
+
# @return [Integer]
|
117
|
+
#
|
118
|
+
# @example
|
119
|
+
# match.player2_deck_id #=> 4
|
120
|
+
#
|
121
|
+
# @api public
|
122
|
+
attr_reader :player2_deck_id
|
123
|
+
|
124
|
+
##
|
125
|
+
# @!attribute [r] status
|
126
|
+
# the Match's status
|
127
|
+
#
|
128
|
+
# @return [String]
|
129
|
+
#
|
130
|
+
# @example
|
131
|
+
# match.status #=> "Ended"
|
132
|
+
#
|
133
|
+
# @api public
|
134
|
+
attr_reader :status
|
135
|
+
|
136
|
+
##
|
137
|
+
# @!attribute [r] version
|
138
|
+
# the Match's version
|
139
|
+
#
|
140
|
+
# @return [String]
|
141
|
+
#
|
142
|
+
# @example
|
143
|
+
# match.version #=> "v3"
|
144
|
+
#
|
145
|
+
# @api public
|
146
|
+
attr_reader :version
|
147
|
+
|
148
|
+
##
|
149
|
+
# @!attribute [r] random_seed
|
150
|
+
# the Match's random_seed
|
151
|
+
#
|
152
|
+
# @return [Integer]
|
153
|
+
#
|
154
|
+
# @example
|
155
|
+
# match.random_seed #=> 1548242486
|
156
|
+
#
|
157
|
+
# @api public
|
158
|
+
attr_reader :random_seed
|
159
|
+
|
160
|
+
##
|
161
|
+
# @!attribute [r] winner_id
|
162
|
+
# the Match's winner_id
|
163
|
+
#
|
164
|
+
# @return [String]
|
165
|
+
#
|
166
|
+
# @example
|
167
|
+
# match.winner_id #=> "ZombieSlayer_507586"
|
168
|
+
#
|
169
|
+
# @api public
|
170
|
+
attr_reader :winner_id
|
171
|
+
|
172
|
+
##
|
173
|
+
# @!attribute [r] block_height
|
174
|
+
# the Match's block_height
|
175
|
+
#
|
176
|
+
# @return [Integer]
|
177
|
+
#
|
178
|
+
# @example
|
179
|
+
# match.block_height #=> 497513
|
180
|
+
#
|
181
|
+
# @api public
|
182
|
+
attr_reader :block_height
|
183
|
+
|
184
|
+
validate :id_is_a_non_negative_integer
|
185
|
+
validate :created_at_is_a_time_and_not_null
|
186
|
+
validate :updated_at_is_a_time_and_not_null
|
187
|
+
validate :player1_id_is_a_string_and_not_null
|
188
|
+
validate :player2_id_is_a_string_and_not_null
|
189
|
+
validates :player1_accepted, inclusion: { in: [true, false] }
|
190
|
+
validates :player2_accepted, inclusion: { in: [true, false] }
|
191
|
+
validate :player1_deck_id_is_a_non_negative_integer
|
192
|
+
validate :player2_deck_id_is_a_non_negative_integer
|
193
|
+
validate :status_is_a_string_and_not_null
|
194
|
+
validate :version_is_a_string_and_not_null
|
195
|
+
validate :random_seed_is_a_non_negative_integer
|
196
|
+
validate :winner_id_is_a_string_and_not_null
|
197
|
+
validate :block_height_is_a_non_negative_integer_and_not_null
|
198
|
+
|
199
|
+
##
|
200
|
+
# Creates a new Match
|
201
|
+
#
|
202
|
+
# @param match [Hash] Parsed JSON response
|
203
|
+
#
|
204
|
+
# @return [ZombieBattleground::Api::Match]
|
205
|
+
#
|
206
|
+
# @example
|
207
|
+
# match = ZombieBattleground::Api::Match.new(parsed_json)
|
208
|
+
# # => ZombieBattleground::Api::Match
|
209
|
+
#
|
210
|
+
# @api public
|
211
|
+
def initialize(match)
|
212
|
+
match.each do |key, value|
|
213
|
+
next if value.nil? # this is an illegal response, match id 1 is bogus
|
214
|
+
|
215
|
+
if %w[created_at updated_at].include?(key)
|
216
|
+
instance_variable_set("@#{key}".to_sym, Time.parse(value))
|
217
|
+
else
|
218
|
+
instance_variable_set("@#{key}".to_sym, value)
|
219
|
+
end
|
42
220
|
end
|
43
221
|
end
|
44
222
|
end
|
@@ -6,20 +6,56 @@ require 'zombie_battleground/api/validation_helper'
|
|
6
6
|
|
7
7
|
module ZombieBattleground
|
8
8
|
class Api
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
class Models
|
10
|
+
##
|
11
|
+
# Validator for SimpleCard (only returned from GetDeck(s))
|
12
|
+
class SimpleCard
|
13
|
+
include ActiveModel::Validations
|
14
|
+
include ZombieBattleground::Api::ValidationHelper
|
14
15
|
|
15
|
-
|
16
|
+
##
|
17
|
+
# @!attribute [r] card_name
|
18
|
+
# the Card's name
|
19
|
+
#
|
20
|
+
# @return [String]
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
# simple_card.card_name #=> "Hazmaz"
|
24
|
+
#
|
25
|
+
# @api public
|
26
|
+
attr_reader :card_name
|
16
27
|
|
17
|
-
|
18
|
-
|
28
|
+
##
|
29
|
+
# @!attribute [r] amount
|
30
|
+
# the amount of the Card in the deck
|
31
|
+
#
|
32
|
+
# @return [Integer]
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# simple_card.amount #=> 2
|
36
|
+
#
|
37
|
+
# @api public
|
38
|
+
attr_reader :amount
|
19
39
|
|
20
|
-
|
21
|
-
|
22
|
-
|
40
|
+
validate :card_name_is_a_string_and_not_null
|
41
|
+
validate :amount_is_a_non_negative_integer_and_not_null
|
42
|
+
|
43
|
+
##
|
44
|
+
# Creates a new SimpleCard (returned by GetDeck(s))
|
45
|
+
#
|
46
|
+
# @param card [Hash] Parsed JSON response
|
47
|
+
#
|
48
|
+
# @return [ZombieBattleground::Api::SimpleCard]
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
# simple_card = ZombieBattleground::Api::SimpleCard.new(parsed_json)
|
52
|
+
# # => ZombieBattleground::Api::SimpleCard
|
53
|
+
#
|
54
|
+
# @api public
|
55
|
+
def initialize(card)
|
56
|
+
card.each do |key, value|
|
57
|
+
instance_variable_set("@#{key}".to_sym, value)
|
58
|
+
end
|
23
59
|
end
|
24
60
|
end
|
25
61
|
end
|
@@ -8,19 +8,54 @@ require 'zombie_battleground/api/requests/request_helper'
|
|
8
8
|
module ZombieBattleground
|
9
9
|
class Api
|
10
10
|
##
|
11
|
-
#
|
12
|
-
class
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
# Namespace for Requests
|
12
|
+
class Requests
|
13
|
+
##
|
14
|
+
# Request validator for GetCard
|
15
|
+
class GetCardRequest
|
16
|
+
include ActiveModel::Validations
|
17
|
+
include ZombieBattleground::Api::ValidationHelper
|
18
|
+
include ZombieBattleground::Api::Requests::RequestHelper
|
16
19
|
|
17
|
-
|
20
|
+
##
|
21
|
+
# @!attribute [r] mould_id
|
22
|
+
# Card's mould_id
|
23
|
+
#
|
24
|
+
# @return [String]
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# request.id #=> "1"
|
28
|
+
#
|
29
|
+
# @api public
|
30
|
+
attr_accessor :mould_id
|
18
31
|
|
19
|
-
|
20
|
-
|
32
|
+
##
|
33
|
+
# @!attribute [r] version
|
34
|
+
# Deck's version
|
35
|
+
#
|
36
|
+
# @return [String]
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# request.id #=> "v3"
|
40
|
+
#
|
41
|
+
# @api public
|
42
|
+
attr_accessor :version
|
21
43
|
|
22
|
-
|
23
|
-
|
44
|
+
validate :mould_id_is_a_string_and_not_null
|
45
|
+
validate :version_is_a_string_and_not_null
|
46
|
+
|
47
|
+
##
|
48
|
+
# The URI for the endpoint
|
49
|
+
#
|
50
|
+
# @return [String]
|
51
|
+
#
|
52
|
+
# @example
|
53
|
+
# request.uri # => "card"
|
54
|
+
#
|
55
|
+
# @api public
|
56
|
+
def uri
|
57
|
+
'card'
|
58
|
+
end
|
24
59
|
end
|
25
60
|
end
|
26
61
|
end
|
@@ -7,33 +7,209 @@ require 'zombie_battleground/api/requests/request_helper'
|
|
7
7
|
|
8
8
|
module ZombieBattleground
|
9
9
|
class Api
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
10
|
+
class Requests
|
11
|
+
##
|
12
|
+
# Request validator for GetCards
|
13
|
+
class GetCardsRequest
|
14
|
+
include ActiveModel::Validations
|
15
|
+
include ZombieBattleground::Api::ValidationHelper
|
16
|
+
include ZombieBattleground::Api::Requests::RequestHelper
|
17
|
+
|
18
|
+
##
|
19
|
+
# @!attribute [r] id
|
20
|
+
# Optionally set the Card's id for filtered querying
|
21
|
+
#
|
22
|
+
# @return [Integer]
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# request.id #=> 1
|
26
|
+
#
|
27
|
+
# @api public
|
28
|
+
attr_accessor :id
|
29
|
+
|
30
|
+
##
|
31
|
+
# @!attribute [r] mould_id
|
32
|
+
# Optionally mould_id the Card's mould_id for filtered querying
|
33
|
+
#
|
34
|
+
# @return [String]
|
35
|
+
#
|
36
|
+
# @example
|
37
|
+
# request.mould_id #=> "1"
|
38
|
+
#
|
39
|
+
# @api public
|
40
|
+
attr_accessor :mould_id
|
41
|
+
|
42
|
+
##
|
43
|
+
# @!attribute [r] version
|
44
|
+
# Optionally version the Card's version for filtered querying
|
45
|
+
#
|
46
|
+
# @return [String]
|
47
|
+
#
|
48
|
+
# @example
|
49
|
+
# request.version #=> "v3"
|
50
|
+
#
|
51
|
+
# @api public
|
52
|
+
attr_accessor :version
|
53
|
+
|
54
|
+
##
|
55
|
+
# @!attribute [r] set
|
56
|
+
# Optionally set the Card's set for filtered querying
|
57
|
+
#
|
58
|
+
# @return [String]
|
59
|
+
#
|
60
|
+
# @example
|
61
|
+
# request.set #=> "AIR"
|
62
|
+
#
|
63
|
+
# @api public
|
64
|
+
attr_accessor :kind
|
65
|
+
|
66
|
+
##
|
67
|
+
# @!attribute [r] set
|
68
|
+
# Optionally set the Card's set for filtered querying
|
69
|
+
#
|
70
|
+
# @return [String]
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# request.set #=> "AIR"
|
74
|
+
#
|
75
|
+
# @api public
|
76
|
+
attr_accessor :set
|
77
|
+
|
78
|
+
##
|
79
|
+
# @!attribute [r] name
|
80
|
+
# Optionally set the Card's name for filtered querying
|
81
|
+
#
|
82
|
+
# @return [String]
|
83
|
+
#
|
84
|
+
# @example
|
85
|
+
# request.name #=> "Whizpar"
|
86
|
+
#
|
87
|
+
# @api public
|
88
|
+
attr_accessor :name
|
89
|
+
|
90
|
+
##
|
91
|
+
# @!attribute [r] rank
|
92
|
+
# Optionally set the Card's rank for filtered querying
|
93
|
+
#
|
94
|
+
# @return [String]
|
95
|
+
#
|
96
|
+
# @example
|
97
|
+
# request.rank #=> "MINION"
|
98
|
+
#
|
99
|
+
# @api public
|
100
|
+
attr_accessor :rank
|
101
|
+
|
102
|
+
##
|
103
|
+
# @!attribute [r] type
|
104
|
+
# Optionally set the Card's type for filtered querying
|
105
|
+
#
|
106
|
+
# @return [String]
|
107
|
+
#
|
108
|
+
# @example
|
109
|
+
# request.type #=> "WALKER"
|
110
|
+
#
|
111
|
+
# @api public
|
112
|
+
attr_accessor :type
|
113
|
+
|
114
|
+
##
|
115
|
+
# @!attribute [r] rarity
|
116
|
+
# Optionally set the Card's rarity for filtered querying
|
117
|
+
#
|
118
|
+
# @return [String]
|
119
|
+
#
|
120
|
+
# @example
|
121
|
+
# request.rarity #=> ""
|
122
|
+
#
|
123
|
+
# @api public
|
124
|
+
attr_accessor :rarity
|
125
|
+
|
126
|
+
##
|
127
|
+
# @!attribute [r] damage
|
128
|
+
# Optionally set the Card's damage for filtered querying
|
129
|
+
#
|
130
|
+
# @return [Integer]
|
131
|
+
#
|
132
|
+
# @example
|
133
|
+
# request.damage #=> 1
|
134
|
+
#
|
135
|
+
# @api public
|
136
|
+
attr_accessor :damage
|
137
|
+
|
138
|
+
##
|
139
|
+
# @!attribute [r] health
|
140
|
+
# Optionally set the Card's health for filtered querying
|
141
|
+
#
|
142
|
+
# @return [Integer]
|
143
|
+
#
|
144
|
+
# @example
|
145
|
+
# request.health #=> 1
|
146
|
+
#
|
147
|
+
# @api public
|
148
|
+
attr_accessor :health
|
149
|
+
|
150
|
+
##
|
151
|
+
# @!attribute [r] cost
|
152
|
+
# Optionally set the Card's cost for filtered querying
|
153
|
+
#
|
154
|
+
# @return [Integer]
|
155
|
+
#
|
156
|
+
# @example
|
157
|
+
# request.cost #=> 1
|
158
|
+
#
|
159
|
+
# @api public
|
160
|
+
attr_accessor :cost
|
161
|
+
|
162
|
+
##
|
163
|
+
# @!attribute [r] page
|
164
|
+
# Optionally set the page number for filtered querying
|
165
|
+
#
|
166
|
+
# @return [Integer]
|
167
|
+
#
|
168
|
+
# @example
|
169
|
+
# request.page #=> 1
|
170
|
+
#
|
171
|
+
# @api public
|
172
|
+
attr_accessor :page
|
173
|
+
|
174
|
+
##
|
175
|
+
# @!attribute [r] limit
|
176
|
+
# Optionally set the limit for max Cards returned
|
177
|
+
#
|
178
|
+
# @return [Integer]
|
179
|
+
#
|
180
|
+
# @example
|
181
|
+
# request.limit #=> 100
|
182
|
+
#
|
183
|
+
# @api public
|
184
|
+
attr_accessor :limit
|
185
|
+
|
186
|
+
validate :id_is_a_non_negative_integer
|
187
|
+
validate :mould_id_is_a_string
|
188
|
+
validate :version_is_a_string
|
189
|
+
validate :kind_is_a_string
|
190
|
+
validate :set_is_a_string
|
191
|
+
validate :name_is_a_string
|
192
|
+
validate :rank_is_a_string
|
193
|
+
validate :type_is_a_string
|
194
|
+
validate :rarity_is_a_string
|
195
|
+
validate :damage_is_a_non_negative_integer
|
196
|
+
validate :health_is_a_non_negative_integer
|
197
|
+
validate :cost_is_a_non_negative_integer
|
198
|
+
validate :page_is_a_non_negative_integer
|
199
|
+
validate :limit_is_a_non_negative_integer
|
200
|
+
|
201
|
+
##
|
202
|
+
# The URI for the endpoint
|
203
|
+
#
|
204
|
+
# @return [String]
|
205
|
+
#
|
206
|
+
# @example
|
207
|
+
# request.uri # => "cards"
|
208
|
+
#
|
209
|
+
# @api public
|
210
|
+
def uri
|
211
|
+
'cards'
|
212
|
+
end
|
37
213
|
end
|
38
214
|
end
|
39
215
|
end
|