Module: Fountain::Api::RequestHelper

Included in:
Applicants, AvailableSlots, Funnels, Labels, Notes, Stages
Defined in:
lib/fountain/api/request_helper.rb

Overview

Fountain API HTTP request helper

Constant Summary collapse

DEFAULT_REQUEST_OPTIONS =
{
  method: :get,
  body: nil,
  headers: nil,
  ssl_verify_mode: OpenSSL::SSL::VERIFY_PEER,
  ssl_ca_file: nil
}.freeze

Instance Method Summary collapse

Instance Method Details

#request(path, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/fountain/api/request_helper.rb', line 28

def request(path, options = {})
  options = DEFAULT_REQUEST_OPTIONS.merge(options)

  raise Fountain::InvalidMethodError unless %i[get post put delete].include? options[:method]

  http = create_http(options)
  req = create_request(path, options)
  http.start { http.request(req) }
end

#request_json(path, options = {}) ⇒ Object



21
22
23
24
25
26
# File 'lib/fountain/api/request_helper.rb', line 21

def request_json(path, options = {})
  expected_response = options.delete :expected_response
  response = request path, options
  check_response response, expected_response
  parse_response response.body
end