class CmQuiz::ProjectAPI

Constants

REQUEST_TIMEOUT

Public Class Methods

new(endpoint) click to toggle source
# File lib/cm_quiz/project_api.rb, line 16
def initialize(endpoint)
  @endpoint = endpoint
end

Public Instance Methods

request(verb, path, options = {}) click to toggle source
# File lib/cm_quiz/project_api.rb, line 20
def request(verb, path, options = {})
  url = @endpoint + path

  query = options[:query]
  body = options[:body] ? options[:body].to_json : options[:body]
  headers = { 'Content-Type' => 'application/json' }.merge(options[:headers] || {})

  http_options = {
    query: query,
    body: body,
    headers: headers,
    timeout: REQUEST_TIMEOUT
  }
  res = HTTParty.send(verb, url, http_options)

  raise PerformFailed.new("[#{res.code}]: #{res.body}", res) unless res.success?

  res
end