zombie_battleground-api 0.4.0 → 0.4.1

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: 61f183b1671a060cdcd4d32e604ecd8518691d1c160d6158a862a8c82a61c0ab
4
- data.tar.gz: 38b45a305a6d3b7027165d5d46f607c26b2e4b224db45a45f8c0e0aeb79c9676
3
+ metadata.gz: 11df9750d399535b01b26d87d68a25297f330f51dd0e347d31d1c0dbda43a032
4
+ data.tar.gz: 0c293f96164be6fe65eb072e56d7ff23d616d8e7f4d421a3e182cec36319ddaa
5
5
  SHA512:
6
- metadata.gz: 776bc9c496ec436ef5f8a94ef94fbd69f17783fbfc3fb20066d42dd23eec3d0b2cf80dc20f17bbb973ebe2d84047bd8730afb5632b181316bedc26169264805d
7
- data.tar.gz: 236108055ed121d07da4073bd54870b934b066e4ac49581920d9a45a3a103a4d2912c3b6380c4b39117862dc97962bf30da7260eda358ff14d511d8ab50545bd
6
+ metadata.gz: 727b93807b5a4ff030c2cb9877a38390a1c6dccb2b4a0a322348502fb9284fbaf593f1f3ee64e59ad7fd203d70ca41843c1e8f6974e9f49bc6ba67fdf153b663
7
+ data.tar.gz: 0f50bf8ea5c3af8523941303405486d23851c7e4b0f72c4d346a4f8d5f72afb199e78aacf63ff492597dfa88a5fc3edc2f1eab115ef9c07748a1305f55def3c2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zombie_battleground-api (0.4.0)
4
+ zombie_battleground-api (0.4.1)
5
5
  activerecord
6
6
  faraday
7
7
  json
data/README.md CHANGED
@@ -26,10 +26,10 @@ 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.4.0).
29
+ See the [API documentation](https://www.rubydoc.info/gems/zombie_battleground-api/0.4.1).
30
30
  Every API call returns a response object that contains a complete modeled Ruby object of the response.
31
31
 
32
- Use the singleton class `ZombieBattleground::Api`
32
+ Use the singleton class `ZombieBattleground::Api`. The singleton has additional extentions, the client implements the public API as is.
33
33
 
34
34
  ```ruby
35
35
  require 'zombie_battleground/api'
@@ -50,9 +50,6 @@ client = ZombieBattleground::Api::Client.new
50
50
 
51
51
  client.decks_request(limit: 1)
52
52
  # => ZombieBattleground::Api::Responses::GetDecksResponse
53
-
54
- client.decks(limit: 1)
55
- # => [ZombieBattleground::Api::Models::Decks]
56
53
  ```
57
54
 
58
55
  ## Development
@@ -4,46 +4,59 @@ require 'zombie_battleground/api/constants'
4
4
 
5
5
  module ZombieBattleground
6
6
  class Api
7
- ##
8
- # API Extensions
9
7
  module Extensions
10
8
  ##
11
9
  # API Extensions for Cards
12
10
  module Cards
13
11
  ##
14
- # Fetches all available cards
12
+ # Returns an enumerator for all available cards, accepts a block for yields
15
13
  #
16
- # @return [Array<ZombieBattleground::Api::Models::Card>]
14
+ # @return [Enumerator]
17
15
  #
18
- # @example
19
- # cards = ZombieBattleground::Api.all_cards
16
+ # @example Get an enumerator for the cards
17
+ # ZombieBattleground::Api.all_cards
18
+ # # => Enumerator
19
+ #
20
+ # @example Dump all cards as an array
21
+ # ZombieBattleground::Api.all_cards.to_a
20
22
  # # => [ZombieBattleground::Api::Models::Card]
21
23
  #
24
+ # @example Return the first card
25
+ # ZombieBattleground::Api.all_cards.first
26
+ # # => ZombieBattleground::Api::Models::Card
27
+ #
28
+ # @example Pass it a block
29
+ # ZombieBattleground::Api.all_cards do |card|
30
+ # do_something_with(card) if card.mould_id == "1" && card.version == "v3"
31
+ # end
32
+ # # => nil
33
+ #
22
34
  # @api public
23
35
  def all_cards(**args)
36
+ args.delete(:limit) # query as many as possible
37
+ return enum_for(:all_cards) unless block_given?
38
+
24
39
  page = 1
25
- cards = []
26
40
 
27
41
  loop do
28
42
  response = @client.cards_request(args.merge(page: page))
29
- cards.push(*response.cards)
43
+ response.cards.each { |card| yield card }
44
+
30
45
  break if response.cards.size < PAGE_MAX
31
46
  # :nocov:
32
47
  page += 1
33
48
  # :nocov:
34
49
  end
35
-
36
- cards
37
50
  end
38
51
 
39
52
  ##
40
- # Fetches all available cards
53
+ # Fetches all card kinds
41
54
  #
42
- # @return [Array<ZombieBattleground::Api::Models::Card>]
55
+ # @return [Array<String>]
43
56
  #
44
57
  # @example
45
- # cards = ZombieBattleground::Api.all_cards
46
- # # => [ZombieBattleground::Api::Models::Card]
58
+ # cards = ZombieBattleground::Api.card_kinds
59
+ # # => [String]
47
60
  #
48
61
  # @api public
49
62
  def card_kinds
@@ -119,7 +132,7 @@ module ZombieBattleground
119
132
  #
120
133
  # @api public
121
134
  def cards_by_kind(kind:)
122
- all_cards(kind: kind)
135
+ all_cards(kind: kind).to_a
123
136
  end
124
137
 
125
138
  ##
@@ -135,7 +148,7 @@ module ZombieBattleground
135
148
  #
136
149
  # @api public
137
150
  def cards_by_rank(rank:)
138
- all_cards(rank: rank)
151
+ all_cards(rank: rank).to_a
139
152
  end
140
153
 
141
154
  ##
@@ -151,7 +164,7 @@ module ZombieBattleground
151
164
  #
152
165
  # @api public
153
166
  def cards_by_set(set:)
154
- all_cards(set: set)
167
+ all_cards(set: set).to_a
155
168
  end
156
169
 
157
170
  ##
@@ -167,7 +180,7 @@ module ZombieBattleground
167
180
  #
168
181
  # @api public
169
182
  def cards_by_type(type:)
170
- all_cards(type: type)
183
+ all_cards(type: type).to_a
171
184
  end
172
185
 
173
186
  ##
@@ -183,7 +196,7 @@ module ZombieBattleground
183
196
  #
184
197
  # @api public
185
198
  def cards_by_rarity(rarity:)
186
- all_cards(rarity: rarity)
199
+ all_cards(rarity: rarity).to_a
187
200
  end
188
201
  end
189
202
  end
@@ -6,6 +6,6 @@ module ZombieBattleground
6
6
  class Api
7
7
  ##
8
8
  # Verion of the Gem
9
- VERSION = '0.4.0'
9
+ VERSION = '0.4.1'
10
10
  end
11
11
  end
@@ -59,7 +59,7 @@ module ZombieBattleground
59
59
  #
60
60
  # @api public
61
61
  def decks(**args)
62
- @client.decks_request(**args).decks
62
+ decks_request(**args).decks
63
63
  end
64
64
 
65
65
  ##
@@ -91,7 +91,7 @@ module ZombieBattleground
91
91
  #
92
92
  # @api public
93
93
  def deck(**args)
94
- @client.deck_request(**args).deck
94
+ deck_request(**args).deck
95
95
  end
96
96
 
97
97
  ##
@@ -137,7 +137,7 @@ module ZombieBattleground
137
137
  #
138
138
  # @api public
139
139
  def matches(**args)
140
- @client.matches_request(**args).matches
140
+ matches_request(**args).matches
141
141
  end
142
142
 
143
143
  ##
@@ -169,7 +169,7 @@ module ZombieBattleground
169
169
  #
170
170
  # @api public
171
171
  def match(**args)
172
- @client.match_request(**args).match
172
+ match_request(**args).match
173
173
  end
174
174
 
175
175
  ##
@@ -227,7 +227,7 @@ module ZombieBattleground
227
227
  #
228
228
  # @api public
229
229
  def cards(**args)
230
- @client.cards_request(**args).cards
230
+ cards_request(**args).cards
231
231
  end
232
232
 
233
233
  ##
@@ -261,7 +261,7 @@ module ZombieBattleground
261
261
  #
262
262
  # @api public
263
263
  def card(**args)
264
- @client.card_request(**args).card
264
+ card_request(**args).card
265
265
  end
266
266
  end
267
267
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zombie_battleground-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Shields
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-15 00:00:00.000000000 Z
11
+ date: 2019-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -236,7 +236,6 @@ files:
236
236
  - Gemfile
237
237
  - Gemfile.lock
238
238
  - LICENSE
239
- - LICENSE.txt
240
239
  - README.md
241
240
  - Rakefile
242
241
  - bin/console
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2019 John Shields
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.