class TelephoneAppointments::Api

Constants

SSL_PORT

Public Instance Methods

post(path, form_data = nil) click to toggle source
# File lib/telephone_appointments/api.rb, line 7
def post(path, form_data = nil)
  uri = URI.parse("#{api_uri}#{path}")
  http = Net::HTTP.new(uri.host, uri.port)
  http.read_timeout = read_timeout
  http.use_ssl = true if uri.port == SSL_PORT
  request = Net::HTTP::Post.new(uri.request_uri, headers)
  request.set_form_data(form_data) if form_data

  TelephoneAppointments::Response.new(http.request(request))
end

Private Instance Methods

api_uri() click to toggle source
# File lib/telephone_appointments/api.rb, line 31
def api_uri
  ENV.fetch('TELEPHONE_APPOINTMENTS_API_URI', 'http://localhost:3001')
end
bearer_token() click to toggle source
# File lib/telephone_appointments/api.rb, line 27
def bearer_token
  ENV['TELEPHONE_APPOINTMENTS_API_BEARER_TOKEN']
end
headers() click to toggle source
# File lib/telephone_appointments/api.rb, line 20
def headers
  {}.tap do |hash|
    hash['Authorization'] = "Bearer #{bearer_token}" if bearer_token
    hash['Accept'] = 'application/json'
  end
end
read_timeout() click to toggle source
# File lib/telephone_appointments/api.rb, line 35
def read_timeout
  ENV.fetch('TELEPHONE_APPOINTMENTS_API_READ_TIMEOUT', 5).to_i
end