Repository URL to install this package:
|
Version:
0.0.1 ▾
|
module AppointmentPlus
# Defines HTTP request methods
module Request
# Perform an HTTP GET request
def get(path, options = {})
request(:get, path, options)
end
# Perform an HTTP POST request
def post(path, options = {})
request(:post, path, options)
end
private
# Perform an HTTP request
def request(method, path, options)
begin
response = connection.send(method) do |request|
case method
when :get
request.url(path,options)
when :post, :put
request.headers['Content-Type'] = 'application/json'
request.body = options.to_json unless options.empty?
request.url(path)
end
request.options.timeout = 30 # read timeout
request.options.open_timeout = 60 # connection timeout
end
rescue Faraday::ConnectionFailed => e
raise ConnectionError.new(e)
rescue Faraday::TimeoutError => e
raise TimeoutError.new(e)
rescue Faraday::ResourceNotFound => e
raise NotFoundError.new(e)
rescue Faraday::ParsingError => e
raise ParseError.new(e)
rescue Faraday::SSLError => e
raise SSLError.new(e)
rescue => e
raise Error.new(e)
end
Response.create(response.body)
end
end
end