Class: Celly::Leaders

Inherits:
Object
  • Object
show all
Defined in:
lib/celly/leaders.rb

Constant Summary collapse

BASE_URL =
'https://statsapi.web.nhl.com/api/v1'

Instance Method Summary collapse

Instance Method Details

#assists(season) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/celly/leaders.rb', line 20

def assists(season)
  end_point = "/stats/leaders?leaderCategories=assists&season#{season}"
  uri = URI("#{BASE_URL}#{end_point}")
  response = Net::HTTP.get_response(uri)

  if response.code == '200'
    json_response = JSON.parse(response.body)
    {status: response.code, message: response.message, data: json_response["leagueLeaders"]}
  else
    {status: response.code, message: response.message}
  end
end

#goals(season) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/celly/leaders.rb', line 7

def goals(season)
  end_point = "/stats/leaders?leaderCategories=goals&season#{season}"
  uri = URI("#{BASE_URL}#{end_point}")
  response = Net::HTTP.get_response(uri)

  if response.code == '200'
    json_response = JSON.parse(response.body)
    {status: response.code, message: response.message, data: json_response["leagueLeaders"]}
  else
    {status: response.code, message: response.message}
  end
end

#points(season) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/celly/leaders.rb', line 33

def points(season)
  end_point = "/stats/leaders?leaderCategories=points&season#{season}"
  uri = URI("#{BASE_URL}#{end_point}")
  response = Net::HTTP.get_response(uri)

  if response.code == '200'
    json_response = JSON.parse(response.body)
    {status: response.code, message: response.message, data: json_response["leagueLeaders"]}
  else
    {status: response.code, message: response.message}
  end
end

#shutouts(season) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/celly/leaders.rb', line 46

def shutouts(season)
  end_point = "/stats/leaders?leaderCategories=shutouts&season#{season}"
  uri = URI("#{BASE_URL}#{end_point}")
  response = Net::HTTP.get_response(uri)

  if response.code == '200'
    json_response = JSON.parse(response.body)
    {status: response.code, message: response.message, data: json_response["leagueLeaders"]}
  else
    {status: response.code, message: response.message}
  end

end

#wins(season) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/celly/leaders.rb', line 60

def wins(season)
  end_point = "/stats/leaders?leaderCategories=wins&season#{season}"
  uri = URI("#{BASE_URL}#{end_point}")
  response = Net::HTTP.get_response(uri)

  if response.code == '200'
    json_response = JSON.parse(response.body)
    {status: response.code, message: response.message, data: json_response["leagueLeaders"]}
  else
    {status: response.code, message: response.message}
  end
end