Skip to content

Commit c159bcc

Browse files
Intorduce Faraday HTTP client (#134)
Co-authored-by: Seam Bot <[email protected]>
1 parent 028e581 commit c159bcc

22 files changed

+292
-206
lines changed

Gemfile.lock

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,123 +2,119 @@ PATH
22
remote: .
33
specs:
44
seam (2.0.0a2)
5-
http (~> 5.2)
5+
faraday (~> 2.7)
6+
faraday-retry (~> 2.2)
67
svix (~> 1.30)
78

89
GEM
910
remote: https://rubygems.org/
1011
specs:
11-
addressable (2.8.6)
12-
public_suffix (>= 2.0.2, < 6.0)
12+
addressable (2.8.7)
13+
public_suffix (>= 2.0.2, < 7.0)
1314
ansi (1.5.0)
1415
ast (2.4.2)
15-
base64 (0.2.0)
16-
bigdecimal (3.1.7)
16+
bigdecimal (3.1.8)
1717
crack (1.0.0)
1818
bigdecimal
1919
rexml
2020
diff-lcs (1.5.1)
21-
docile (1.4.0)
22-
domain_name (0.6.20240107)
21+
docile (1.4.1)
2322
ethon (0.16.0)
2423
ffi (>= 1.15.0)
25-
ffi (1.16.3)
26-
ffi-compiler (1.3.2)
27-
ffi (>= 1.15.5)
28-
rake
24+
faraday (2.12.0)
25+
faraday-net_http (>= 2.0, < 3.4)
26+
json
27+
logger
28+
faraday-net_http (3.3.0)
29+
net-http
30+
faraday-retry (2.2.1)
31+
faraday (~> 2.0)
32+
ffi (1.17.0)
33+
ffi (1.17.0-x86_64-linux-gnu)
2934
gem-release (2.2.2)
30-
hashdiff (1.1.0)
31-
http (5.2.0)
32-
addressable (~> 2.8)
33-
base64 (~> 0.1)
34-
http-cookie (~> 1.0)
35-
http-form_data (~> 2.2)
36-
llhttp-ffi (~> 0.5.0)
37-
http-cookie (1.0.5)
38-
domain_name (~> 0.5)
39-
http-form_data (2.3.0)
35+
hashdiff (1.1.1)
4036
json (2.7.2)
4137
language_server-protocol (3.17.0.3)
4238
lint_roller (1.1.0)
43-
llhttp-ffi (0.5.0)
44-
ffi-compiler (~> 1.0)
45-
rake (~> 13.0)
39+
logger (1.6.1)
4640
multi_json (1.15.0)
47-
parallel (1.24.0)
41+
net-http (0.4.1)
42+
uri
43+
parallel (1.26.3)
4844
parse_gemspec (1.0.0)
4945
parse_gemspec-cli (1.0.0)
5046
multi_json
5147
parse_gemspec
5248
thor
53-
parser (3.3.0.5)
49+
parser (3.3.5.0)
5450
ast (~> 2.4.1)
5551
racc
56-
public_suffix (5.0.5)
57-
racc (1.7.3)
52+
public_suffix (6.0.1)
53+
racc (1.8.1)
5854
rainbow (3.1.1)
5955
rake (13.2.1)
60-
regexp_parser (2.9.0)
61-
rexml (3.2.6)
56+
regexp_parser (2.9.2)
57+
rexml (3.3.8)
6258
rspec (3.13.0)
6359
rspec-core (~> 3.13.0)
6460
rspec-expectations (~> 3.13.0)
6561
rspec-mocks (~> 3.13.0)
66-
rspec-core (3.13.0)
62+
rspec-core (3.13.2)
6763
rspec-support (~> 3.13.0)
68-
rspec-expectations (3.13.0)
64+
rspec-expectations (3.13.3)
6965
diff-lcs (>= 1.2.0, < 2.0)
7066
rspec-support (~> 3.13.0)
71-
rspec-mocks (3.13.0)
67+
rspec-mocks (3.13.2)
7268
diff-lcs (>= 1.2.0, < 2.0)
7369
rspec-support (~> 3.13.0)
7470
rspec-support (3.13.1)
75-
rubocop (1.62.1)
71+
rubocop (1.66.1)
7672
json (~> 2.3)
7773
language_server-protocol (>= 3.17.0)
7874
parallel (~> 1.10)
7975
parser (>= 3.3.0.2)
8076
rainbow (>= 2.2.2, < 4.0)
81-
regexp_parser (>= 1.8, < 3.0)
82-
rexml (>= 3.2.5, < 4.0)
83-
rubocop-ast (>= 1.31.1, < 2.0)
77+
regexp_parser (>= 2.4, < 3.0)
78+
rubocop-ast (>= 1.32.2, < 2.0)
8479
ruby-progressbar (~> 1.7)
8580
unicode-display_width (>= 2.4.0, < 3.0)
86-
rubocop-ast (1.31.2)
87-
parser (>= 3.3.0.4)
88-
rubocop-performance (1.20.2)
81+
rubocop-ast (1.32.3)
82+
parser (>= 3.3.1.0)
83+
rubocop-performance (1.22.1)
8984
rubocop (>= 1.48.1, < 2.0)
90-
rubocop-ast (>= 1.30.0, < 2.0)
85+
rubocop-ast (>= 1.31.1, < 2.0)
9186
ruby-progressbar (1.13.0)
9287
simplecov (0.22.0)
9388
docile (~> 1.1)
9489
simplecov-html (~> 0.11)
9590
simplecov_json_formatter (~> 0.1)
96-
simplecov-console (0.9.1)
91+
simplecov-console (0.9.2)
9792
ansi
9893
simplecov
9994
terminal-table
100-
simplecov-html (0.12.3)
95+
simplecov-html (0.13.1)
10196
simplecov_json_formatter (0.1.4)
102-
standard (1.35.1)
97+
standard (1.41.1)
10398
language_server-protocol (~> 3.17.0.2)
10499
lint_roller (~> 1.0)
105-
rubocop (~> 1.62.0)
100+
rubocop (~> 1.66.0)
106101
standard-custom (~> 1.0.0)
107-
standard-performance (~> 1.3)
102+
standard-performance (~> 1.5)
108103
standard-custom (1.0.2)
109104
lint_roller (~> 1.0)
110105
rubocop (~> 1.50)
111-
standard-performance (1.3.1)
106+
standard-performance (1.5.0)
112107
lint_roller (~> 1.1)
113-
rubocop-performance (~> 1.20.2)
114-
svix (1.30.0)
108+
rubocop-performance (~> 1.22.0)
109+
svix (1.38.0)
115110
typhoeus (~> 1.0, >= 1.0.1)
116111
terminal-table (3.0.2)
117112
unicode-display_width (>= 1.1.1, < 3)
118-
thor (1.3.1)
113+
thor (1.3.2)
119114
typhoeus (1.4.1)
120115
ethon (>= 0.9.0)
121-
unicode-display_width (2.5.0)
116+
unicode-display_width (2.6.0)
117+
uri (0.13.1)
122118
webmock (3.0.1)
123119
addressable (>= 2.3.6)
124120
crack (>= 0.3.2)

lib/seam.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ def self.new(**args)
1010
Http.new(**args)
1111
end
1212

13-
def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: false, debug: false)
14-
Http.from_api_key(api_key, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt, debug: debug)
13+
def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: false)
14+
Http.from_api_key(api_key, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt)
1515
end
1616

17-
def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: false, debug: false)
18-
Http.from_personal_access_token(personal_access_token, workspace_id, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt, debug: debug)
17+
def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: false)
18+
Http.from_personal_access_token(personal_access_token, workspace_id, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt)
1919
end
2020

2121
def self.lts_version

lib/seam/helpers/action_attempt.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def self.update_action_attempt(action_attempt, client)
4545
}
4646
)
4747

48-
action_attempt.update_from_response(response["action_attempt"])
48+
action_attempt.update_from_response(response.body["action_attempt"])
4949
action_attempt
5050
end
5151
end

lib/seam/http.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ def self.new(**args)
88
Http::SingleWorkspace.new(**args)
99
end
1010

11-
def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: false, debug: false)
12-
Http::SingleWorkspace.from_api_key(api_key, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt,
13-
debug: debug)
11+
def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: false)
12+
Http::SingleWorkspace.from_api_key(api_key, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt)
1413
end
1514

16-
def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: false, debug: false)
15+
def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: false)
1716
Http::SingleWorkspace.from_personal_access_token(personal_access_token, workspace_id, endpoint: endpoint,
18-
wait_for_action_attempt: wait_for_action_attempt, debug: debug)
17+
wait_for_action_attempt: wait_for_action_attempt)
1918
end
2019

2120
class ApiError < StandardError
@@ -40,7 +39,7 @@ class InvalidInputError < ApiError
4039
attr_reader :validation_errors
4140

4241
def initialize(error, status_code, request_id)
43-
super(error, status_code, request_id)
42+
super
4443
@code = "invalid_input"
4544
@validation_errors = error["validation_errors"] || {}
4645
end

lib/seam/http_multi_workspace.rb

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
# frozen_string_literal: true
22

3+
require_relative "request"
34
require_relative "parse_options"
45
require_relative "lts_version"
56
require_relative "auth"
6-
require_relative "request"
77

88
module Seam
99
module Http
1010
class MultiWorkspace
11-
attr_reader :wait_for_action_attempt, :defaults
11+
attr_reader :client, :defaults
1212

13-
def initialize(personal_access_token:, endpoint: nil, wait_for_action_attempt: true)
13+
def initialize(personal_access_token:, endpoint: nil, wait_for_action_attempt: true, faraday_options: {},
14+
faraday_retry_options: {})
1415
@wait_for_action_attempt = wait_for_action_attempt
1516
@defaults = {"wait_for_action_attempt" => wait_for_action_attempt}
1617
@endpoint = Http::Options.get_endpoint(endpoint)
1718
@auth_headers = Http::Auth.get_auth_headers_for_multi_workspace_personal_access_token(personal_access_token)
19+
@client = Seam::Http::Request.create_faraday_client(@endpoint, @auth_headers, faraday_options,
20+
faraday_retry_options)
1821
end
1922

2023
def self.lts_version
@@ -29,29 +32,24 @@ def workspaces
2932
@workspaces ||= WorkspacesProxy.new(Seam::Clients::Workspaces.new(self))
3033
end
3134

32-
def self.from_personal_access_token(personal_access_token, endpoint: nil, wait_for_action_attempt: true)
35+
def self.from_personal_access_token(personal_access_token, endpoint: nil, wait_for_action_attempt: true, faraday_options: {}, faraday_retry_options: {})
3336
new(
3437
personal_access_token: personal_access_token,
3538
endpoint: endpoint,
36-
wait_for_action_attempt: wait_for_action_attempt
39+
wait_for_action_attempt: wait_for_action_attempt,
40+
faraday_options: faraday_options,
41+
faraday_retry_options: faraday_retry_options
3742
)
3843
end
3944

4045
def request_seam_object(method, path, klass, inner_object, config = {})
41-
response = request_seam(method, path, config)
42-
43-
data = response[inner_object]
44-
46+
response = Seam::Http::Request.request_seam(@client, @endpoint, method, path, config)
47+
data = response.body[inner_object]
4548
klass.load_from_response(data, self)
4649
end
4750

4851
def request_seam(method, path, config = {})
49-
Seam::Request.new(
50-
auth_headers: @auth_headers,
51-
endpoint: @endpoint
52-
).perform(
53-
method, path, config
54-
)
52+
Seam::Http::Request.request_seam(@client, @endpoint, method, path, config)
5553
end
5654
end
5755

lib/seam/http_single_workspace.rb

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,50 @@
11
# frozen_string_literal: true
22

3+
require_relative "request"
34
require_relative "parse_options"
45
require_relative "routes/routes"
5-
require_relative "request"
66

77
module Seam
88
module Http
99
class SingleWorkspace
1010
include Seam::Routes
1111

12-
attr_accessor :defaults
12+
attr_reader :client, :defaults
1313

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)
1718
@endpoint = options[:endpoint]
1819
@auth_headers = options[:auth_headers]
19-
@debug = debug
20-
@wait_for_action_attempt = wait_for_action_attempt
2120
@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)
2224
end
2325

2426
def lts_version
2527
Seam::LTS_VERSION
2628
end
2729

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)
3033
end
3134

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)
3438
end
3539

3640
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]
4143
klass.load_from_response(data, self)
4244
end
4345

4446
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)
5248
end
5349
end
5450
end

0 commit comments

Comments
 (0)