Skip to content

Commit 3f6ad5f

Browse files
committed
v9.3.0
1 parent ac170dc commit 3f6ad5f

File tree

8 files changed

+50
-5
lines changed

8 files changed

+50
-5
lines changed

docs/_data/additional_items.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
path: customizing-json-parser
2121
- title: Choosing Network Adapter
2222
path: choosing-network-adapter
23+
- title: Configuring API host
24+
path: configuring-api-host
2325
- title: Exception handling
2426
path: exception_handling
2527
sub_paths:

docs/additional_info/changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 9.3.0 (27-Nov-2024)
4+
5+
* Allow to override the API host to send requests to:
6+
7+
```ruby
8+
@client = RubyLokaliseApi.client('LOKALISE_API_TOKEN', api_host: 'http://example.com/api')
9+
```
10+
311
## 9.2.1 (01-Nov-2024)
412

513
* Update dependencies

docs/additional_info/customization.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,17 @@ Faraday.default_adapter = :excon
5757
```
5858

5959
Please note that since the release of Faraday 2, most adapters have to be added manually. Find all supported adapters [on Faraday official website](https://github.com/lostisland/awesome-faraday#adapters).
60+
61+
## Configuring API host
62+
63+
By default, API requests are sent to the `https://api.lokalise.com/api2/` URL that acts as a host.
64+
65+
OAuth 2 authentication requests are sent to `https://app.lokalise.com`.
66+
67+
To override the API host, use the following approach (works for all client types):
68+
69+
```ruby
70+
@client = RubyLokaliseApi.client('LOKALISE_API_TOKEN', api_host: 'http://example.com/api')
71+
```
72+
73+
Then use your `@client` as usual.

lib/ruby_lokalise_api/base_client.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
module RubyLokaliseApi
44
# This class contains the base client. Inherited by Client (regular API client)
5-
# and OAuth2Client (used for OAuth-2 based authentication)
5+
# and OAuth2Client (used for OAuth2-based authentication)
66
class BaseClient
77
include RubyLokaliseApi::Rest
88

9-
attr_reader :token, :token_header
9+
attr_reader :token, :token_header, :api_host
1010
attr_accessor :timeout, :open_timeout
1111

1212
def initialize(token, params = {})
1313
@token = token
1414
@timeout = params.fetch(:timeout, nil)
1515
@open_timeout = params.fetch(:open_timeout, nil)
1616
@token_header = ''
17+
@api_host = params.fetch(:api_host, nil)
1718
end
1819
end
1920
end

lib/ruby_lokalise_api/connection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __base_options(endpoint)
5454
accept: 'application/json',
5555
user_agent: "ruby-lokalise-api gem/#{RubyLokaliseApi::VERSION}"
5656
},
57-
url: endpoint.base_url
57+
url: (endpoint.client.api_host || endpoint.base_url)
5858
}
5959
end
6060

lib/ruby_lokalise_api/oauth2/auth.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module RubyLokaliseApi
44
module OAuth2
55
# This class defines OAuth2 flow
66
class Auth
7-
attr_reader :client_id, :client_secret, :timeout, :open_timeout
7+
attr_reader :client_id, :client_secret, :timeout, :open_timeout, :api_host
88

99
OAUTH2_ENDPOINT = RubyLokaliseApi::Endpoints::OAuth2::OAuth2Endpoint
1010

@@ -13,6 +13,7 @@ def initialize(client_id, client_secret, params = {})
1313
@client_secret = client_secret
1414
@timeout = params[:timeout]
1515
@open_timeout = params[:open_timeout]
16+
@api_host = params[:api_host]
1617
end
1718

1819
# Returns OAuth2 endpoint URI

lib/ruby_lokalise_api/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module RubyLokaliseApi
4-
VERSION = '9.2.1'
4+
VERSION = '9.3.0'
55
end

spec/lib/ruby_lokalise_api/connection_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,25 @@
6969
expect(another_conn.options.open_timeout).to eq(200)
7070
end
7171

72+
it 'uses default endpoint URL' do
73+
custom_client = RubyLokaliseApi.client(ENV.fetch('LOKALISE_API_TOKEN', nil))
74+
75+
custom_endpoint = endpoint name: 'Projects', client: custom_client, params: { query: [project_id] }
76+
77+
conn = dummy.connection custom_endpoint
78+
expect(conn.url_prefix.to_s).to eq(RubyLokaliseApi::Endpoints::MainEndpoint::BASE_URL)
79+
end
80+
81+
it 'allows to override the endpoint URL' do
82+
custom_api_host = 'http://example.com/api'
83+
custom_client = RubyLokaliseApi.client(ENV.fetch('LOKALISE_API_TOKEN', nil), api_host: custom_api_host)
84+
85+
custom_endpoint = endpoint name: 'Projects', client: custom_client, params: { query: [project_id] }
86+
87+
conn = dummy.connection custom_endpoint
88+
expect(conn.url_prefix.to_s).to eq(custom_api_host)
89+
end
90+
7291
it 'gzip compression is on by default' do
7392
custom_client = RubyLokaliseApi.client(ENV.fetch('LOKALISE_API_TOKEN', nil))
7493

0 commit comments

Comments
 (0)