Class: ZombieBattleground::Api::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/zombie_battleground/api/client.rb

Overview

The API Client for Zombie Battleground

Instance Method Summary collapse

Constructor Details

#initializeZombieBattleground::Api::Client

Creates a new client

Examples:

client = ZombieBattleground::Api::Client.new
# => ZombieBattleground::Api::Client


47
48
49
50
# File 'lib/zombie_battleground/api/client.rb', line 47

def initialize
  @endpoint = 'https://api.loom.games/zb'
  @api_version = 'v1'
end

Instance Method Details

#card_request(**args) ⇒ ZombieBattleground::Api::Responses::GetCardResponse

Queries for a Card

Examples:

response = client.card_request(mould_id: 2, version: 'v3')
# => ZombieBattleground::Api::Responses::GetCardResponse

Parameters:

  • mould_id (String)

    Optionally filter on Card mould_id

  • version (String)

    Optionally filter on Card version

Returns:

Raises:



238
239
240
241
242
243
244
245
246
247
248
# File 'lib/zombie_battleground/api/client.rb', line 238

def card_request(**args)
  request = ZombieBattleground::Api::Requests::GetCardRequest.new
  args.each { |key, val| request.send("#{key}=", val) }
  raise ZombieBattleground::Api::Errors::InvalidInput, request.errors.messages unless request.valid?

  response = connection(uri: request.uri, params: request.params).get
  card = ZombieBattleground::Api::Responses::GetCardResponse.new(response)
  raise ZombieBattleground::Api::Errors::InvalidResponse.new(response, card) unless card.valid?

  card
end

#cards_request(**args) ⇒ ZombieBattleground::Api::Responses::GetCardsResponse

Queries for Cards

Examples:

response = client.cards_request(limit: 1)
# => ZombieBattleground::Api::Responses::GetCardsResponse

Parameters:

  • id (Integer)

    Optionally filter on Card id

  • mould_id (String)

    Optionally filter on Card mould_id

  • version (String)

    Optionally filter on Card version

  • kind (String)

    Optionally filter on Card kind

  • set (String)

    Optionally filter on Card set

  • name (String)

    Optionally filter on Card name

  • rank (String)

    Optionally filter on Card rank

  • type (String)

    Optionally filter on Card type

  • rarity (String)

    Optionally filter on Card rarity

  • damage (Integer)

    Optionally filter on Card damage

  • health (Integer)

    Optionally filter on Card health

  • cost (Integer)

    Optionally filter on Card cost

  • page (Integer)

    Used for pagination of query results

  • limit (Integer)

    Used for pagination of query results. Max 100

  • remove_invalid (Boolean)

    Remove invalid decks from response. Default: true

Returns:

Raises:



208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/zombie_battleground/api/client.rb', line 208

def cards_request(**args)
  remove_invalid = args[:remove_invalid].nil? ? true : args.delete(:remove_invalid)

  request = ZombieBattleground::Api::Requests::GetCardsRequest.new
  args.each { |key, val| request.send("#{key}=", val) }
  raise ZombieBattleground::Api::Errors::InvalidInput, request.errors.messages unless request.valid?

  response = connection(uri: request.uri, params: request.params).get
  cards = ZombieBattleground::Api::Responses::GetCardsResponse.new(response)
  cards.remove_invalid = remove_invalid
  raise ZombieBattleground::Api::Errors::InvalidResponse.new(response, cards) unless cards.valid?

  cards
end

#deck_request(**args) ⇒ ZombieBattleground::Api::Responses::GetDeckResponse

Queries for a Deck

Examples:

response = client.deck_request(id: 1813)
# => ZombieBattleground::Api::Responses::GetDeckResponse

Parameters:

  • id (Integer)

    Deck id to request

Returns:

Raises:



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/zombie_battleground/api/client.rb', line 105

def deck_request(**args)
  request = ZombieBattleground::Api::Requests::GetDeckRequest.new
  args.each { |key, val| request.send("#{key}=", val) }
  raise ZombieBattleground::Api::Errors::InvalidInput, request.errors.messages unless request.valid?

  response = connection(uri: request.uri, params: request.params).get
  deck = ZombieBattleground::Api::Responses::GetDeckResponse.new(response)
  raise ZombieBattleground::Api::Errors::InvalidResponse.new(response, deck) unless deck.valid?

  deck
end

#decks_request(**args) ⇒ ZombieBattleground::Api::Responses::GetDecksResponse

Queries for Decks

Examples:

response = client.decks_reuest(limit: 1)
# => ZombieBattleground::Api::Responses::GetDecksResponse

Parameters:

  • id (Integer)

    Optionally filter on Deck id

  • user_id (String)

    Optionally filter on Deck user_id

  • deck_id (Integer)

    Optionally filter on Deck deck_id

  • name (String)

    Optionally filter on Deck name

  • hero_id (Integer)

    Optionally filter on Deck hero_id

  • primary_skill_id (Integer)

    Optionally filter on Deck primary_skill_id

  • secondary_skill_id (Integer)

    Optionally filter on Deck secondary_skill_id

  • version (string)

    optionally filter on deck version

  • page (Integer)

    Used for pagination of query results

  • limit (Integer)

    Used for pagination of query results. Max 100

  • remove_invalid (Boolean)

    Remove invalid decks from response. Default: true

Returns:

Raises:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/zombie_battleground/api/client.rb', line 76

def decks_request(**args)
  remove_invalid = args[:remove_invalid].nil? ? true : args.delete(:remove_invalid)

  request = ZombieBattleground::Api::Requests::GetDecksRequest.new
  args.each { |key, val| request.send("#{key}=", val) }
  raise ZombieBattleground::Api::Errors::InvalidInput, request.errors.messages unless request.valid?

  response = connection(uri: request.uri, params: request.params).get
  decks = ZombieBattleground::Api::Responses::GetDecksResponse.new(response)
  decks.remove_invalid = remove_invalid
  raise ZombieBattleground::Api::Errors::InvalidResponse.new(response, decks) unless decks.valid?

  decks
end

#match_request(**args) ⇒ ZombieBattleground::Api::Responses::GetMatchResponse

Queries for a Match

Examples:

response = client.match_request(id: 1454)
# => ZombieBattleground::Api::Responses::GetMatchResponse

Parameters:

  • id (Integer)

    Match id to request

Returns:

Raises:



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/zombie_battleground/api/client.rb', line 168

def match_request(**args)
  request = ZombieBattleground::Api::Requests::GetMatchRequest.new
  args.each { |key, val| request.send("#{key}=", val) }
  raise ZombieBattleground::Api::Errors::InvalidInput, request.errors.messages unless request.valid?

  response = connection(uri: request.uri, params: request.params).get
  match = ZombieBattleground::Api::Responses::GetMatchResponse.new(response)
  raise ZombieBattleground::Api::Errors::InvalidResponse.new(response, match) unless match.valid?

  match
end

#matches_request(**args) ⇒ ZombieBattleground::Api::Responses::GetMatchesResponse

Queries for Matches

Examples:

response = client.matches_request(limit: 1)
# => ZombieBattleground::Api::Responses::GetMatchesResponse

Parameters:

  • id (Integer)

    Optionally filter on Match id

  • player1_id (String)

    Optionally filter on Match player1_id

  • player2_id (String)

    Optionally filter on Match player2_id

  • status (String)

    Optionally filter on Match status

  • version (String)

    Optionally filter on Match version

  • winner_id (String)

    Optionally filter on Match winner_id

  • page (Integer)

    Used for pagination of query results

  • limit (Integer)

    Used for pagination of query results. Max 100

  • remove_invalid (Boolean)

    Remove invalid decks from response. Default: true

Returns:

Raises:



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/zombie_battleground/api/client.rb', line 139

def matches_request(**args)
  remove_invalid = args[:remove_invalid].nil? ? true : args.delete(:remove_invalid)

  request = ZombieBattleground::Api::Requests::GetMatchesRequest.new
  args.each { |key, val| request.send("#{key}=", val) }
  raise ZombieBattleground::Api::Errors::InvalidInput, request.errors.messages unless request.valid?

  response = connection(uri: request.uri, params: request.params).get
  matches = ZombieBattleground::Api::Responses::GetMatchesResponse.new(response)
  matches.remove_invalid = remove_invalid
  raise ZombieBattleground::Api::Errors::InvalidResponse.new(response, matches) unless matches.valid?

  matches
end