Class: LolesportsApi::Tournament

Inherits:
BaseApiObject show all
Defined in:
lib/lolesports-api/tournament.rb

Constant Summary collapse

API_URL =
'http://na.lolesports.com/api/tournament'

Constants inherited from BaseApiObject

BaseApiObject::SCHEDULE_URL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseApiObject

fail_by_status, #reload

Constructor Details

#initialize(attributes) ⇒ Tournament

Returns a new instance of Tournament.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lolesports-api/tournament.rb', line 9

def initialize(attributes)
  @id = attributes['id'].to_i
  @contestants = []
  @date_begin = parse_datetime(attributes['dateBegin'])
  @date_end = parse_datetime(attributes['dateEnd'])
  @is_finished = attributes['isFinished']
  @name = attributes['name']
  @name_public = attributes['namePublic']
  @no_vods = attributes['noVods']
  @published = attributes['published']
  @season = attributes['season']
  @winner = attributes['winner'].to_i
  @matches = []

  self
end

Instance Attribute Details

#contestantsObject (readonly)

Returns the value of attribute contestants.



3
4
5
# File 'lib/lolesports-api/tournament.rb', line 3

def contestants
  @contestants
end

#date_beginObject (readonly)

Returns the value of attribute date_begin.



3
4
5
# File 'lib/lolesports-api/tournament.rb', line 3

def date_begin
  @date_begin
end

#date_endObject (readonly)

Returns the value of attribute date_end.



3
4
5
# File 'lib/lolesports-api/tournament.rb', line 3

def date_end
  @date_end
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/lolesports-api/tournament.rb', line 3

def id
  @id
end

#is_finishedObject (readonly)

Returns the value of attribute is_finished.



3
4
5
# File 'lib/lolesports-api/tournament.rb', line 3

def is_finished
  @is_finished
end

#matchesObject (readonly)

Returns the value of attribute matches.



3
4
5
# File 'lib/lolesports-api/tournament.rb', line 3

def matches
  @matches
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/lolesports-api/tournament.rb', line 3

def name
  @name
end

#name_publicObject (readonly)

Returns the value of attribute name_public.



3
4
5
# File 'lib/lolesports-api/tournament.rb', line 3

def name_public
  @name_public
end

#no_vodsObject (readonly)

Returns the value of attribute no_vods.



3
4
5
# File 'lib/lolesports-api/tournament.rb', line 3

def no_vods
  @no_vods
end

#publishedObject (readonly)

Returns the value of attribute published.



3
4
5
# File 'lib/lolesports-api/tournament.rb', line 3

def published
  @published
end

#seasonObject (readonly)

Returns the value of attribute season.



3
4
5
# File 'lib/lolesports-api/tournament.rb', line 3

def season
  @season
end

#winnerObject (readonly)

Returns the value of attribute winner.



3
4
5
# File 'lib/lolesports-api/tournament.rb', line 3

def winner
  @winner
end

Class Method Details

.find(tournament_id) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/lolesports-api/tournament.rb', line 26

def self.find(tournament_id)
  super
  if @attributes['contestants'] && @attributes['contestants'].any?
    @attributes['contestants'].each_value do |contestant|
      @base_object.contestants << LolesportsApi::Team.new(contestant)
    end
  end
  @base_object
end

Instance Method Details

#find_matchesObject



36
37
38
39
40
41
42
43
# File 'lib/lolesports-api/tournament.rb', line 36

def find_matches
  response = Faraday.get("#{SCHEDULE_URL}?tournamentId=#{@id}")
  matches_json = JSON.parse(response.body)
  matches_json.each_value do |match|
    @matches << LolesportsApi::Match.new(match)
  end
  @matches
end