|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
| 3 | +require_relative "request" |
3 | 4 | require_relative "parse_options" |
4 | 5 | require_relative "routes/routes" |
5 | | -require_relative "request" |
6 | 6 |
|
7 | 7 | module Seam |
8 | 8 | module Http |
9 | 9 | class SingleWorkspace |
10 | 10 | include Seam::Routes |
11 | 11 |
|
12 | | - attr_accessor :defaults |
| 12 | + attr_reader :client, :defaults |
13 | 13 |
|
14 | | - def initialize(api_key: nil, personal_access_token: nil, workspace_id: nil, endpoint: nil, |
15 | | - wait_for_action_attempt: true, debug: false) |
16 | | - options = Http::Options.parse_options(api_key: api_key, personal_access_token: personal_access_token, workspace_id: workspace_id, endpoint: endpoint) |
| 14 | + def initialize(client: nil, api_key: nil, personal_access_token: nil, workspace_id: nil, endpoint: nil, |
| 15 | + wait_for_action_attempt: true, faraday_options: {}, faraday_retry_options: {}) |
| 16 | + options = Http::Options.parse_options(api_key: api_key, personal_access_token: personal_access_token, |
| 17 | + workspace_id: workspace_id, endpoint: endpoint) |
17 | 18 | @endpoint = options[:endpoint] |
18 | 19 | @auth_headers = options[:auth_headers] |
19 | | - @debug = debug |
20 | | - @wait_for_action_attempt = wait_for_action_attempt |
21 | 20 | @defaults = Seam::DeepHashAccessor.new({"wait_for_action_attempt" => wait_for_action_attempt}) |
| 21 | + |
| 22 | + @client = client || Seam::Http::Request.create_faraday_client(@endpoint, @auth_headers, faraday_options, |
| 23 | + faraday_retry_options) |
22 | 24 | end |
23 | 25 |
|
24 | 26 | def lts_version |
25 | 27 | Seam::LTS_VERSION |
26 | 28 | end |
27 | 29 |
|
28 | | - def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: false, debug: false) |
29 | | - new(api_key: api_key, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt, debug: debug) |
| 30 | + def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: false, faraday_options: {}, faraday_retry_options: {}) |
| 31 | + new(api_key: api_key, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt, |
| 32 | + faraday_options: faraday_options, faraday_retry_options: faraday_retry_options) |
30 | 33 | end |
31 | 34 |
|
32 | | - def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: false, debug: false) |
33 | | - new(personal_access_token: personal_access_token, workspace_id: workspace_id, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt, debug: debug) |
| 35 | + def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: false, faraday_options: {}, faraday_retry_options: {}) |
| 36 | + new(personal_access_token: personal_access_token, workspace_id: workspace_id, endpoint: endpoint, |
| 37 | + wait_for_action_attempt: wait_for_action_attempt, faraday_options: faraday_options, faraday_retry_options: faraday_retry_options) |
34 | 38 | end |
35 | 39 |
|
36 | 40 | def request_seam_object(method, path, klass, inner_object, config = {}) |
37 | | - response = request_seam(method, path, config) |
38 | | - |
39 | | - data = response[inner_object] |
40 | | - |
| 41 | + response = Seam::Http::Request.request_seam(@client, @endpoint, method, path, config) |
| 42 | + data = response.body[inner_object] |
41 | 43 | klass.load_from_response(data, self) |
42 | 44 | end |
43 | 45 |
|
44 | 46 | def request_seam(method, path, config = {}) |
45 | | - Seam::Request.new( |
46 | | - auth_headers: @auth_headers, |
47 | | - endpoint: @endpoint, |
48 | | - debug: @debug |
49 | | - ).perform( |
50 | | - method, path, config |
51 | | - ) |
| 47 | + Seam::Http::Request.request_seam(@client, @endpoint, method, path, config) |
52 | 48 | end |
53 | 49 | end |
54 | 50 | end |
|
0 commit comments