Class: ZombieBattleground::Api::Responses::GetMatchesResponse

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

Overview

Response validator for GetMatches

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Creates a new GetMatchesResponse

Examples:

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

Parameters:

  • response (Faraday::Response)

    Faraday response from endpoint



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/zombie_battleground/api/responses/get_matches_response.rb', line 97

def initialize(response)
  handle_errors(response)

  JSON.parse(response.body).each do |key, value|
    if key == 'matches'
      instance_variable_set(
        "@#{key}".to_sym, value.map { |match| ZombieBattleground::Api::Models::Match.new(match) }
      )
    else
      instance_variable_set("@#{key}".to_sym, value)
    end
  end
end

Instance Attribute Details

#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_matches_response.rb', line 54

def limit
  @limit
end

#matchesArray<ZombieBattleground::Api::Models::Match> (readonly)

the matches found for the page and limit

Examples:

response.matches #=> [ZombieBattleground::Api::Models::Match]

Returns:



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

def matches
  @matches
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_matches_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)


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

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_matches_response.rb', line 30

def total
  @total
end