lokalise_manager 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0640f0599d5b4967f79d2ced69f63d7cb7edde3e2a3a49336d08d17e5fb4c0f
4
- data.tar.gz: 0766d8cb7f6b478e427f8ef7dd1409d86072a74a4606b026eaa718f6fe4761b5
3
+ metadata.gz: a6dbbda54dc255ed4ec13547b954213e41ab38c90d1520ffe3762d36dc2917f8
4
+ data.tar.gz: a341a91e4fea6ff76e0de87e5efa9660f5a0c5a7659656fbcfa14600fc4937d8
5
5
  SHA512:
6
- metadata.gz: 38a3adfcc0bf4a78f595547cdc3ba2962a4122d8bbeaa7e132d47dc4e76992711e653710a802e395fafcb0c316743607876a10f0914c2633472994891fd4850e
7
- data.tar.gz: 98b2edd83de044615db56ee71d090afa03fcfc7793c55854e322ab466996e0eb46c74f3b22dbdbd44e570f31746d40394912ba39c29dd17337b17e08d0417761
6
+ metadata.gz: 2f5f277f431596f70ee52f45186a972dcd507d1be08f6fc71bd04117556ca803efbe3e8b0d6a123ec6f81b959a5a1c99d9aa63a3189a4700a195fb823ca766e2
7
+ data.tar.gz: c64848ee98ee90cd77507bae719048ac425c60b7f16581b52de6ed6ab2301976487f6999027eab729244c4d3e8b27af1d5d6875c74d8b3d7cbd35112e0ededf1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0 (25-Oct-21)
4
+
5
+ * Add a new option `:use_oauth2_token` which is `false` by default. When enabled, you'll be able to provide a token obtained via [OAuth 2 flow](https://docs.lokalise.com/en/articles/5574713-oauth-2) rather than generated via Lokalise profile. The token should still be provided via the `:api_token` option:
6
+
7
+ ```ruby
8
+ importer = LokaliseManager.importer api_token: 'TOKEN_VIA_OAUTH2', project_id: '123.abc', use_oauth2_token: true
9
+ ```
10
+
3
11
  ## 1.0.0 (14-Oct-21)
4
12
 
5
13
  * Initial release
data/README.md CHANGED
@@ -87,6 +87,7 @@ Please don't forget that Lokalise API has rate limiting and you cannot send more
87
87
  ### Common config
88
88
 
89
89
  * `api_token` (`string`, required) — Lokalise API token with read/write permissions.
90
+ * `use_oauth2_token` (`boolean`) — whether you would like to use a token obtained via [OAuth 2 flow](https://docs.lokalise.com/en/articles/5574713-oauth-2). Defaults to `false`.
90
91
  * `project_id` (`string`, required) — Lokalise project ID. You must have import/export permissions in the specified project.
91
92
  * `locales_path` (`string`) — path to the directory with your translation files. Defaults to `"#{Dir.getwd}/locales"`.
92
93
  * `branch` (`string`) — Lokalise project branch to use. Defaults to `""` (no branch is provided).
@@ -169,6 +170,10 @@ If your translation files are not in YAML format, you will need to adjust the fo
169
170
  * `translations_converter` (`lambda` or `proc`) — converts translations data to a proper format before saving them to a translation file. Defaults to `->(raw_data) { raw_data.to_yaml }`. In the simplest case you may just return the data back, for example `-> (raw_data) { raw_data }`.
170
171
  * `lang_iso_inferer` (`lambda` or `proc`) — infers language ISO code based on the translation file data before uploading it to Lokalise. Defaults to `->(data) { YAML.safe_load(data)&.keys&.first }`.
171
172
 
173
+ ### Customizing JSON parser and network adapter
174
+
175
+ JSON parser and network adapter utilized by lokalise_manager can be customized as well. Please check [ruby-lokalise-api doc](https://lokalise.github.io/ruby-lokalise-api/additional_info/customization) to learn more.
176
+
172
177
  ## Providing config options
173
178
 
174
179
  ### Per-client
@@ -7,13 +7,19 @@ module LokaliseManager
7
7
  attr_writer :import_opts, :import_safe_mode, :export_opts, :locales_path,
8
8
  :file_ext_regexp, :skip_file_export, :branch, :timeouts,
9
9
  :translations_loader, :translations_converter, :lang_iso_inferer,
10
- :max_retries_export, :max_retries_import
10
+ :max_retries_export, :max_retries_import, :use_oauth2_token
11
11
 
12
12
  # Main interface to provide configuration options
13
13
  def config
14
14
  yield self
15
15
  end
16
16
 
17
+ # When enabled, will use OAuth 2 Lokalise client and will require to provide a token obtained via OAuth 2 flow
18
+ # rather than via Lokalise profile
19
+ def use_oauth2_token
20
+ @use_oauth2_token || false
21
+ end
22
+
17
23
  # Full path to directory with translation files
18
24
  def locales_path
19
25
  @locales_path || "#{Dir.getwd}/locales"
@@ -30,7 +30,10 @@ module LokaliseManager
30
30
  #
31
31
  # @return [Lokalise::Client]
32
32
  def api_client
33
- @api_client ||= ::Lokalise.client config.api_token, {enable_compression: true}.merge(config.timeouts)
33
+ client_opts = [config.api_token, {enable_compression: true}.merge(config.timeouts)]
34
+ client_method = config.use_oauth2_token ? :oauth_client : :client
35
+
36
+ @api_client ||= ::Lokalise.send(client_method, *client_opts)
34
37
  end
35
38
 
36
39
  # Resets API client
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LokaliseManager
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
@@ -14,6 +14,11 @@ describe LokaliseManager::GlobalConfig do
14
14
  fake_class.project_id = '123.abc'
15
15
  end
16
16
 
17
+ it 'is possible to set use_oauth2_token' do
18
+ allow(fake_class).to receive(:use_oauth2_token=).with(true)
19
+ fake_class.use_oauth2_token = true
20
+ end
21
+
17
22
  it 'is possible to set file_ext_regexp' do
18
23
  allow(fake_class).to receive(:file_ext_regexp=).with(Regexp.new('.*'))
19
24
  fake_class.file_ext_regexp = Regexp.new('.*')
@@ -94,9 +94,20 @@ describe LokaliseManager::TaskDefinitions::Base do
94
94
  timeout: 500
95
95
  })
96
96
 
97
- expect(described_object.api_client).to be_an_instance_of(Lokalise::Client)
98
- expect(described_object.api_client.open_timeout).to eq(100)
99
- expect(described_object.api_client.timeout).to eq(500)
97
+ client = described_object.api_client
98
+ expect(client).to be_an_instance_of(Lokalise::Client)
99
+ expect(client).not_to be_an_instance_of(Lokalise::OAuthClient)
100
+ expect(client.open_timeout).to eq(100)
101
+ expect(client.timeout).to eq(500)
102
+ end
103
+
104
+ it 'uses .oauth_client when the use_oauth2_token is true' do
105
+ allow(described_object.config).to receive(:use_oauth2_token).and_return(true)
106
+
107
+ client = described_object.api_client
108
+
109
+ expect(client).to be_an_instance_of(Lokalise::OAuthClient)
110
+ expect(client).not_to be_an_instance_of(Lokalise::Client)
100
111
  end
101
112
  end
102
113
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lokalise_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Bodrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-14 00:00:00.000000000 Z
11
+ date: 2021-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-lokalise-api