ruby-lokalise-api 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0736dd816b0cc92d92a04277d86aaec283aa9d7f7be024c736e1a6b4c91531c
4
- data.tar.gz: 725e7262b0a226db6ae1d20d856eaac895ee11f5b39df15b3167a6b0db1984ec
3
+ metadata.gz: 7d4e828a877250b7e76e2134f9d9bbc8e4749519d0adfcad12fbfa25f65b52a9
4
+ data.tar.gz: 4d8d9236940e3fdd0796b92b09544eab9565c9a41c2e16d589a8f30c07628e4d
5
5
  SHA512:
6
- metadata.gz: 94f10e17e3290f76b95fef30acddc5ab448dd27c064ea6e306fe69af621e2e25e63ed51fa2f919c6421df1eeea6a230b414054c9ceb23fb120aaa7d587b1c192
7
- data.tar.gz: 31d41d8735f06151825eed3db874156ef78bec552e44cb8de8dcdd761878373ed5b6a3c745b918d6474262e681f9166c0e0d551d416254436464248e92821d8e
6
+ metadata.gz: c1d6d1c7f192cd70a60c2f07b4fb70c16e9b7c3bfa1a3c0834eed9569c59f7dca38d042187a5a8b99122905ea0eb3adf7b574f8f41d85763d08b0d50ff03305e
7
+ data.tar.gz: 13dfc2c81e9057dd8ece7513f74d3d0d793040fa9755470f7167f1dd1724d93275a7c75f64ecabfc0da1d43c3ec86e5b9eca73ea87ba191188643b330899b282
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'faraday'
4
+ require 'faraday_middleware'
4
5
  require 'yaml'
5
6
  require 'addressable'
6
7
 
@@ -24,12 +24,13 @@ require 'ruby-lokalise-api/rest/webhooks'
24
24
  module Lokalise
25
25
  class Client
26
26
  attr_reader :token
27
- attr_accessor :timeout, :open_timeout
27
+ attr_accessor :timeout, :open_timeout, :enable_compression
28
28
 
29
29
  def initialize(token, params = {})
30
30
  @token = token
31
31
  @timeout = params.fetch(:timeout, nil)
32
32
  @open_timeout = params.fetch(:open_timeout, nil)
33
+ @enable_compression = params.fetch(:enable_compression, false)
33
34
  end
34
35
 
35
36
  # rubocop:disable Metrics/ParameterLists
@@ -5,7 +5,16 @@ module Lokalise
5
5
  BASE_URL = 'https://api.lokalise.com/api2/'
6
6
 
7
7
  def connection(client)
8
- options = {
8
+ Faraday.new(options(client), request_params_for(client)) do |faraday|
9
+ faraday.use(:gzip) if client.enable_compression
10
+ faraday.adapter Faraday.default_adapter
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def options(client)
17
+ {
9
18
  headers: {
10
19
  accept: 'application/json',
11
20
  user_agent: "ruby-lokalise-api gem/#{Lokalise::VERSION}",
@@ -13,11 +22,8 @@ module Lokalise
13
22
  },
14
23
  url: BASE_URL
15
24
  }
16
- Faraday.new(options, request_params_for(client)) { |faraday| faraday.adapter Faraday.default_adapter }
17
25
  end
18
26
 
19
- private
20
-
21
27
  # Allows to customize request params per-client
22
28
  def request_params_for(client)
23
29
  {request: {timeout: client.timeout, open_timeout: client.open_timeout}}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lokalise
4
- VERSION = '4.2.0'
4
+ VERSION = '4.3.0'
5
5
  end
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_dependency 'addressable', '~> 2.5'
26
26
  spec.add_dependency 'faraday', '~> 1.0'
27
+ spec.add_dependency 'faraday_middleware', '~> 1.0'
27
28
  spec.add_dependency 'json', '>= 1.8.0'
28
29
 
29
30
  spec.add_development_dependency 'codecov', '~> 0.1'
@@ -3,6 +3,9 @@
3
3
  RSpec.describe Lokalise::Connection do
4
4
  include described_class
5
5
 
6
+ let(:project_id) { '803826145ba90b42d5d860.46800099' }
7
+ let(:key_id) { 44_596_059 }
8
+
6
9
  before { Lokalise.reset_client! }
7
10
 
8
11
  after do
@@ -10,11 +13,12 @@ RSpec.describe Lokalise::Connection do
10
13
  Faraday.default_adapter = :net_http
11
14
  end
12
15
 
13
- it 'timeouts should not be set by default but the token must be present' do
16
+ it 'timeouts and compression should not be set by default but the token must be present' do
14
17
  conn = connection test_client
15
18
  expect(conn.options.timeout).to be_nil
16
19
  expect(conn.options.open_timeout).to be_nil
17
20
  expect(conn.headers['X-api-token']).to eq(test_client.token)
21
+ expect(conn.builder.handlers).not_to include(FaradayMiddleware::Gzip)
18
22
  end
19
23
 
20
24
  it 'allows to customize timeouts' do
@@ -42,4 +46,38 @@ RSpec.describe Lokalise::Connection do
42
46
  expect(another_conn.builder.adapter).to eq(Faraday::Adapter::Excon)
43
47
  expect(conn.builder.adapter).to eq(Faraday::Adapter::NetHttp)
44
48
  end
49
+
50
+ it 'allows to customize compression' do
51
+ custom_client = Lokalise.client(ENV['LOKALISE_API_TOKEN'], enable_compression: true)
52
+ conn = connection custom_client
53
+ expect(conn.headers['X-api-token']).to eq(custom_client.token)
54
+ expect(conn.builder.handlers).to include(FaradayMiddleware::Gzip)
55
+ end
56
+
57
+ it 'is possible to enable gzip compression' do
58
+ gzip_client = Lokalise.client(ENV['LOKALISE_API_TOKEN'], enable_compression: true)
59
+ keys = VCR.use_cassette('all_keys_gzip') do
60
+ gzip_client.keys project_id
61
+ end.collection
62
+
63
+ expect(keys.first.key_id).to eq(key_id)
64
+ end
65
+
66
+ it 'is possible to disable gzip compression' do
67
+ no_gzip_client = Lokalise.client(ENV['LOKALISE_API_TOKEN'], enable_compression: false)
68
+ keys = VCR.use_cassette('all_keys_no_gzip') do
69
+ no_gzip_client.keys project_id
70
+ end.collection
71
+
72
+ expect(keys.first.key_id).to eq(key_id)
73
+ end
74
+
75
+ it 'gzip compression is off by default' do
76
+ default_gzip_client = Lokalise.client(ENV['LOKALISE_API_TOKEN'])
77
+ keys = VCR.use_cassette('all_keys_default_gzip') do
78
+ default_gzip_client.keys project_id
79
+ end.collection
80
+
81
+ expect(keys.first.key_id).to eq(key_id)
82
+ end
45
83
  end
@@ -6,6 +6,7 @@ RSpec.describe Lokalise do
6
6
  expect(test_client.token).to eq(ENV['LOKALISE_API_TOKEN'])
7
7
  expect(test_client.timeout).to be_nil
8
8
  expect(test_client.open_timeout).to be_nil
9
+ expect(test_client.enable_compression).to be false
9
10
  end
10
11
 
11
12
  specify '.reset_client!' do
@@ -29,5 +30,10 @@ RSpec.describe Lokalise do
29
30
  custom_client = described_class.client(ENV['LOKALISE_API_TOKEN'], open_timeout: 100)
30
31
  expect(custom_client.open_timeout).to eq(100)
31
32
  end
33
+
34
+ it 'is possible to customize compression' do
35
+ custom_client = described_class.client(ENV['LOKALISE_API_TOKEN'], enable_compression: true)
36
+ expect(custom_client.enable_compression).to be true
37
+ end
32
38
  end
33
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lokalise-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.3.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-04-28 00:00:00.000000000 Z
11
+ date: 2021-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: json
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -334,7 +348,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
334
348
  - !ruby/object:Gem::Version
335
349
  version: '0'
336
350
  requirements: []
337
- rubygems_version: 3.2.15
351
+ rubygems_version: 3.2.23
338
352
  signing_key:
339
353
  specification_version: 4
340
354
  summary: Ruby interface to the Lokalise API