Class: Mousecop::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/mousecop/player.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#conferenceObject

Returns the value of attribute conference.



6
7
8
# File 'lib/mousecop/player.rb', line 6

def conference
  @conference
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/mousecop/player.rb', line 6

def id
  @id
end

#imageObject

Returns the value of attribute image.



6
7
8
# File 'lib/mousecop/player.rb', line 6

def image
  @image
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/mousecop/player.rb', line 6

def name
  @name
end

Class Method Details

.allObject



8
9
10
11
12
13
14
15
16
# File 'lib/mousecop/player.rb', line 8

def self.all
  @roster = Faraday.get(base_url + "/players").body

  JSON.parse(@roster).collect do |player|
  self.create(name: player["name"],
  id: player["id"],
  image: player["image"])
  end
end

.base_urlObject



39
40
41
# File 'lib/mousecop/player.rb', line 39

def self.base_url
  "http://collegebowl.avatarpro.biz/"
end

.create(attributes = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/mousecop/player.rb', line 18

def self.create(attributes= {})
  self.new.tap do |player|
  player.name = attributes[:name]
  player.id = attributes[:id]
  player.image = attributes[:image]
  end
end

.firstObject



34
35
36
37
# File 'lib/mousecop/player.rb', line 34

def self.first
  @all ||= self.all
  @all.first
end

.sampleObject



26
27
28
29
30
31
32
# File 'lib/mousecop/player.rb', line 26

def self.sample
  player_response = Faraday.get(base_url + "/player").body
  player = JSON.parse(player_response).first
  Mousecop::Player.create(name: player["name"],
     id: player["id"],
     image: player["image"])
end