class Rubytoolbox::Api

Constants

DEFAULT_URL
VERSION

Attributes

endpoint_url[RW]

Public Class Methods

new(url: DEFAULT_URL) click to toggle source
# File lib/rubytoolbox/api.rb, line 24
def initialize(url: DEFAULT_URL)
  self.endpoint_url = url.clone.freeze
end

Public Instance Methods

compare(*names) click to toggle source
# File lib/rubytoolbox/api.rb, line 28
def compare(*names)
  url = URI(File.join(endpoint_url, "projects", "compare", names.join(",")))

  data = handle_response! Net::HTTP.get_response(url)

  data.fetch("projects").map do |project_data|
    Project.new project_data
  end
end

Private Instance Methods

error_message_for_response(response) click to toggle source
# File lib/rubytoolbox/api.rb, line 49
def error_message_for_response(response)
  data = JSON.parse(response.body)

  "Unexpected response status #{response.code}! #{data['message']}"
rescue JSON::ParserError
  "Unexpected response status #{response.code}! #{response.body}"
end
handle_response!(response) click to toggle source
# File lib/rubytoolbox/api.rb, line 40
def handle_response!(response)
  case response.code.to_i
  when 200
    JSON.parse(response.body)
  else
    raise RequestError, error_message_for_response(response)
  end
end