Class: Hanko::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/hanko/connection.rb

Overview

Low-level HTTP wrapper around Faraday.

Configures the Faraday connection with authentication headers, timeouts, and the Middleware::RaiseError middleware.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, adapter: nil) ⇒ Connection

Builds a new Connection from the given configuration.

Parameters:

  • config (Configuration)

    SDK configuration

  • adapter (Array, nil) (defaults to: nil)

    optional Faraday adapter override (for testing)



21
22
23
# File 'lib/hanko/connection.rb', line 21

def initialize(config, adapter: nil)
  @connection = build_connection(config, adapter)
end

Instance Attribute Details

#connectionFaraday::Connection (readonly)

Returns the underlying Faraday connection.

Returns:

  • (Faraday::Connection)

    the underlying Faraday connection



14
15
16
# File 'lib/hanko/connection.rb', line 14

def connection
  @connection
end

Instance Method Details

#delete(path, params = {}) ⇒ Faraday::Response

Performs an HTTP DELETE request.

Parameters:

  • path (String)

    the request path

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

    query parameters

Returns:

  • (Faraday::Response)


66
67
68
# File 'lib/hanko/connection.rb', line 66

def delete(path, params = {})
  connection.delete(path, params)
end

#get(path, params = {}) ⇒ Faraday::Response

Performs an HTTP GET request.

Parameters:

  • path (String)

    the request path

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

    query parameters

Returns:

  • (Faraday::Response)


30
31
32
# File 'lib/hanko/connection.rb', line 30

def get(path, params = {})
  connection.get(path, params)
end

#patch(path, body = {}) ⇒ Faraday::Response

Performs an HTTP PATCH request with a JSON body.

Parameters:

  • path (String)

    the request path

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

    the request body (serialized to JSON)

Returns:

  • (Faraday::Response)


57
58
59
# File 'lib/hanko/connection.rb', line 57

def patch(path, body = {})
  connection.patch(path, JSON.generate(body))
end

#post(path, body = {}) ⇒ Faraday::Response

Performs an HTTP POST request with a JSON body.

Parameters:

  • path (String)

    the request path

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

    the request body (serialized to JSON)

Returns:

  • (Faraday::Response)


39
40
41
# File 'lib/hanko/connection.rb', line 39

def post(path, body = {})
  connection.post(path, JSON.generate(body))
end

#put(path, body = {}) ⇒ Faraday::Response

Performs an HTTP PUT request with a JSON body.

Parameters:

  • path (String)

    the request path

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

    the request body (serialized to JSON)

Returns:

  • (Faraday::Response)


48
49
50
# File 'lib/hanko/connection.rb', line 48

def put(path, body = {})
  connection.put(path, JSON.generate(body))
end