Class: Celly::Team

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

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#all ⇒ Object



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

def all
  end_point = "/teams"
  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["teams"] }
  else
    {status: response.code, message: response.message}
  end
end

#find(id) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/celly/team.rb', line 35

def find(id)
  end_point = "/teams/#{id}"
  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["teams"]}
  else
    {status: response.code, message: response.message}
  end
end

#roster(id) ⇒ Object



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

def roster(id)
  end_point = "/teams/#{id}/roster"
  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["roster"]}
  else
    {status: response.code, message: response.message}
  end
end

#stats(id) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/celly/team.rb', line 49

def stats(id)
  end_point = "/teams/#{id}/stats"
  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["stats"]}
  else
    {status: response.code, message: response.message}
  end
end