zombie_battleground-api 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0eed5214567ac570ecbdfcbeedc8269cd6ccb7b4b9a1478f319ef27a2e67ba8e
4
- data.tar.gz: 92782a7faa90816774764b2d70f078d0f9e3c2a1d30f1c29253030935900d130
3
+ metadata.gz: 430fd528262b48c3e7957823bb13172e5f88e0055730681347f791317f748c78
4
+ data.tar.gz: 1b8c3e16c7a49bbb8c52844d1365ecdd22dc5e0e30f26b5dc5758642bd57b64a
5
5
  SHA512:
6
- metadata.gz: 4b397cee1af935eb4f24084c325bd96cca10ffbeee7916611446057c88497d52c6d35c8a39648ec5292da05e6eea65c74d1414a9b86dbefe177db43656e13d27
7
- data.tar.gz: '09ee97e39b13d6dd8e52811d9083c619e6e70a78b00514eb2d2b5c940d85b54bb2971d97f260d51e47fe27ac9f4bca193cb839d8220a5caa08b9cb8a009585f1'
6
+ metadata.gz: 0527fe9ff2693c3d9248ae10289cca07cd2f65419e30d3c9e85e7221868996915d48d53c5219cbffba9054d1cad82002f7df962c65379f048ada2e563188156e
7
+ data.tar.gz: 486b8abf7f16a582291e98ec174af67a8a7da4e674f0e9d4faebd8d49d3ebf0a2843b5f3fa2c439847768dd1b1fad9cb90d7c52c2cdac80ddf389e7dd34ca834
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zombie_battleground-api (0.5.0)
4
+ zombie_battleground-api (0.5.1)
5
5
  activerecord
6
6
  faraday
7
7
  json
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.5.0).
29
+ See the [API documentation](https://www.rubydoc.info/gems/zombie_battleground-api/0.5.1).
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.
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'zombie_battleground/api/extensions/cards'
4
+ require 'zombie_battleground/api/extensions/decks'
4
5
 
5
6
  module ZombieBattleground
6
7
  class Api
@@ -8,6 +9,7 @@ module ZombieBattleground
8
9
  # API Extensions
9
10
  module Extensions
10
11
  include ZombieBattleground::Api::Extensions::Cards
12
+ include ZombieBattleground::Api::Extensions::Decks
11
13
  end
12
14
  end
13
15
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zombie_battleground/api/constants'
4
+
5
+ module ZombieBattleground
6
+ class Api
7
+ module Extensions
8
+ ##
9
+ # API Extensions for Decks
10
+ module Decks
11
+ ##
12
+ # Returns an enumerator for all available decks, accepts a block for yields
13
+ #
14
+ # @return [Enumerator]
15
+ #
16
+ # @example Get an enumerator for the decks
17
+ # ZombieBattleground::Api.all_decks
18
+ # # => Enumerator
19
+ #
20
+ # @example Dump all decks as an array
21
+ # ZombieBattleground::Api.all_decks.to_a
22
+ # # => [ZombieBattleground::Api::Models::Deck]
23
+ #
24
+ # @example Return the first deck
25
+ # ZombieBattleground::Api.all_decks.first
26
+ # # => ZombieBattleground::Api::Models::Deck
27
+ #
28
+ # @example Pass it a block
29
+ # ZombieBattleground::Api.all_decks do |deck|
30
+ # do_something_with(deck) if deck.id == 1
31
+ # end
32
+ # # => nil
33
+ #
34
+ # @api public
35
+ def all_decks(**args)
36
+ args.delete(:limit) # query as many as possible
37
+ return enum_for(:all_decks, args) unless block_given?
38
+
39
+ page = 1
40
+
41
+ loop do
42
+ response = @client.decks_request(args.merge(page: page))
43
+ response.decks.each { |deck| yield deck }
44
+
45
+ break if response.decks_count < PAGE_MAX
46
+ # :nocov:
47
+ page += 1
48
+ # :nocov:
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -60,11 +60,23 @@ module ZombieBattleground
60
60
  # @return [Array<ZombieBattleground::Api::Models::Deck>]
61
61
  #
62
62
  # @example
63
- # response.deck #=> [ZombieBattleground::Api::Models::Deck]
63
+ # response.decks #=> [ZombieBattleground::Api::Models::Deck]
64
64
  #
65
65
  # @api public
66
66
  attr_reader :decks
67
67
 
68
+ ##
69
+ # @!attribute [r] decks_count
70
+ # the deck found for the page and limit
71
+ #
72
+ # @return [Integer]
73
+ #
74
+ # @example
75
+ # response.decks_count #=> 1
76
+ #
77
+ # @api public
78
+ attr_reader :decks_count
79
+
68
80
  ##
69
81
  # @!attribute [a] remove_invalid
70
82
  # flag to remove objects in response that are invalid during validation
@@ -99,6 +111,9 @@ module ZombieBattleground
99
111
 
100
112
  JSON.parse(response.body).each do |key, value|
101
113
  if key == 'decks'
114
+ # Keep the API response count, it will differ when invalid decks are stripped
115
+ @decks_count = value.size
116
+
102
117
  instance_variable_set(
103
118
  "@#{key}".to_sym, value.map { |deck| ZombieBattleground::Api::Models::Deck.new(deck) }
104
119
  )
@@ -6,6 +6,6 @@ module ZombieBattleground
6
6
  class Api
7
7
  ##
8
8
  # Verion of the Gem
9
- VERSION = '0.5.0'
9
+ VERSION = '0.5.1'
10
10
  end
11
11
  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.5.0
4
+ version: 0.5.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-16 00:00:00.000000000 Z
11
+ date: 2019-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -248,6 +248,7 @@ files:
248
248
  - lib/zombie_battleground/api/extensions.rb
249
249
  - lib/zombie_battleground/api/extensions/cards.rb
250
250
  - lib/zombie_battleground/api/extensions/cards.yml
251
+ - lib/zombie_battleground/api/extensions/decks.rb
251
252
  - lib/zombie_battleground/api/models/card.rb
252
253
  - lib/zombie_battleground/api/models/deck.rb
253
254
  - lib/zombie_battleground/api/models/match.rb