Class: FplGsheet::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/fpl_gsheet/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry_id) ⇒ Entry

Returns a new instance of Entry.



6
7
8
9
10
11
12
13
14
# File 'lib/fpl_gsheet/entry.rb', line 6

def initialize(entry_id)
  entry_json=JSON.load(open("https://fantasy.premierleague.com/api/entry/#{entry_id}/", {ssl_verify_mode: 0}))
  @entry_data=entry_json.reject { |e| e.is_a? Hash }
  @league_data=entry_json['leagues']
  @name=@entry_data['name']
  @id=@entry_data['id']
  @historical_gameweeks = Hash.new()
  #@fixtures = fixtures.map { |f| TeamFixture.new(f, @data['id']) }

end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/fpl_gsheet/entry.rb', line 5

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/fpl_gsheet/entry.rb', line 5

def name
  @name
end

Instance Method Details

#chipsObject



30
# File 'lib/fpl_gsheet/entry.rb', line 30

def chips; history["chips"]; end

#gameweek_historyObject



36
# File 'lib/fpl_gsheet/entry.rb', line 36

def gameweek_history; history["current"]; end

#historyObject



20
21
22
# File 'lib/fpl_gsheet/entry.rb', line 20

def history
  @history ||= JSON.load(open("https://fantasy.premierleague.com/api/entry/#{id}/history/", {ssl_verify_mode: 0}))
end

#manager_nameObject



16
17
18
# File 'lib/fpl_gsheet/entry.rb', line 16

def manager_name
  @entry_data['player_first_name'] + ' ' + @entry_data['player_last_name']
end

#past_seasonsObject



34
# File 'lib/fpl_gsheet/entry.rb', line 34

def past_seasons; history["past"]; end

#picksObject



38
39
40
41
# File 'lib/fpl_gsheet/entry.rb', line 38

def picks
  latest_gameweek = gameweek_history.last['event']
  picks_for_gameweek[latest_gameweek]
end

#picks_for_gameweek(gw) ⇒ Object



43
44
45
46
47
# File 'lib/fpl_gsheet/entry.rb', line 43

def picks_for_gameweek(gw)
  return @historical_gameweeks[gw] if @historical_gameweeks.key?(gw)
  api ||= JSON.load(open("https://fantasy.premierleague.com/api/entry/#{id}/event/#{gw}/picks/", {ssl_verify_mode: 0}))
  @historical_gameweeks[gw] = api['picks'].map { |p| Pick.new(p)}
end

#summaryObject



32
# File 'lib/fpl_gsheet/entry.rb', line 32

def summary; history["entry"]; end

#transfersObject



25
26
27
28
# File 'lib/fpl_gsheet/entry.rb', line 25

def transfers
  @transfer_data ||= JSON.load(open("https://fantasy.premierleague.com/api/entry/#{id}/transfers/", {ssl_verify_mode: 0}))
  @transfer_data.reverse # At some point FPL changed to have newest transfers first; that's just silly

end