Class: Celly::Scores
- Inherits:
-
Object
- Object
- Celly::Scores
- Defined in:
- lib/celly/scores.rb
Constant Summary collapse
- BASE_URL =
'https://statsapi.web.nhl.com/api/v1'
Instance Method Summary collapse
Instance Method Details
#on(date) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/celly/scores.rb', line 36 def on(date) end_point = "/schedule?startDate=#{date}&endDate=#{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., data: json_response["dates"]} else {status: response.code, message: response.} end end |
#today ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/celly/scores.rb', line 8 def today today = Date.today.strftime("%Y-%m-%d") end_point = "/schedule?startDate=#{today}&endDate=#{today}" 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., data: json_response["dates"]} else {status: response.code, message: response.} end end |
#yesterday ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/celly/scores.rb', line 22 def yesterday yesterday = Date.today.prev_day.strftime("%Y-%m-%d") end_point = "/schedule?startDate=#{yesterday}&endDate=#{yesterday}" 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., data: json_response["dates"]} else {status: response.code, message: response.} end end |