module SleeperRb::Utilities::Request
This module encapsulates the logic for handling the response when querying from the Sleeper API.
Constants
- BASE_URL
- CDN_BASE_URL
Private Instance Methods
download_file(url, filename)
click to toggle source
# File lib/sleeper_rb/utilities/request.rb, line 29 def download_file(url, filename) uri = URI(url) Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| resp = http.get(uri.path) file = Tempfile.new(filename) file.binmode file.write(resp.body) file.flush file end end
execute_request(url)
click to toggle source
# File lib/sleeper_rb/utilities/request.rb, line 17 def execute_request(url) response = Net::HTTP.get_response(URI(url)) case response.code.to_i when 200 then JSON.parse(response.body, symbolize_names: true) when 400 then raise BadRequest when 404 then raise NotFound when 429 then raise RateLimitExceeded else raise ServerError end end