Class: FootStats::Player

Inherits:
Resource show all
Defined in:
lib/foot_stats/player.rb

Class Method Summary collapse

Methods inherited from Resource

#initialize, updated_response

Methods included from AttributeAccessor

#attributes, included

Constructor Details

This class inherits a constructor from FootStats::Resource

Class Method Details

.all(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/foot_stats/player.rb', line 5

def self.all(options={})
  team_id = options.fetch(:team)
  request  = Request.new self, :Equipe => team_id
  response = request.parse stream_key: "team_players-#{team_id}"

  return response.error if response.error?

  updated_response response, options
end

.parse_response(response) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/foot_stats/player.rb', line 15

def self.parse_response(response)
  # FootStats sucks!
  # When there is only one player, resource isn't a collection,
  # but it's the only player!
  case response.resource
  when Hash
    [self.new(
      source_id: response.resource['@Id'].to_i,
      full_name: response.resource['@Nome'],
      nickname:  response.resource['@Apelido']
    )]
  when Array
    response.collect do |player_params|
      self.new(
        source_id: player_params['@Id'].to_i,
        full_name: player_params['@Nome'],
        nickname:  player_params['@Apelido']
      )
    end
  else
    []
  end
end

.resource_keyString

Return the resource key that is fetch from the API response.

Returns:

  • (String)


51
52
53
# File 'lib/foot_stats/player.rb', line 51

def self.resource_key
  'Jogador'
end

.resource_nameString

Return the resource name to request to FootStats.

Returns:

  • (String)


43
44
45
# File 'lib/foot_stats/player.rb', line 43

def self.resource_name
  'ListaJogadoresEquipe'
end