Class: ZombieBattleground::Api::Responses::GetDecksResponse

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, ResponseHelper, ValidationHelper
Defined in:
lib/zombie_battleground/api/responses/get_decks_response.rb

Overview

Response validator for GetDecks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ZombieBattleground::Api::GetDecksResponse

Creates a new GetDecksResponse

Examples:

response = ZombieBattleground::Api::GetDecksResponse.new(faraday_response)
# => ZombieBattleground::Api::GetDecksResponse

Parameters:

  • response (Faraday::Response)

    Faraday response from endpoint



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/zombie_battleground/api/responses/get_decks_response.rb', line 109

def initialize(response)
  handle_errors(response)

  JSON.parse(response.body).each do |key, value|
    if key == 'decks'
      # Keep the API response count, it will differ when invalid decks are stripped
      @decks_count = value.size

      instance_variable_set(
        "@#{key}".to_sym, value.map { |deck| ZombieBattleground::Api::Models::Deck.new(deck) }
      )
    else
      instance_variable_set("@#{key}".to_sym, value)
    end
  end
end

Instance Attribute Details

#decksArray<ZombieBattleground::Api::Models::Deck> (readonly)

the deck found for the page and limit

Examples:

response.decks #=> [ZombieBattleground::Api::Models::Deck]

Returns:



66
67
68
# File 'lib/zombie_battleground/api/responses/get_decks_response.rb', line 66

def decks
  @decks
end

#decks_countInteger (readonly)

the number of decks returned in the response

Examples:

response.decks_count #=> 1

Returns:

  • (Integer)


78
79
80
# File 'lib/zombie_battleground/api/responses/get_decks_response.rb', line 78

def decks_count
  @decks_count
end

#limitInteger (readonly)

the limit of results for the page

Examples:

response.limit #=> 100

Returns:

  • (Integer)


54
55
56
# File 'lib/zombie_battleground/api/responses/get_decks_response.rb', line 54

def limit
  @limit
end

#pageInteger (readonly)

the page number of the results

Examples:

response.page #=> 1

Returns:

  • (Integer)


42
43
44
# File 'lib/zombie_battleground/api/responses/get_decks_response.rb', line 42

def page
  @page
end

#remove_invalidBoolean

flag to remove objects in response that are invalid during validation

Examples:

response.remove_invalid = true

Returns:

  • (Boolean)


90
91
92
# File 'lib/zombie_battleground/api/responses/get_decks_response.rb', line 90

def remove_invalid
  @remove_invalid
end

#totalInteger (readonly)

the total number of results available

Examples:

response.total #=> 1505

Returns:

  • (Integer)


30
31
32
# File 'lib/zombie_battleground/api/responses/get_decks_response.rb', line 30

def total
  @total
end