zombie_battleground-api 0.6.1 → 0.7.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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/zombie_battleground/api/extensions/matches.rb +143 -0
- data/lib/zombie_battleground/api/extensions.rb +2 -0
- data/lib/zombie_battleground/api/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2acaf3416a0f31d86fcff302d3379ed5884176681dcc15e76a98ce5a3747ba42
|
4
|
+
data.tar.gz: f766298c75216df689c2e46f8ec573de5969637d620da1391128f9d3c20ce4ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 611408f4ef29cc8c24ac1c905242361cd9675549d0a8a7606560cb204e689117fd4cd42aae0d04abc9b40abb25d6cbe3c82c2e9924e277fa69a1f7a4c6fef201
|
7
|
+
data.tar.gz: 68d8e0552e801dfc97d8490d08dc50b9832c92596a2f43ed35ab36b8fce1aa22766b57b090f46fd0fba81ae39a121b657587f5df5dd025e572205e1f4e98bddd
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,7 +26,7 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
See the [API documentation](https://www.rubydoc.info/gems/zombie_battleground-api/0.
|
29
|
+
See the [API documentation](https://www.rubydoc.info/gems/zombie_battleground-api/0.7.0).
|
30
30
|
Every API call returns a response object that contains a complete modeled Ruby object of the response.
|
31
31
|
|
32
32
|
Use the singleton class `ZombieBattleground::Api`. The singleton has additional extentions, the client implements the public API as is.
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
require 'zombie_battleground/api/constants'
|
6
|
+
|
7
|
+
module ZombieBattleground
|
8
|
+
class Api
|
9
|
+
module Extensions
|
10
|
+
##
|
11
|
+
# API Extensions for Matches
|
12
|
+
module Matches
|
13
|
+
##
|
14
|
+
# Returns an enumerator for all available matches, accepts a block for yields
|
15
|
+
#
|
16
|
+
# @return [Enumerator]
|
17
|
+
#
|
18
|
+
# @example Get an enumerator for the matches
|
19
|
+
# ZombieBattleground::Api.all_matches
|
20
|
+
# # => Enumerator
|
21
|
+
#
|
22
|
+
# @example Dump all matches as an array
|
23
|
+
# ZombieBattleground::Api.all_matches.to_a
|
24
|
+
# # => [ZombieBattleground::Api::Models::Match]
|
25
|
+
#
|
26
|
+
# @example Return the first matche
|
27
|
+
# ZombieBattleground::Api.all_matches.first
|
28
|
+
# # => ZombieBattleground::Api::Models::Match
|
29
|
+
#
|
30
|
+
# @example Pass it a block
|
31
|
+
# ZombieBattleground::Api.all_matches do |match|
|
32
|
+
# do_something_with(match) if match.id == 1
|
33
|
+
# end
|
34
|
+
# # => nil
|
35
|
+
#
|
36
|
+
# @api public
|
37
|
+
def all_matches(**args)
|
38
|
+
args.delete(:limit) # query as many as possible
|
39
|
+
return enum_for(:all_matches, args) unless block_given?
|
40
|
+
|
41
|
+
page = 1
|
42
|
+
|
43
|
+
loop do
|
44
|
+
response = @client.matches_request(args.merge(page: page))
|
45
|
+
response.matches.each { |match| yield match }
|
46
|
+
|
47
|
+
break if response.matches.size < PAGE_MAX
|
48
|
+
# :nocov:
|
49
|
+
page += 1
|
50
|
+
# :nocov:
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Returns the most recently created matches
|
56
|
+
#
|
57
|
+
# @param limit [Integer]
|
58
|
+
#
|
59
|
+
# @return [Array<ZombieBattleground::Api::Models::Match>]
|
60
|
+
#
|
61
|
+
# @example
|
62
|
+
# two_most_recent = ZombieBattleground::Api.recently_created_matches(3)
|
63
|
+
# # => [ZombieBattleground::Api::Models::Match]
|
64
|
+
#
|
65
|
+
# @api public
|
66
|
+
def recently_created_matches(limit)
|
67
|
+
# the `.sort` calls are dodging coverage?...
|
68
|
+
# :nocov:
|
69
|
+
all_matches.to_a
|
70
|
+
.sort { |a, b| b.created_at <=> a.created_at }
|
71
|
+
.first(limit)
|
72
|
+
# :nocov:
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Returns the most recently updated matches
|
77
|
+
#
|
78
|
+
# @param limit [Integer]
|
79
|
+
#
|
80
|
+
# @return [Array<ZombieBattleground::Api::Models::Match>]
|
81
|
+
#
|
82
|
+
# @example
|
83
|
+
# two_most_recent = ZombieBattleground::Api.recently_updated_matches(3)
|
84
|
+
# # => [ZombieBattleground::Api::Models::Match]
|
85
|
+
#
|
86
|
+
# @api public
|
87
|
+
def recently_updated_matches(limit)
|
88
|
+
# the `.sort` calls are dodging coverage?...
|
89
|
+
# :nocov:
|
90
|
+
all_matches.to_a
|
91
|
+
.sort { |a, b| b.updated_at <=> a.updated_at }
|
92
|
+
.first(limit)
|
93
|
+
# :nocov:
|
94
|
+
end
|
95
|
+
|
96
|
+
##
|
97
|
+
# Returns the most recently ended matches
|
98
|
+
#
|
99
|
+
# @param limit [Integer]
|
100
|
+
#
|
101
|
+
# @return [Array<ZombieBattleground::Api::Models::Match>]
|
102
|
+
#
|
103
|
+
# @example
|
104
|
+
# two_most_recent = ZombieBattleground::Api.recently_ended_matches(3)
|
105
|
+
# # => [ZombieBattleground::Api::Models::Match]
|
106
|
+
#
|
107
|
+
# @api public
|
108
|
+
def recently_ended_matches(limit)
|
109
|
+
# the `.sort` calls are dodging coverage?...
|
110
|
+
# :nocov:
|
111
|
+
all_matches.to_a
|
112
|
+
.select { |match| match.status == 'Ended' }
|
113
|
+
.sort { |a, b| b.ended_at <=> a.ended_at }
|
114
|
+
.first(limit)
|
115
|
+
# :nocov:
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# Returns the matches for the player_id
|
120
|
+
#
|
121
|
+
# @param player_id [String]
|
122
|
+
#
|
123
|
+
# @return [Array<ZombieBattleground::Api::Models::Match>]
|
124
|
+
#
|
125
|
+
# @example
|
126
|
+
# player_matches = ZombieBattleground::Api.matches_for_player("ZombieSlayer_5699")
|
127
|
+
# # => [ZombieBattleground::Api::Models::Match]
|
128
|
+
#
|
129
|
+
# @api public
|
130
|
+
def matches_for_player(player_id)
|
131
|
+
# the `.sort` calls are dodging coverage?...
|
132
|
+
# :nocov:
|
133
|
+
all_matches(player1_id: player_id)
|
134
|
+
.to_a
|
135
|
+
.push(*all_matches(player2_id: player_id).to_a)
|
136
|
+
.uniq(&:id)
|
137
|
+
.sort { |a, b| b.created_at <=> a.created_at }
|
138
|
+
# :nocov:
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'zombie_battleground/api/extensions/cards'
|
4
4
|
require 'zombie_battleground/api/extensions/decks'
|
5
|
+
require 'zombie_battleground/api/extensions/matches'
|
5
6
|
|
6
7
|
module ZombieBattleground
|
7
8
|
class Api
|
@@ -10,6 +11,7 @@ module ZombieBattleground
|
|
10
11
|
module Extensions
|
11
12
|
include ZombieBattleground::Api::Extensions::Cards
|
12
13
|
include ZombieBattleground::Api::Extensions::Decks
|
14
|
+
include ZombieBattleground::Api::Extensions::Matches
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zombie_battleground-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Shields
|
@@ -250,6 +250,7 @@ files:
|
|
250
250
|
- lib/zombie_battleground/api/extensions/cards.yml
|
251
251
|
- lib/zombie_battleground/api/extensions/decks.rb
|
252
252
|
- lib/zombie_battleground/api/extensions/decks.yml
|
253
|
+
- lib/zombie_battleground/api/extensions/matches.rb
|
253
254
|
- lib/zombie_battleground/api/models/card.rb
|
254
255
|
- lib/zombie_battleground/api/models/deck.rb
|
255
256
|
- lib/zombie_battleground/api/models/match.rb
|