zombie_battleground-api 0.1.0 → 0.2.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.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/Gemfile.lock +29 -11
  4. data/README.md +4 -0
  5. data/Rakefile +62 -5
  6. data/lib/zombie_battleground/api.rb +108 -8
  7. data/lib/zombie_battleground/api/client.rb +157 -23
  8. data/lib/zombie_battleground/api/errors.rb +28 -0
  9. data/lib/zombie_battleground/api/models/card.rb +272 -32
  10. data/lib/zombie_battleground/api/models/deck.rb +234 -46
  11. data/lib/zombie_battleground/api/models/match.rb +211 -33
  12. data/lib/zombie_battleground/api/models/simple_card.rb +47 -11
  13. data/lib/zombie_battleground/api/requests/get_card_request.rb +45 -10
  14. data/lib/zombie_battleground/api/requests/get_cards_request.rb +203 -27
  15. data/lib/zombie_battleground/api/requests/get_deck_request.rb +43 -13
  16. data/lib/zombie_battleground/api/requests/get_decks_request.rb +141 -23
  17. data/lib/zombie_battleground/api/requests/get_match_request.rb +43 -13
  18. data/lib/zombie_battleground/api/requests/get_matches_request.rb +125 -21
  19. data/lib/zombie_battleground/api/requests/request_helper.rb +24 -10
  20. data/lib/zombie_battleground/api/responses/get_card_response.rb +50 -16
  21. data/lib/zombie_battleground/api/responses/get_cards_response.rb +103 -33
  22. data/lib/zombie_battleground/api/responses/get_deck_response.rb +49 -17
  23. data/lib/zombie_battleground/api/responses/get_decks_response.rb +103 -33
  24. data/lib/zombie_battleground/api/responses/get_match_response.rb +49 -17
  25. data/lib/zombie_battleground/api/responses/get_matches_response.rb +103 -33
  26. data/lib/zombie_battleground/api/responses/response_helper.rb +32 -16
  27. data/lib/zombie_battleground/api/validation_helper.rb +497 -0
  28. data/lib/zombie_battleground/api/version.rb +5 -1
  29. data/zombie_battleground-api.gemspec +6 -0
  30. metadata +71 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b70c3c3d5dbcf87bd3104d85db5a99cdaefa0224cb6e3441a956cd7ade8290a
4
- data.tar.gz: 214cbe7b928a264a1c55e80f99f6ad9096058a88addc89a28dfbe209007850be
3
+ metadata.gz: e39b7b110a3e45704b60e09b56a81b353ffc87347a06d759d8deb178c8b788b7
4
+ data.tar.gz: b369d8a886b27eae14908fd61b6a36767c259336ce0a7dcc5b1a4ee3880cd665
5
5
  SHA512:
6
- metadata.gz: 4c4f80e80f1c4f463185f9d189ede2914bb41175fd9343e5d9ee82992c318c679c76fd1b8ac06887eeafc8df8159638b3ca431fd4687a0b2a42409591872fd8f
7
- data.tar.gz: c49ecc117373b8f15b526242c12201a0fb48f0032815105dd6504ea00453948380e20209907302869dd287c3ac513dab6d422e7c0be75709e28ad775fce5e482
6
+ metadata.gz: 658ec416c5a8aad44dcbe57ef39b2f518ecfaa4b07c8f6b2265cfcef207f36631144a96e38bcc3d101e57c4956250b02d264fb7defcfd39dbe8bca95a4e25ea5
7
+ data.tar.gz: 7ac36a2d0f1339a2d03d40eb9a9a795443e24a54ffd58fd7d94a1ffd9c4a2116e0d03fd94fe20b1017add7150fc4fbf8f51d4b46b112ad5c8badd0cd7a98e16b
data/.gitignore CHANGED
@@ -46,6 +46,9 @@ build-iPhoneSimulator/
46
46
  # .ruby-version
47
47
  # .ruby-gemset
48
48
 
49
+ # Ignore Vim swaps
50
+ *.sw*
51
+
49
52
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
53
  .rvmrc
51
54
  =======
@@ -54,6 +57,7 @@ build-iPhoneSimulator/
54
57
  /_yardoc/
55
58
  /coverage/
56
59
  /doc/
60
+ /out/
57
61
  /pkg/
58
62
  /spec/reports/
59
63
  /tmp/
data/Gemfile.lock CHANGED
@@ -1,22 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zombie_battleground-api (0.1.0)
4
+ zombie_battleground-api (0.2.0)
5
5
  activerecord
6
6
  faraday
7
7
  json
8
8
  pry
9
+ pry-doc
9
10
 
10
11
  GEM
11
12
  remote: https://rubygems.org/
12
13
  specs:
13
- activemodel (5.2.1)
14
- activesupport (= 5.2.1)
15
- activerecord (5.2.1)
16
- activemodel (= 5.2.1)
17
- activesupport (= 5.2.1)
14
+ activemodel (5.2.2)
15
+ activesupport (= 5.2.2)
16
+ activerecord (5.2.2)
17
+ activemodel (= 5.2.2)
18
+ activesupport (= 5.2.2)
18
19
  arel (>= 9.0)
19
- activesupport (5.2.1)
20
+ activesupport (5.2.2)
20
21
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
22
  i18n (>= 0.7, < 2)
22
23
  minitest (~> 5.1)
@@ -24,24 +25,29 @@ GEM
24
25
  arel (9.0.0)
25
26
  ast (2.4.0)
26
27
  coderay (1.1.2)
27
- concurrent-ruby (1.0.5)
28
+ concurrent-ruby (1.1.4)
28
29
  diff-lcs (1.3)
30
+ docile (1.3.1)
29
31
  faraday (0.15.4)
30
32
  multipart-post (>= 1.2, < 3)
31
- i18n (1.1.1)
33
+ gem-release (2.0.1)
34
+ i18n (1.5.3)
32
35
  concurrent-ruby (~> 1.0)
33
36
  jaro_winkler (1.5.1)
34
37
  json (2.1.0)
35
- method_source (0.9.0)
38
+ method_source (0.9.2)
36
39
  minitest (5.11.3)
37
40
  multipart-post (2.0.0)
38
41
  parallel (1.12.1)
39
42
  parser (2.5.1.0)
40
43
  ast (~> 2.4.0)
41
44
  powerpack (0.1.2)
42
- pry (0.12.0)
45
+ pry (0.12.2)
43
46
  coderay (~> 1.1.0)
44
47
  method_source (~> 0.9.0)
48
+ pry-doc (1.0.0)
49
+ pry (~> 0.11)
50
+ yard (~> 0.9.11)
45
51
  rainbow (3.0.0)
46
52
  rake (10.5.0)
47
53
  rspec (3.8.0)
@@ -66,19 +72,31 @@ GEM
66
72
  ruby-progressbar (~> 1.7)
67
73
  unicode-display_width (~> 1.0, >= 1.0.1)
68
74
  ruby-progressbar (1.9.0)
75
+ simplecov (0.16.1)
76
+ docile (~> 1.1)
77
+ json (>= 1.8, < 3)
78
+ simplecov-html (~> 0.10.0)
79
+ simplecov-html (0.10.2)
69
80
  thread_safe (0.3.6)
70
81
  tzinfo (1.2.5)
71
82
  thread_safe (~> 0.1)
72
83
  unicode-display_width (1.4.0)
84
+ yard (0.9.18)
85
+ yardstick (0.9.9)
86
+ yard (~> 0.8, >= 0.8.7.2)
73
87
 
74
88
  PLATFORMS
75
89
  ruby
76
90
 
77
91
  DEPENDENCIES
78
92
  bundler (~> 1.16)
93
+ gem-release
79
94
  rake (~> 10.0)
80
95
  rspec (~> 3.0)
81
96
  rubocop
97
+ simplecov
98
+ yard
99
+ yardstick
82
100
  zombie_battleground-api!
83
101
 
84
102
  BUNDLED WITH
data/README.md CHANGED
@@ -23,6 +23,8 @@ Or install it yourself as:
23
23
  Use the singleton class `ZombieBattleground::Api`
24
24
 
25
25
  ```ruby
26
+ require 'zombie_battleground-api/api'
27
+
26
28
  ZombieBattleground::Api.decks(limit: 1)
27
29
  # => ZombieBattleground::Api::GetDecksResponse
28
30
  ```
@@ -30,6 +32,8 @@ ZombieBattleground::Api.decks(limit: 1)
30
32
  Use the API client directly
31
33
 
32
34
  ```ruby
35
+ require 'zombie_battleground-api/api/client'
36
+
33
37
  client = ZombieBattleground::Api::Client.new
34
38
  client.decks(limit: 1) # => ZombieBattleground::Api::GetDecksResponse
35
39
  ```
data/Rakefile CHANGED
@@ -3,14 +3,71 @@
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
5
  require 'rubocop/rake_task'
6
+ require 'yard'
7
+ require 'yard/rake/yardoc_task'
8
+ require 'yardstick/rake/measurement'
9
+ require 'yardstick/rake/verify'
6
10
 
7
- RSpec::Core::RakeTask.new(:spec)
8
- task default: :spec
11
+ def empty_directory(directory)
12
+ FileUtils.remove_entry(directory)
13
+ FileUtils.mkdir(directory)
14
+ end
15
+
16
+ # clean up the workspace
17
+ task(:clean) do
18
+ empty_directory('doc')
19
+ empty_directory('out')
20
+ empty_directory('pkg')
21
+ end
9
22
 
23
+ # unit tests
24
+ RSpec::Core::RakeTask.new(:spec) do |task|
25
+ task.pattern = 'spec/**/*_spec.rb'
26
+ task.rspec_opts = '--require spec_helper ' \
27
+ '--format documentation ' \
28
+ '--format html ' \
29
+ '--out out/rspec_unit.html'
30
+ end
31
+ task(default: :spec)
32
+
33
+ # configure rubocop
10
34
  RuboCop::RakeTask.new(:rubocop) do |task|
11
- task.options = ['--display-cop-names']
35
+ task.options = [
36
+ '--format', 'simple',
37
+ '--format', 'html',
38
+ '--out', 'out/rubocop.html',
39
+ 'lib/**/*.rb',
40
+ 'spec/**/*.rb'
41
+ ]
42
+ end
43
+ task(default: :rubocop)
44
+
45
+ # configure yard
46
+ YARD::Rake::YardocTask.new(:yard) do |task|
47
+ task.files = Dir['lib/**/*.rb']
48
+ task.options = [
49
+ '--quiet' # YARD doesn't like the methods that received (**args)
50
+ ]
51
+ task.stats_options = [
52
+ '--list-undoc'
53
+ ]
54
+ end
55
+ task(default: :yard)
56
+
57
+ # documentation coverage
58
+ Yardstick::Rake::Measurement.new(:yardstick_measure) do |task|
59
+ task.output = 'out/yard-report.txt'
60
+ end
61
+ task(default: :yardstick_measure)
62
+
63
+ # documentation enforcement
64
+ Yardstick::Rake::Verify.new(:yardstick_verify) do |task|
65
+ task.threshold = 100
12
66
  end
67
+ task(default: :yardstick_verify)
13
68
 
14
- task default: :rubocop
69
+ # Require tests, syntax and documentation to pass before building
70
+ task(build: %i[spec rubocop yard yardstick_measure yardstick_verify])
15
71
 
16
- task build: %i[spec rubocop]
72
+ # Require a succesful build before release
73
+ task(release: %i[build])
@@ -10,30 +10,130 @@ module ZombieBattleground
10
10
  @client = ZombieBattleground::Api::Client.new
11
11
 
12
12
  class << self
13
- attr_accessor :client
14
-
13
+ ##
14
+ # Queries for Decks
15
+ #
16
+ # @param id [Integer] Optionally filter on Deck id
17
+ # @param user_id [String] Optionally filter on Deck user_id
18
+ # @param deck_id [Integer] Optionally filter on Deck deck_id
19
+ # @param name [String] Optionally filter on Deck name
20
+ # @param hero_id [Integer] Optionally filter on Deck hero_id
21
+ # @param primary_skill_id [Integer] Optionally filter on Deck primary_skill_id
22
+ # @param secondary_skill_id [Integer] Optionally filter on Deck secondary_skill_id
23
+ # @param version [String] Optionally filter on Deck version
24
+ # @param page [Integer] Used for pagination of query results
25
+ # @param limit [Integer] Used for pagination of query results. Max 100
26
+ #
27
+ # @return [ZombieBattleground::Api::Responses::GetDecksResponse]
28
+ #
29
+ # @example
30
+ # response = ZombieBattleground::Api.decks(limit: 1)
31
+ # response # => ZombieBattleground::Api::Responses::GetDecksResponse
32
+ #
33
+ # @api public
15
34
  def decks(**args)
16
- client.decks(**args)
35
+ @client.decks(**args)
17
36
  end
18
37
 
38
+ ##
39
+ # Queries for a Deck
40
+ #
41
+ # @param id [Integer] Deck id to request
42
+ #
43
+ # @return [ZombieBattleground::Api::Responses::GetDeckResponse]
44
+ #
45
+ # @example
46
+ # response = ZombieBattleground::Api.deck(id: 1813)
47
+ # response # => ZombieBattleground::Api::Responses::GetDeckResponse
48
+ #
49
+ # @api public
19
50
  def deck(**args)
20
- client.deck(**args)
51
+ @client.deck(**args)
21
52
  end
22
53
 
54
+ ##
55
+ # Queries for Matches
56
+ #
57
+ # @param id [Integer] Optionally filter on Match id
58
+ # @param player1_id [String] Optionally filter on Match player1_id
59
+ # @param player2_id [String] Optionally filter on Match player2_id
60
+ # @param status [String] Optionally filter on Match status
61
+ # @param version [String] Optionally filter on Match version
62
+ # @param winner_id [String] Optionally filter on Match winner_id
63
+ # @param page [Integer] Used for pagination of query results
64
+ # @param limit [Integer] Used for pagination of query results. Max 100
65
+ #
66
+ # @return [ZombieBattleground::Api::Responses::GetMatchesResponse]
67
+ #
68
+ # @example
69
+ # response = ZombieBattleground::Api.matches(limit: 1)
70
+ # response # => ZombieBattleground::Api::Responses::GetMatchesResponse
71
+ #
72
+ # @api public
23
73
  def matches(**args)
24
- client.matches(**args)
74
+ @client.matches(**args)
25
75
  end
26
76
 
77
+ ##
78
+ # Queries for a Match
79
+ #
80
+ # @param id [Integer] Match id to request
81
+ #
82
+ # @return [ZombieBattleground::Api::Responses::GetMatchResponse]
83
+ #
84
+ # @example
85
+ # response = ZombieBattleground::Api.match(id: 1454)
86
+ # response # => ZombieBattleground::Api::Responses::GetMatchResponse
87
+ #
88
+ # @api public
27
89
  def match(**args)
28
- client.match(**args)
90
+ @client.match(**args)
29
91
  end
30
92
 
93
+ ##
94
+ # Queries for Cards
95
+ #
96
+ # @param id [Integer] Optionally filter on Card id
97
+ # @param mould_id [String] Optionally filter on Card mould_id
98
+ # @param version [String] Optionally filter on Card version
99
+ # @param kind [String] Optionally filter on Card kind
100
+ # @param set [String] Optionally filter on Card set
101
+ # @param name [String] Optionally filter on Card name
102
+ # @param rank [String] Optionally filter on Card rank
103
+ # @param type [String] Optionally filter on Card type
104
+ # @param rarity [String] Optionally filter on Card rarity
105
+ # @param damage [Integer] Optionally filter on Card damage
106
+ # @param health [Integer] Optionally filter on Card health
107
+ # @param cost [Integer] Optionally filter on Card cost
108
+ # @param page [Integer] Used for pagination of query results
109
+ # @param limit [Integer] Used for pagination of query results. Max 100
110
+ #
111
+ # @return [ZombieBattleground::Api::Responses::GetCardsResponse]
112
+ #
113
+ # @example
114
+ # response = ZombieBattleground::Api.cards(limit: 1)
115
+ # response # => ZombieBattleground::Api::Responses::GetCardsResponse
116
+ #
117
+ # @api public
31
118
  def cards(**args)
32
- client.cards(**args)
119
+ @client.cards(**args)
33
120
  end
34
121
 
122
+ ##
123
+ # Queries for a Card
124
+ #
125
+ # @param mould_id [String] Optionally filter on Card mould_id
126
+ # @param version [String] Optionally filter on Card version
127
+ #
128
+ # @return [ZombieBattleground::Api::Responses::GetCardResponse]
129
+ #
130
+ # @example
131
+ # response = ZombieBattleground::Api.card(mould_id: 2, version: 'v3')
132
+ # response # => ZombieBattleground::Api::Responses::GetCardResponse
133
+ #
134
+ # @api public
35
135
  def card(**args)
36
- client.card(**args)
136
+ @client.card(**args)
37
137
  end
38
138
  end
39
139
  end
@@ -22,93 +22,227 @@ module ZombieBattleground
22
22
  ##
23
23
  # The API Client for Zombie Battleground
24
24
  class Client
25
+ ##
26
+ # Creates a new client
27
+ #
28
+ # @return [void]
29
+ #
30
+ # @example
31
+ # client = ZombieBattleground::Api::Client.new
32
+ #
33
+ # @api public
25
34
  def initialize
26
35
  @endpoint = 'https://api.loom.games/zb'
27
36
  @api_version = 'v1'
28
37
  end
29
38
 
30
- def connection(uri:, params:)
31
- Faraday.new(
32
- url: "#{@endpoint}/#{@api_version}/#{uri}",
33
- params: params,
34
- headers: {
35
- 'User-Agent' => "RubyGem-zombie_battleground-api_#{VERSION}",
36
- 'Content-Type' => 'application/json'
37
- }
38
- )
39
- end
40
-
39
+ ##
40
+ # Queries for Decks
41
+ #
42
+ # @param id [Integer] Optionally filter on Deck id
43
+ # @param user_id [String] Optionally filter on Deck user_id
44
+ # @param deck_id [Integer] Optionally filter on Deck deck_id
45
+ # @param name [String] Optionally filter on Deck name
46
+ # @param hero_id [Integer] Optionally filter on Deck hero_id
47
+ # @param primary_skill_id [Integer] Optionally filter on Deck primary_skill_id
48
+ # @param secondary_skill_id [Integer] Optionally filter on Deck secondary_skill_id
49
+ # @param version [String] Optionally filter on Deck version
50
+ # @param page [Integer] Used for pagination of query results
51
+ # @param limit [Integer] Used for pagination of query results. Max 100
52
+ #
53
+ # @return [ZombieBattleground::Api::Responses::GetDecksResponse]
54
+ #
55
+ # @raise [ZombieBattleground::Api::Errors::InvalidInput, ZombieBattleground::Api::Errors::InvalidResponse]
56
+ #
57
+ # @example
58
+ # response = client.decks(limit: 1)
59
+ # response # => ZombieBattleground::Api::Responses::GetDecksResponse
60
+ #
61
+ # @api public
41
62
  def decks(**args)
42
- request = ZombieBattleground::Api::GetDecksRequest.new
63
+ request = ZombieBattleground::Api::Requests::GetDecksRequest.new
43
64
  args.each { |key, val| request.send("#{key}=", val) }
44
65
  raise ZombieBattleground::Api::Errors::InvalidInput, request.errors.messages unless request.valid?
45
66
 
46
67
  response = connection(uri: request.uri, params: request.params).get
47
- decks = ZombieBattleground::Api::GetDecksResponse.new(response)
68
+ decks = ZombieBattleground::Api::Responses::GetDecksResponse.new(response)
48
69
  raise ZombieBattleground::Api::Errors::InvalidResponse.new(response, decks) unless decks.valid?
49
70
 
50
71
  decks
51
72
  end
52
73
 
74
+ ##
75
+ # Queries for a Deck
76
+ #
77
+ # @param id [Integer] Deck id to request
78
+ #
79
+ # @return [ZombieBattleground::Api::Responses::GetDeckResponse]
80
+ #
81
+ # @raise [ZombieBattleground::Api::Errors::InvalidInput, ZombieBattleground::Api::Errors::InvalidResponse]
82
+ #
83
+ # @example
84
+ # response = client.deck(id: 1813)
85
+ # response # => ZombieBattleground::Api::Responses::GetDeckResponse
86
+ #
87
+ # @api public
53
88
  def deck(**args)
54
- request = ZombieBattleground::Api::GetDeckRequest.new
89
+ request = ZombieBattleground::Api::Requests::GetDeckRequest.new
55
90
  args.each { |key, val| request.send("#{key}=", val) }
56
91
  raise ZombieBattleground::Api::Errors::InvalidInput, request.errors.messages unless request.valid?
57
92
 
58
93
  response = connection(uri: request.uri, params: request.params).get
59
- deck = ZombieBattleground::Api::GetDeckResponse.new(response)
94
+ deck = ZombieBattleground::Api::Responses::GetDeckResponse.new(response)
60
95
  raise ZombieBattleground::Api::Errors::InvalidResponse.new(response, deck) unless deck.valid?
61
96
 
62
97
  deck
63
98
  end
64
99
 
100
+ ##
101
+ # Queries for Matches
102
+ #
103
+ # @param id [Integer] Optionally filter on Match id
104
+ # @param player1_id [String] Optionally filter on Match player1_id
105
+ # @param player2_id [String] Optionally filter on Match player2_id
106
+ # @param status [String] Optionally filter on Match status
107
+ # @param version [String] Optionally filter on Match version
108
+ # @param winner_id [String] Optionally filter on Match winner_id
109
+ # @param page [Integer] Used for pagination of query results
110
+ # @param limit [Integer] Used for pagination of query results. Max 100
111
+ #
112
+ # @return [ZombieBattleground::Api::Responses::GetMatchesResponse]
113
+ #
114
+ # @raise [ZombieBattleground::Api::Errors::InvalidInput, ZombieBattleground::Api::Errors::InvalidResponse]
115
+ #
116
+ # @example
117
+ # response = client.matches(limit: 1)
118
+ # response # => ZombieBattleground::Api::Responses::GetMatchesResponse
119
+ #
120
+ # @api public
65
121
  def matches(**args)
66
- request = ZombieBattleground::Api::GetMatchesRequest.new
122
+ request = ZombieBattleground::Api::Requests::GetMatchesRequest.new
67
123
  args.each { |key, val| request.send("#{key}=", val) }
68
124
  raise ZombieBattleground::Api::Errors::InvalidInput, request.errors.messages unless request.valid?
69
125
 
70
126
  response = connection(uri: request.uri, params: request.params).get
71
- matches = ZombieBattleground::Api::GetMatchesResponse.new(response)
127
+ matches = ZombieBattleground::Api::Responses::GetMatchesResponse.new(response)
72
128
  raise ZombieBattleground::Api::Errors::InvalidResponse.new(response, matches) unless matches.valid?
73
129
 
74
130
  matches
75
131
  end
76
132
 
133
+ ##
134
+ # Queries for a Match
135
+ #
136
+ # @param id [Integer] Match id to request
137
+ #
138
+ # @return [ZombieBattleground::Api::Responses::GetMatchResponse]
139
+ #
140
+ # @raise [ZombieBattleground::Api::Errors::InvalidInput, ZombieBattleground::Api::Errors::InvalidResponse]
141
+ #
142
+ # @example
143
+ # response = client.match(id: 1454)
144
+ # response # => ZombieBattleground::Api::Responses::GetMatchResponse
145
+ #
146
+ # @api public
77
147
  def match(**args)
78
- request = ZombieBattleground::Api::GetMatchRequest.new
148
+ request = ZombieBattleground::Api::Requests::GetMatchRequest.new
79
149
  args.each { |key, val| request.send("#{key}=", val) }
80
150
  raise ZombieBattleground::Api::Errors::InvalidInput, request.errors.messages unless request.valid?
81
151
 
82
152
  response = connection(uri: request.uri, params: request.params).get
83
- match = ZombieBattleground::Api::GetMatchResponse.new(response)
153
+ match = ZombieBattleground::Api::Responses::GetMatchResponse.new(response)
84
154
  raise ZombieBattleground::Api::Errors::InvalidResponse.new(response, match) unless match.valid?
85
155
 
86
156
  match
87
157
  end
88
158
 
159
+ ##
160
+ # Queries for Cards
161
+ #
162
+ # @param id [Integer] Optionally filter on Card id
163
+ # @param mould_id [String] Optionally filter on Card mould_id
164
+ # @param version [String] Optionally filter on Card version
165
+ # @param kind [String] Optionally filter on Card kind
166
+ # @param set [String] Optionally filter on Card set
167
+ # @param name [String] Optionally filter on Card name
168
+ # @param rank [String] Optionally filter on Card rank
169
+ # @param type [String] Optionally filter on Card type
170
+ # @param rarity [String] Optionally filter on Card rarity
171
+ # @param damage [Integer] Optionally filter on Card damage
172
+ # @param health [Integer] Optionally filter on Card health
173
+ # @param cost [Integer] Optionally filter on Card cost
174
+ # @param page [Integer] Used for pagination of query results
175
+ # @param limit [Integer] Used for pagination of query results. Max 100
176
+ #
177
+ # @return [ZombieBattleground::Api::Responses::GetCardsResponse]
178
+ #
179
+ # @raise [ZombieBattleground::Api::Errors::InvalidInput, ZombieBattleground::Api::Errors::InvalidResponse]
180
+ #
181
+ # @example
182
+ # response = client.cards(limit: 1)
183
+ # response # => ZombieBattleground::Api::Responses::GetCardsResponse
184
+ #
185
+ # @api public
89
186
  def cards(**args)
90
- request = ZombieBattleground::Api::GetCardsRequest.new
187
+ request = ZombieBattleground::Api::Requests::GetCardsRequest.new
91
188
  args.each { |key, val| request.send("#{key}=", val) }
92
189
  raise ZombieBattleground::Api::Errors::InvalidInput, request.errors.messages unless request.valid?
93
190
 
94
191
  response = connection(uri: request.uri, params: request.params).get
95
- cards = ZombieBattleground::Api::GetCardsResponse.new(response)
192
+ cards = ZombieBattleground::Api::Responses::GetCardsResponse.new(response)
96
193
  raise ZombieBattleground::Api::Errors::InvalidResponse.new(response, cards) unless cards.valid?
97
194
 
98
195
  cards
99
196
  end
100
197
 
198
+ ##
199
+ # Queries for a Card
200
+ #
201
+ # @param mould_id [String] Optionally filter on Card mould_id
202
+ # @param version [String] Optionally filter on Card version
203
+ #
204
+ # @return [ZombieBattleground::Api::Responses::GetCardResponse]
205
+ #
206
+ # @raise [ZombieBattleground::Api::Errors::InvalidInput, ZombieBattleground::Api::Errors::InvalidResponse]
207
+ #
208
+ # @example
209
+ # response = client.card(mould_id: 2, version: 'v3')
210
+ # response # => ZombieBattleground::Api::Responses::GetCardResponse
211
+ #
212
+ # @api public
101
213
  def card(**args)
102
- request = ZombieBattleground::Api::GetCardRequest.new
214
+ request = ZombieBattleground::Api::Requests::GetCardRequest.new
103
215
  args.each { |key, val| request.send("#{key}=", val) }
104
216
  raise ZombieBattleground::Api::Errors::InvalidInput, request.errors.messages unless request.valid?
105
217
 
106
218
  response = connection(uri: request.uri, params: request.params).get
107
- card = ZombieBattleground::Api::GetCardResponse.new(response)
219
+ card = ZombieBattleground::Api::Responses::GetCardResponse.new(response)
108
220
  raise ZombieBattleground::Api::Errors::InvalidResponse.new(response, card) unless card.valid?
109
221
 
110
222
  card
111
223
  end
224
+
225
+ private
226
+
227
+ ##
228
+ # Creates a new Faraday connection
229
+ #
230
+ # @param uri [String] the URI to append to the endpoint and API version
231
+ # @param params [Hash] the query paramaters for the request
232
+ #
233
+ # @return [Faraday::Connection]
234
+ #
235
+ # @api private
236
+ def connection(uri:, params:)
237
+ Faraday.new(
238
+ url: "#{@endpoint}/#{@api_version}/#{uri}",
239
+ params: params,
240
+ headers: {
241
+ 'User-Agent' => "RubyGem-zombie_battleground-api_#{VERSION}",
242
+ 'Content-Type' => 'application/json'
243
+ }
244
+ )
245
+ end
112
246
  end
113
247
  end
114
248
  end