zombie_battleground-api 0.3.0 → 0.4.0

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: 34fc43e2507e55e1951d7129ce11c504c7e27062a6c0c2157dcc5d05a9519ebe
4
- data.tar.gz: '0835fc5e45bb4e62520f3e3a6cee2f26af62f240c0d525145855b2cbe20a2617'
3
+ metadata.gz: 61f183b1671a060cdcd4d32e604ecd8518691d1c160d6158a862a8c82a61c0ab
4
+ data.tar.gz: 38b45a305a6d3b7027165d5d46f607c26b2e4b224db45a45f8c0e0aeb79c9676
5
5
  SHA512:
6
- metadata.gz: d8a1ee09f560723cf30110e2db8bde35e6aca2d0f9eae438e457d6f7a0c0706cb3c716bba18731f77403e1da2d05cf5c24dc2793535081f4eb11770f4adef30d
7
- data.tar.gz: bf055508b468c05c5310af9c3037faed74695beb7fd84e98bf65d2f7cb3d42dc96bd0df1c84e10b0339428287a006ccb5873902bd2cb141dac0a552000b37e9b
6
+ metadata.gz: 776bc9c496ec436ef5f8a94ef94fbd69f17783fbfc3fb20066d42dd23eec3d0b2cf80dc20f17bbb973ebe2d84047bd8730afb5632b181316bedc26169264805d
7
+ data.tar.gz: 236108055ed121d07da4073bd54870b934b066e4ac49581920d9a45a3a103a4d2912c3b6380c4b39117862dc97962bf30da7260eda358ff14d511d8ab50545bd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zombie_battleground-api (0.3.0)
4
+ zombie_battleground-api (0.4.0)
5
5
  activerecord
6
6
  faraday
7
7
  json
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
  [![Build Status](https://travis-ci.org/watmin/zombie_battleground-api.svg?branch=master)](https://travis-ci.org/watmin/zombie_battleground-api)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/watmin/zombie_battleground-api/badge.svg?branch=master)](https://coveralls.io/github/watmin/zombie_battleground-api?branch=master)
6
6
 
7
+ [Challenge Accepted](https://medium.com/loom-network/https-medium-com-loom-network-introducing-zombie-battleground-public-api-600-pack-giveaway-859fea0dc406)
8
+
7
9
  Ruby implementation of the Public API for Zombie Battleground
8
10
 
9
11
  ## Installation
@@ -24,7 +26,7 @@ Or install it yourself as:
24
26
 
25
27
  ## Usage
26
28
 
27
- See the [API documentation](https://www.rubydoc.info/gems/zombie_battleground-api/0.3.0).
29
+ See the [API documentation](https://www.rubydoc.info/gems/zombie_battleground-api/0.4.0).
28
30
  Every API call returns a response object that contains a complete modeled Ruby object of the response.
29
31
 
30
32
  Use the singleton class `ZombieBattleground::Api`
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # ZombieBattleground namespace
5
+ module ZombieBattleground
6
+ class Api
7
+ ##
8
+ # Max items per page
9
+ PAGE_MAX = 100
10
+ end
11
+ end
@@ -0,0 +1,191 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zombie_battleground/api/constants'
4
+
5
+ module ZombieBattleground
6
+ class Api
7
+ ##
8
+ # API Extensions
9
+ module Extensions
10
+ ##
11
+ # API Extensions for Cards
12
+ module Cards
13
+ ##
14
+ # Fetches all available cards
15
+ #
16
+ # @return [Array<ZombieBattleground::Api::Models::Card>]
17
+ #
18
+ # @example
19
+ # cards = ZombieBattleground::Api.all_cards
20
+ # # => [ZombieBattleground::Api::Models::Card]
21
+ #
22
+ # @api public
23
+ def all_cards(**args)
24
+ page = 1
25
+ cards = []
26
+
27
+ loop do
28
+ response = @client.cards_request(args.merge(page: page))
29
+ cards.push(*response.cards)
30
+ break if response.cards.size < PAGE_MAX
31
+ # :nocov:
32
+ page += 1
33
+ # :nocov:
34
+ end
35
+
36
+ cards
37
+ end
38
+
39
+ ##
40
+ # Fetches all available cards
41
+ #
42
+ # @return [Array<ZombieBattleground::Api::Models::Card>]
43
+ #
44
+ # @example
45
+ # cards = ZombieBattleground::Api.all_cards
46
+ # # => [ZombieBattleground::Api::Models::Card]
47
+ #
48
+ # @api public
49
+ def card_kinds
50
+ all_cards.map(&:kind).uniq
51
+ end
52
+
53
+ ##
54
+ # Fetches all card ranks
55
+ #
56
+ # @return [Array<String>]
57
+ #
58
+ # @example
59
+ # ranks = ZombieBattleground::Api.card_ranks
60
+ # # => [String]
61
+ #
62
+ # @api public
63
+ def card_ranks
64
+ all_cards.map(&:rank).uniq
65
+ end
66
+
67
+ ##
68
+ # Fetches all card sets
69
+ #
70
+ # @return [Array<String>]
71
+ #
72
+ # @example
73
+ # sets = ZombieBattleground::Api.card_sets
74
+ # # => [String]
75
+ #
76
+ # @api public
77
+ def card_sets
78
+ all_cards.map(&:set).uniq
79
+ end
80
+
81
+ ##
82
+ # Fetches all card types
83
+ #
84
+ # @return [Array<String>]
85
+ #
86
+ # @example
87
+ # types = ZombieBattleground::Api.card_types
88
+ # # => [String]
89
+ #
90
+ # @api public
91
+ def card_types
92
+ all_cards.map(&:type).uniq
93
+ end
94
+
95
+ ##
96
+ # Fetches all card rarities
97
+ #
98
+ # @return [Array<String>]
99
+ #
100
+ # @example
101
+ # rarities = ZombieBattleground::Api.card_rarities
102
+ # # => [String]
103
+ #
104
+ # @api public
105
+ def card_rarities
106
+ all_cards.map(&:rarity).uniq
107
+ end
108
+
109
+ ##
110
+ # Fetches all cards with selected kind
111
+ #
112
+ # @param kind [String]
113
+ #
114
+ # @return [Array<ZombieBattleground::Api::Models::Card>]
115
+ #
116
+ # @example
117
+ # cards = ZombieBattleground::Api.cards_by_kind(kind: "SPELL")
118
+ # # => [ZombieBattleground::Api::Models::Card]
119
+ #
120
+ # @api public
121
+ def cards_by_kind(kind:)
122
+ all_cards(kind: kind)
123
+ end
124
+
125
+ ##
126
+ # Fetches all cards with selected rank
127
+ #
128
+ # @param rank [String]
129
+ #
130
+ # @return [Array<ZombieBattleground::Api::Models::Card>]
131
+ #
132
+ # @example
133
+ # cards = ZombieBattleground::Api.cards_by_rank(rank: "COMMANDER")
134
+ # # => [ZombieBattleground::Api::Models::Card]
135
+ #
136
+ # @api public
137
+ def cards_by_rank(rank:)
138
+ all_cards(rank: rank)
139
+ end
140
+
141
+ ##
142
+ # Fetches all cards with selected set
143
+ #
144
+ # @param set [String]
145
+ #
146
+ # @return [Array<ZombieBattleground::Api::Models::Card>]
147
+ #
148
+ # @example
149
+ # cards = ZombieBattleground::Api.cards_by_set(set: "WATER")
150
+ # # => [ZombieBattleground::Api::Models::Card]
151
+ #
152
+ # @api public
153
+ def cards_by_set(set:)
154
+ all_cards(set: set)
155
+ end
156
+
157
+ ##
158
+ # Fetches all cards with selected type
159
+ #
160
+ # @param type [String]
161
+ #
162
+ # @return [Array<ZombieBattleground::Api::Models::Card>]
163
+ #
164
+ # @example
165
+ # cards = ZombieBattleground::Api.cards_by_type(type: "WALKER")
166
+ # # => [ZombieBattleground::Api::Models::Card]
167
+ #
168
+ # @api public
169
+ def cards_by_type(type:)
170
+ all_cards(type: type)
171
+ end
172
+
173
+ ##
174
+ # Fetches all cards with selected rarity
175
+ #
176
+ # @param rarity [String]
177
+ #
178
+ # @return [Array<ZombieBattleground::Api::Models::Card>]
179
+ #
180
+ # @example
181
+ # cards = ZombieBattleground::Api.cards_by_rarity(rarity: "")
182
+ # # => [ZombieBattleground::Api::Models::Card]
183
+ #
184
+ # @api public
185
+ def cards_by_rarity(rarity:)
186
+ all_cards(rarity: rarity)
187
+ end
188
+ end
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zombie_battleground/api/extensions/cards'
4
+
5
+ module ZombieBattleground
6
+ class Api
7
+ ##
8
+ # API Extensions
9
+ module Extensions
10
+ include ZombieBattleground::Api::Extensions::Cards
11
+ end
12
+ end
13
+ end
@@ -6,6 +6,6 @@ module ZombieBattleground
6
6
  class Api
7
7
  ##
8
8
  # Verion of the Gem
9
- VERSION = '0.3.0'
9
+ VERSION = '0.4.0'
10
10
  end
11
11
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'zombie_battleground/api/client'
4
+ require 'zombie_battleground/api/extensions'
4
5
 
5
6
  module ZombieBattleground
6
7
  ##
@@ -9,6 +10,8 @@ module ZombieBattleground
9
10
  @client = ZombieBattleground::Api::Client.new
10
11
 
11
12
  class << self
13
+ include ZombieBattleground::Api::Extensions
14
+
12
15
  ##
13
16
  # Queries for Decks and returns a modeled response
14
17
  #
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Shields
@@ -244,7 +244,10 @@ files:
244
244
  - docker-compose.yml
245
245
  - lib/zombie_battleground/api.rb
246
246
  - lib/zombie_battleground/api/client.rb
247
+ - lib/zombie_battleground/api/constants.rb
247
248
  - lib/zombie_battleground/api/errors.rb
249
+ - lib/zombie_battleground/api/extensions.rb
250
+ - lib/zombie_battleground/api/extensions/cards.rb
248
251
  - lib/zombie_battleground/api/models/card.rb
249
252
  - lib/zombie_battleground/api/models/deck.rb
250
253
  - lib/zombie_battleground/api/models/match.rb