Class: Svelte::RestClient

Inherits:
Object
  • Object
show all
Defined in:
lib/svelte/rest_client.rb

Overview

Rest client to make requests to the service endpoints

Class Method Summary collapse

Class Method Details

.call(verb:, url:, params: {}, options: {}, headers: {}) ⇒ Faraday::Response

Makes an http call to a given REST endpoint

Parameters:

  • verb (String)

    http verb to use for the request (get, post, put, etc.)

  • url (String)

    request url

  • params (Hash) (defaults to: {})

    parameters to send to the request

  • options (Hash) (defaults to: {})

    options

  • headers (Hash) (defaults to: {})

    headers to be sent along with the request

Returns:

  • (Faraday::Response)

    http response from the service

Raises:

  • (HTTPError)

    if an HTTP layer error occurs, an exception will be raised



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/svelte/rest_client.rb', line 23

def call(verb:, url:, params: {}, options: {}, headers: {})
  connection.send verb, url, params, headers do |request|
    request.options.timeout = options[:timeout] if options[:timeout]
  end
rescue Faraday::TimeoutError => e
  raise HTTPError.new(parent: e)
rescue Faraday::ResourceNotFound => e
  raise HTTPError.new(parent: e)
rescue Faraday::ClientError => e
  raise HTTPError.new(parent: e)
end