Skip to content

Commit c9a5fe1

Browse files
Fixed support of multiple sites
The new version of a hack is somehow different. Though, it attempts to do the same trick altering the underlying connection, it does a reconnect instead of just patching the URL. As a result, this allows different resources to work with distinct `site`s at the same time. See [related upstream issue]( JsonApiClient/json_api_client#215 ) for details.
1 parent b263b64 commit c9a5fe1

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/cirro_io/client/base.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ class Base < JsonApiClient::Resource
44
self.route_format = :dasherized_route
55
self.json_key_format = :dasherized_key
66

7-
# https://github.com/JsonApiClient/json_api_client/issues/215
7+
@setup_connection = lambda do |connection|
8+
connection.use CirroIO::Client::JwtAuthentication
9+
connection.use Faraday::Response::Logger
10+
# connection.use CirroIO::Client::ResponseDebuggingMiddleware # This middleware can be injected during debugging or while adding new specs
11+
end
12+
13+
connection(&@setup_connection)
14+
15+
# HACK: https://github.com/JsonApiClient/json_api_client/issues/215
816
def self.site=(url)
9-
super(url)
10-
connection.faraday.url_prefix = url
17+
super.tap { connection true, &@setup_connection }
1118
end
1219

1320
def self.custom_post(endpoint, payload)
@@ -25,9 +32,3 @@ def self.custom_connection
2532
end
2633
end
2734
end
28-
29-
CirroIO::Client::Base.connection do |connection|
30-
connection.use CirroIO::Client::JwtAuthentication
31-
connection.use Faraday::Response::Logger
32-
# connection.use CirroIO::Client::ResponseDebuggingMiddleware # This middleware can be injected during debugging or while adding new specs
33-
end

0 commit comments

Comments
 (0)