Class: Celly::Schedule

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

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#all(start_date, end_date) ⇒ Object



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

def all(start_date, end_date)
  end_point = "/schedule?startDate=#{start_date}&endDate=#{end_date}"
  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["dates"]}
  else
    { status: response.code, message: response.message  }
  end
end

#team(start_date, end_date, team_id) ⇒ Object



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

def team(start_date, end_date, team_id)
  end_point = "/schedule?startDate=#{start_date}&endDate=#{end_date}&teamId=#{team_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["dates"]}
  else
    { status: response.code, message: response.message  }
  end
end