Module: ActiveProject::Connections::Rest

Includes:
Base, Pagination
Included in:
Adapters::Basecamp::Connection, Adapters::Fizzy::Connection, Adapters::Jira::Connection, Adapters::Trello::Connection
Defined in:
lib/active_project/connections/rest.rb

Overview

Reusable REST connection logic for normal, boring APIs like Jira, Basecamp, and Trello. You know, ones that don’t require a decoder ring and a theological debate to use.

Constant Summary

Constants included from HttpClient

HttpClient::DEFAULT_HEADERS, HttpClient::DEFAULT_RETRY_OPTS

Instance Attribute Summary

Attributes included from HttpClient

#connection, #last_response

Instance Method Summary collapse

Methods included from Pagination

#each_edge, #each_page

Methods included from HttpClient

#build_connection, #request

Methods included from Base

#parse_link_header

Instance Method Details

#init_rest(base_url:, auth_middleware:, extra_headers: {}, retry_options: {}) {|conn| ... } ⇒ Object

Must be called from the concrete adapter’s initialize.

Unlike GraphQL, this one doesn’t need you to bend the knee or cite the Book of Steve Job.

Yield Parameters:

  • conn (Faraday::Connection)

    A lovely, dependable object where you slap on your auth.



15
16
17
18
19
20
21
22
# File 'lib/active_project/connections/rest.rb', line 15

def init_rest(base_url:, auth_middleware:, extra_headers: {}, retry_options: {})
  build_connection(
    base_url: base_url,
    auth_middleware: auth_middleware,
    extra_headers: extra_headers,
    retry_options: retry_options
  )
end

#request_rest(method, path, body = nil, query = nil, headers = {}) ⇒ Object

Wrapper around HttpClient#request. Adapters may override this if their APIs have… quirks (read: sins).



26
27
28
29
30
# File 'lib/active_project/connections/rest.rb', line 26

def request_rest(method, path, body = nil, query = nil, headers = {})
  request(method, path, body: body, query: query, headers: headers)
rescue Faraday::Error => e
  raise map_faraday_error(e) # Wrap Faraday errors in our custom trauma response.
end