Class: Phaxio::Client Private

Inherits:
Object
  • Object
show all
Defined in:
lib/phaxio/client.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.connFaraday::Connection

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns A new Faraday connection to `Phaxio::Config.api_endpoint`.

Returns:

  • (Faraday::Connection)

    A new Faraday connection to `Phaxio::Config.api_endpoint`.


41
42
43
44
45
46
47
# File 'lib/phaxio/client.rb', line 41

def conn
  Faraday.new(Phaxio.api_endpoint) do |conn|
    conn.request :multipart
    conn.request :url_encoded
    conn.adapter :net_http
  end
end

.request(method, endpoint, params = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Makes a request to the Phaxio API.

Parameters:

  • method (Symbol, String)

    The HTTP method for the request. Currently only `:get`, `:post`, and `:delete` are supported.

  • endpoint (String)

    The endpoint for the API action, relative to `Phaxio::Config.api_endpoint`.

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

    Any parameters to be sent with the request.

Returns:

  • (Object)

    The `“data”` attribute of the deserialized JSON response. Varies based on the API action.


25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/phaxio/client.rb', line 25

def request method, endpoint, params = {}
  params = api_params params
  begin
    response = case method.to_s
               when 'post' then post(endpoint, params)
               when 'get' then get(endpoint, params)
               when 'delete' then delete(endpoint, params)
               else raise ArgumentError, "HTTP method `#{method}` is not supported."
               end
    handle_response response
  rescue Faraday::ConnectionFailed, Faraday::TimeoutError, Faraday::SSLError => error
    raise Error::ApiConnectionError, "Error communicating with Phaxio: #{error}"
  end
end