Class: FootStats::Player
Class Method Summary collapse
- .all(options = {}) ⇒ Object
- .parse_response(response) ⇒ Object
-
.resource_key ⇒ String
Return the resource key that is fetch from the API response.
-
.resource_name ⇒ String
Return the resource name to request to FootStats.
Methods inherited from Resource
Methods included from AttributeAccessor
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(={}) team_id = .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, 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_key ⇒ String
Return the resource key that is fetch from the API response.
51 52 53 |
# File 'lib/foot_stats/player.rb', line 51 def self.resource_key 'Jogador' end |
.resource_name ⇒ String
Return the resource name to request to FootStats.
43 44 45 |
# File 'lib/foot_stats/player.rb', line 43 def self.resource_name 'ListaJogadoresEquipe' end |