Module: OpConnect::Connection

Included in:
Client
Defined in:
lib/op_connect/connection.rb

Overview

Network layer for API clients.

Instance Method Summary collapse

Instance Method Details

#connectionFaraday::Client

Connection object for the 1Password Connect API.

Returns:

  • (Faraday::Client)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/op_connect/connection.rb', line 69

def connection
  @connection ||= Faraday.new(api_endpoint) do |http|
    http.headers[:user_agent] = user_agent

    http.request :authorization, :Bearer, access_token
    http.request :json

    http.use OpConnect::Response::RaiseError

    http.response :dates
    http.response :json, content_type: "application/json"

    http.adapter adapter, @stubs
  end
end

#delete(url, params: {}, headers: {}) ⇒ Faraday::Response

Make an HTTP DELETE request.

Parameters:

  • url (String)

    The path, relative to OpConnect::Configurable#api_endpoint.

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

    Query params for the request.

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

    Header params for the request.

Returns:

  • (Faraday::Response)


61
62
63
# File 'lib/op_connect/connection.rb', line 61

def delete(url, params: {}, headers: {})
  request :delete, url, params, headers
end

#get(url, params: {}, headers: {}) ⇒ Faraday::Response

Make an HTTP GET request.

Parameters:

  • url (String)

    The path, relative to OpConnect::Configurable#api_endpoint.

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

    Query parameters for the request.

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

    Header params for the request.

Returns:

  • (Faraday::Response)


13
14
15
# File 'lib/op_connect/connection.rb', line 13

def get(url, params: {}, headers: {})
  request :get, url, params, headers
end

#last_responseFaraday::Response

Response for the last HTTP request.

Returns:

  • (Faraday::Response)


89
90
91
# File 'lib/op_connect/connection.rb', line 89

def last_response
  @last_response if defined? @last_response
end

#patch(url, body:, headers: {}) ⇒ Faraday::Response

Make an HTTP PATCH request.

Parameters:

  • url (String)

    The path, relative to OpConnect::Configurable#api_endpoint.

  • body (Hash)

    Body params for the request.

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

    Header params for the request.

Returns:

  • (Faraday::Response)


49
50
51
# File 'lib/op_connect/connection.rb', line 49

def patch(url, body:, headers: {})
  request :patch, url, body, headers
end

#post(url, body:, headers: {}) ⇒ Faraday::Response

Make an HTTP POST request.

Parameters:

  • url (String)

    The path, relative to OpConnect::Configurable#api_endpoint.

  • body (Hash)

    Body params for the request.

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

    Header params for the request.

Returns:

  • (Faraday::Response)


25
26
27
# File 'lib/op_connect/connection.rb', line 25

def post(url, body:, headers: {})
  request :post, url, body, headers
end

#put(url, body:, headers: {}) ⇒ Faraday::Response

Make an HTTP PUT request.

Parameters:

  • url (String)

    The path, relative to OpConnect::Configurable#api_endpoint.

  • body (Hash)

    Body params for the request.

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

    Header params for the request.

Returns:

  • (Faraday::Response)


37
38
39
# File 'lib/op_connect/connection.rb', line 37

def put(url, body:, headers: {})
  request :put, url, body, headers
end