Class: FplGsheet::Entry
- Inherits:
-
Object
- Object
- FplGsheet::Entry
- Defined in:
- lib/fpl_gsheet/entry.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #chips ⇒ Object
- #gameweek_history ⇒ Object
- #history ⇒ Object
-
#initialize(entry_id) ⇒ Entry
constructor
A new instance of Entry.
- #manager_name ⇒ Object
- #past_seasons ⇒ Object
- #picks ⇒ Object
- #picks_for_gameweek(gw) ⇒ Object
- #summary ⇒ Object
- #transfers ⇒ Object
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/fpl_gsheet/entry.rb', line 5 def id @id end |
#name ⇒ Object (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
#chips ⇒ Object
30 |
# File 'lib/fpl_gsheet/entry.rb', line 30 def chips; history["chips"]; end |
#gameweek_history ⇒ Object
36 |
# File 'lib/fpl_gsheet/entry.rb', line 36 def gameweek_history; history["current"]; end |
#history ⇒ Object
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_name ⇒ Object
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_seasons ⇒ Object
34 |
# File 'lib/fpl_gsheet/entry.rb', line 34 def past_seasons; history["past"]; end |
#picks ⇒ Object
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 |
#summary ⇒ Object
32 |
# File 'lib/fpl_gsheet/entry.rb', line 32 def summary; history["entry"]; end |
#transfers ⇒ Object
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 |