ruby-lokalise-api 4.5.1 → 5.0.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: e3db69f1caef4a81c8cb7da9cafb25e68dc4d98abcf7c5806fb748370cd5a335
4
- data.tar.gz: 22e61446ba7bb1b9e0a446c2a0411e1f0fa27ef7615d78fc1eb50f4da9b63411
3
+ metadata.gz: b99a57388157ac9dea3e17b78cf19b27ada718b172b9b5e91230e4b0772073f2
4
+ data.tar.gz: fff194faef3d317f122987fc866c9358f3169dbf8d5a1d52fdf5d810bff0cb84
5
5
  SHA512:
6
- metadata.gz: 03b8381002e892638238ecd2fcd50f3052f7f18e454dab05e3962fbfe61d36b17be3488ce9af3eaaf64733684e25c7f888a24a350601672f3bfc493ac6670c22
7
- data.tar.gz: 0dc3679409dd32bf1eeac182a17b21114b2233bc7b9dc33d0e74bae48f9361557d067c576cba49f90b773dd74b304157b54d58e8e2e67550511fd275c22944e6
6
+ metadata.gz: 478a91cc6130208809c783ac145270d89d3a059d76d9b011133a2e62b8b82bee8d9011004945cfb02b9cd950699f45d6354522281904aaf61b885935aee28dca
7
+ data.tar.gz: 15b10938bcfd13534fbcbea1f7f705b74b39e9f9c02895d413f9c859246a389b020ca4abd1d35c59078388564c7c22995bd558b47aad52b5e233229f34e4bec3
data/README.md CHANGED
@@ -42,7 +42,7 @@ process.status
42
42
  Alternatively instantiate your client with an [OAuth2 token](http://docs.lokalise.com/en/articles/5574713-oauth-2):
43
43
 
44
44
  ```ruby
45
- @client = Lokalise.oauth_client 'YOUR_OAUTH_TOKEN_HERE'
45
+ @client = Lokalise.oauth2_client 'YOUR_OAUTH2_TOKEN_HERE'
46
46
  ```
47
47
 
48
48
  ## Usage
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lokalise
4
+ module BaseRequest
5
+ include Lokalise::JsonHandler
6
+
7
+ private
8
+
9
+ # Get rid of double slashes in the `path`, leading and trailing slash
10
+ def prepare(path)
11
+ path.delete_prefix('/').gsub(%r{//}, '/').gsub(%r{/+\z}, '')
12
+ end
13
+
14
+ def raise_on_error!(status, body)
15
+ respond_with_error(status, body) if status.between?(400, 599) || (body.respond_to?(:has_key?) && body.key?('error'))
16
+ end
17
+
18
+ def respond_with_error(code, body)
19
+ raise(Lokalise::Error, body['error'] || body) unless Lokalise::Error::ERRORS.key? code
20
+
21
+ raise Lokalise::Error::ERRORS[code].from_response(body)
22
+ end
23
+ end
24
+ end
@@ -26,13 +26,12 @@ require 'ruby-lokalise-api/rest/team_user_billing_details'
26
26
  module Lokalise
27
27
  class Client
28
28
  attr_reader :token, :token_header
29
- attr_accessor :timeout, :open_timeout, :enable_compression
29
+ attr_accessor :timeout, :open_timeout
30
30
 
31
31
  def initialize(token, params = {})
32
32
  @token = token
33
33
  @timeout = params.fetch(:timeout, nil)
34
34
  @open_timeout = params.fetch(:open_timeout, nil)
35
- @enable_compression = params.fetch(:enable_compression, false)
36
35
  @token_header = 'x-api-token'
37
36
  end
38
37
 
@@ -6,8 +6,8 @@ module Lokalise
6
6
 
7
7
  def connection(client)
8
8
  Faraday.new(options(client), request_params_for(client)) do |faraday|
9
- faraday.use(:gzip) if client.enable_compression
10
9
  faraday.adapter Faraday.default_adapter
10
+ faraday.request :gzip
11
11
  end
12
12
  end
13
13
 
@@ -18,6 +18,7 @@ module Lokalise
18
18
  headers: {
19
19
  accept: 'application/json',
20
20
  user_agent: "ruby-lokalise-api gem/#{Lokalise::VERSION}",
21
+ accept_encoding: 'gzip,deflate,br',
21
22
  client.token_header => client.token
22
23
  },
23
24
  url: BASE_URL
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lokalise
4
+ module OAuth2
5
+ class Auth
6
+ include Lokalise::OAuth2::Request
7
+
8
+ attr_reader :client_id, :client_secret
9
+
10
+ def initialize(client_id, client_secret)
11
+ @client_id = client_id
12
+ @client_secret = client_secret
13
+ end
14
+
15
+ def auth(scope:, redirect_uri: nil, state: nil)
16
+ scope = scope.join(' ') if scope.is_a?(Array)
17
+
18
+ params = {
19
+ client_id: client_id,
20
+ scope: scope
21
+ }
22
+ params[:state] = state unless state.nil?
23
+ params[:redirect_uri] = redirect_uri unless redirect_uri.nil?
24
+
25
+ _build_url_from params
26
+ end
27
+
28
+ def token(code)
29
+ params = base_params.merge({
30
+ code: code,
31
+ grant_type: 'authorization_code'
32
+ })
33
+ post 'token', params
34
+ end
35
+
36
+ def refresh(token)
37
+ params = base_params.merge({
38
+ refresh_token: token,
39
+ grant_type: 'refresh_token'
40
+ })
41
+ post 'token', params
42
+ end
43
+
44
+ private
45
+
46
+ def base_params
47
+ {
48
+ client_id: client_id,
49
+ client_secret: client_secret
50
+ }
51
+ end
52
+
53
+ def _build_url_from(params)
54
+ URI::HTTPS.build(
55
+ host: BASE_URL.host,
56
+ path: "#{BASE_URL.path}auth",
57
+ query: URI.encode_www_form(params)
58
+ ).to_s
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lokalise
4
+ module OAuth2
5
+ module Connection
6
+ BASE_URL = URI('https://app.lokalise.com/oauth2/')
7
+
8
+ def connection
9
+ Faraday.new(options) { |f| f.adapter Faraday.default_adapter }
10
+ end
11
+
12
+ private
13
+
14
+ def options
15
+ {
16
+ headers: {
17
+ accept: 'application/json',
18
+ user_agent: "ruby-lokalise-api gem/#{Lokalise::VERSION}"
19
+ },
20
+ url: BASE_URL.to_s
21
+ }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lokalise
4
+ module OAuth2
5
+ module Request
6
+ include Lokalise::BaseRequest
7
+ include Lokalise::OAuth2::Connection
8
+
9
+ def post(path, params = {})
10
+ respond_with connection.post(prepare(path), custom_dump(params))
11
+ end
12
+
13
+ private
14
+
15
+ def respond_with(response)
16
+ body = custom_load response.body
17
+ status = response.status
18
+ raise_on_error! status, body
19
+ body
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lokalise
4
- class OAuthClient < Client
4
+ class OAuth2Client < Client
5
5
  def initialize(token, params = {})
6
6
  super(token, params)
7
7
  @token_header = 'Authorization'
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Lokalise
4
4
  module Request
5
+ include Lokalise::BaseRequest
5
6
  include Lokalise::Connection
6
- include Lokalise::JsonHandler
7
7
 
8
8
  # Lokalise returns pagination info in special headers
9
9
  PAGINATION_HEADERS = %w[x-pagination-total-count x-pagination-page-count x-pagination-limit x-pagination-page].freeze
@@ -50,34 +50,23 @@ module Lokalise
50
50
 
51
51
  private
52
52
 
53
- # Get rid of double slashes in the `path`, leading and trailing slash
54
- def prepare(path)
55
- path.delete_prefix('/').gsub(%r{//}, '/').gsub(%r{/+\z}, '')
56
- end
57
-
58
53
  def respond_with(response, client)
59
54
  body = custom_load response.body
60
55
  uri = Addressable::URI.parse response.env.url
61
56
  status = response.status
62
- respond_with_error status, body if status.between?(400, 599) || (body.respond_to?(:has_key?) && body.key?('error'))
57
+ raise_on_error! status, body
63
58
  extract_headers_from(response).
64
59
  merge('content' => body,
65
60
  'client' => client,
66
61
  'path' => uri.path.gsub(%r{/api2/}, ''))
67
62
  end
68
63
 
69
- # Get only pagination headers
64
+ # Keep only pagination headers
70
65
  def extract_headers_from(response)
71
66
  response.
72
67
  headers.
73
68
  to_h.
74
69
  keep_if { |k, _v| PAGINATION_HEADERS.include?(k) }
75
70
  end
76
-
77
- def respond_with_error(code, body)
78
- raise(Lokalise::Error, body['error'] || body) unless Lokalise::Error::ERRORS.key? code
79
-
80
- raise Lokalise::Error::ERRORS[code].from_response(body)
81
- end
82
71
  end
83
72
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lokalise
4
- VERSION = '4.5.1'
4
+ VERSION = '5.0.0'
5
5
  end
@@ -1,19 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'faraday'
4
- require 'faraday_middleware'
4
+ require 'faraday/gzip'
5
5
  require 'yaml'
6
6
  require 'addressable'
7
7
 
8
8
  require 'ruby-lokalise-api/version'
9
9
  require 'ruby-lokalise-api/json_handler'
10
10
  require 'ruby-lokalise-api/connection'
11
+ require 'ruby-lokalise-api/base_request'
11
12
  require 'ruby-lokalise-api/request'
12
13
  require 'ruby-lokalise-api/error'
13
14
  require 'ruby-lokalise-api/utils/string_utils'
14
15
  require 'ruby-lokalise-api/utils/attribute_helpers'
15
16
  require 'ruby-lokalise-api/utils/endpoint_helpers'
16
17
 
18
+ require 'ruby-lokalise-api/oauth2/connection'
19
+ require 'ruby-lokalise-api/oauth2/request'
20
+
17
21
  require 'ruby-lokalise-api/resources/base'
18
22
  require 'ruby-lokalise-api/resources/branch'
19
23
  require 'ruby-lokalise-api/resources/project'
@@ -66,7 +70,9 @@ require 'ruby-lokalise-api/collections/webhook'
66
70
  require 'ruby-lokalise-api/collections/segment'
67
71
 
68
72
  require 'ruby-lokalise-api/client'
69
- require 'ruby-lokalise-api/oauth_client'
73
+ require 'ruby-lokalise-api/oauth2_client'
74
+
75
+ require 'ruby-lokalise-api/oauth2/auth'
70
76
 
71
77
  module Lokalise
72
78
  class << self
@@ -84,18 +90,22 @@ module Lokalise
84
90
  @client = nil
85
91
  end
86
92
 
87
- # Initializes a new OAuthClient object
93
+ # Initializes a new OAuth2Client object
88
94
  #
89
- # @return [Lokalise::OAuthClient]
95
+ # @return [Lokalise::OAuth2Client]
90
96
  # @param token [String]
91
97
  # @param params [Hash]
92
- def oauth_client(token, params = {})
93
- @oauth_client = Lokalise::OAuthClient.new token, params
98
+ def oauth2_client(token, params = {})
99
+ @oauth2_client = Lokalise::OAuth2Client.new token, params
100
+ end
101
+
102
+ # Reset the currently set OAuth2 client
103
+ def reset_oauth2_client!
104
+ @oauth2_client = nil
94
105
  end
95
106
 
96
- # Reset the currently set OAuth client
97
- def reset_oauth_client!
98
- @oauth_client = nil
107
+ def auth_client(client_id, client_secret)
108
+ Lokalise::OAuth2::Auth.new client_id, client_secret
99
109
  end
100
110
  end
101
111
  end
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ['lib']
24
24
 
25
25
  spec.add_dependency 'addressable', '~> 2.5'
26
- spec.add_dependency 'faraday', '~> 1.0'
27
- spec.add_dependency 'faraday_middleware', '~> 1.0'
26
+ spec.add_dependency 'faraday', '~> 2.0'
27
+ spec.add_dependency 'faraday-gzip', '~> 0.1'
28
28
  spec.add_dependency 'json', '>= 1.8.0'
29
29
 
30
30
  spec.add_development_dependency 'codecov', '~> 0.1'
@@ -1,89 +1,68 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe Lokalise::Connection do
4
- include described_class
4
+ let(:dummy) { Class.new { include Lokalise::Connection }.new }
5
5
 
6
6
  let(:project_id) { '803826145ba90b42d5d860.46800099' }
7
7
  let(:key_id) { 44_596_059 }
8
8
 
9
9
  before { Lokalise.reset_client! }
10
10
 
11
- after do
12
- Lokalise.reset_client!
13
- Faraday.default_adapter = :net_http
14
- end
11
+ after { Lokalise.reset_client! }
15
12
 
16
- it 'Authorization header must be present for OAuth client' do
17
- conn = connection test_oauth_client
18
- expect(conn.headers['Authorization']).to eq("Bearer #{test_client.token}")
13
+ it 'Authorization header must be present for OAuth2 client' do
14
+ conn = dummy.connection test_oauth2_client
15
+ expect(conn.headers['Authorization']).to eq(test_oauth2_client.token)
19
16
  expect(conn.headers['X-api-token']).to be_nil
20
17
  end
21
18
 
22
- it 'timeouts and compression should not be set by default but the token must be present' do
23
- conn = connection test_client
19
+ it 'timeouts are not be set by default but the token must be present' do
20
+ conn = dummy.connection test_client
24
21
  expect(conn.options.timeout).to be_nil
25
22
  expect(conn.options.open_timeout).to be_nil
26
23
  expect(conn.headers['X-api-token']).to eq(test_client.token)
27
- expect(conn.builder.handlers).not_to include(FaradayMiddleware::Gzip)
28
24
  end
29
25
 
30
26
  it 'allows to customize timeouts' do
31
27
  custom_client = Lokalise.client(ENV['LOKALISE_API_TOKEN'],
32
28
  open_timeout: 100, timeout: 500)
33
- conn = connection custom_client
29
+ conn = dummy.connection custom_client
34
30
  expect(conn.options.timeout).to eq(500)
35
31
  expect(conn.options.open_timeout).to eq(100)
36
32
  expect(conn.headers['X-api-token']).to eq(custom_client.token)
37
33
 
38
34
  custom_client.timeout = 300
39
35
  custom_client.open_timeout = 200
40
- another_conn = connection custom_client
36
+ another_conn = dummy.connection custom_client
41
37
  expect(another_conn.options.timeout).to eq(300)
42
38
  expect(another_conn.options.open_timeout).to eq(200)
43
39
  end
44
40
 
45
- it 'is possible to customize adapter' do
46
- conn = connection test_client
47
- expect(conn.builder.adapter).to eq(Faraday::Adapter::NetHttp)
48
-
49
- Faraday.default_adapter = :excon
50
-
51
- another_conn = connection test_client
52
- expect(another_conn.builder.adapter).to eq(Faraday::Adapter::Excon)
53
- expect(conn.builder.adapter).to eq(Faraday::Adapter::NetHttp)
54
- end
55
-
56
- it 'allows to customize compression' do
57
- custom_client = Lokalise.client(ENV['LOKALISE_API_TOKEN'], enable_compression: true)
58
- conn = connection custom_client
59
- expect(conn.headers['X-api-token']).to eq(custom_client.token)
60
- expect(conn.builder.handlers).to include(FaradayMiddleware::Gzip)
61
- end
62
-
63
- it 'is possible to enable gzip compression' do
64
- gzip_client = Lokalise.client(ENV['LOKALISE_API_TOKEN'], enable_compression: true)
41
+ it 'works with gzip compression' do
42
+ gzip_client = Lokalise.client(ENV['LOKALISE_API_TOKEN'])
65
43
  keys = VCR.use_cassette('all_keys_gzip') do
66
- gzip_client.keys project_id
44
+ gzip_client.keys project_id, limit: 30
67
45
  end.collection
68
46
 
69
47
  expect(keys.first.key_id).to eq(key_id)
70
48
  end
71
49
 
72
- it 'is possible to disable gzip compression' do
73
- no_gzip_client = Lokalise.client(ENV['LOKALISE_API_TOKEN'], enable_compression: false)
74
- keys = VCR.use_cassette('all_keys_no_gzip') do
75
- no_gzip_client.keys project_id
76
- end.collection
77
-
78
- expect(keys.first.key_id).to eq(key_id)
50
+ it 'gzip compression is on by default' do
51
+ custom_client = Lokalise.client(ENV['LOKALISE_API_TOKEN'])
52
+ conn = dummy.connection custom_client
53
+ expect(conn.headers['X-api-token']).to eq(custom_client.token)
54
+ expect(conn.builder.handlers).to include(Faraday::Gzip::Middleware)
79
55
  end
80
56
 
81
- it 'gzip compression is off by default' do
82
- default_gzip_client = Lokalise.client(ENV['LOKALISE_API_TOKEN'])
83
- keys = VCR.use_cassette('all_keys_default_gzip') do
84
- default_gzip_client.keys project_id
85
- end.collection
57
+ it 'is possible to customize adapter' do
58
+ conn = dummy.connection test_client
59
+ expect(conn.builder.adapter).to eq(Faraday::Adapter::NetHttp)
86
60
 
87
- expect(keys.first.key_id).to eq(key_id)
61
+ Faraday.default_adapter = :test
62
+
63
+ another_conn = dummy.connection test_client
64
+
65
+ expect(another_conn.builder.adapter).to eq(Faraday::Adapter::Test)
66
+ expect(conn.builder.adapter).to eq(Faraday::Adapter::NetHttp)
88
67
  end
89
68
  end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Lokalise::OAuth2::Auth do
4
+ describe '#auth' do
5
+ it 'returns auth code' do
6
+ uri = auth_client.auth scope: 'read_projects'
7
+ expect(uri).to include(described_class::BASE_URL.to_s)
8
+ expect(uri).to include('auth?client_id=')
9
+ expect(uri).to include('&scope=read_projects')
10
+ end
11
+
12
+ it 'allows to pass an array of scopes' do
13
+ scopes = %w[write_projects write_team_groups write_tasks]
14
+ uri = auth_client.auth scope: scopes
15
+ expect(uri).to include(described_class::BASE_URL.to_s)
16
+ expect(uri).to include('auth?client_id=')
17
+ expect(uri).to include("&scope=#{scopes.join('+')}")
18
+ end
19
+
20
+ it 'allows to set redirect_uri' do
21
+ uri = auth_client.auth scope: 'read_projects', redirect_uri: 'http://example.com/callback'
22
+ expect(uri).to include(described_class::BASE_URL.to_s)
23
+ expect(uri).to include('example.com%2Fcallback')
24
+ end
25
+
26
+ it 'allows to set state' do
27
+ state = '123abc'
28
+ uri = auth_client.auth scope: 'read_projects', state: state
29
+ expect(uri).to include(described_class::BASE_URL.to_s)
30
+ expect(uri).to include(state)
31
+ end
32
+ end
33
+
34
+ describe '#token' do
35
+ it 'returns an OAuth2 token' do
36
+ resp = VCR.use_cassette('oauth2/token') do
37
+ auth_client.token ENV['OAUTH2_CODE']
38
+ end
39
+ expect(resp['access_token']).not_to be_nil
40
+ expect(resp['refresh_token']).not_to be_nil
41
+ expect(resp['expires_in']).to eq(3600)
42
+ expect(resp['token_type']).to eq('Bearer')
43
+ end
44
+
45
+ it 'raises an error when the code is invalid' do
46
+ expect do
47
+ VCR.use_cassette('oauth2/token_error') do
48
+ auth_client.token 'incorrect_code'
49
+ end
50
+ end.to raise_error(Lokalise::Error::BadRequest)
51
+ end
52
+ end
53
+
54
+ describe '#refresh' do
55
+ it 'returns a refreshed OAuth2 token' do
56
+ resp = VCR.use_cassette('oauth2/refresh') do
57
+ auth_client.refresh ENV['OAUTH2_REFRESH_TOKEN']
58
+ end
59
+ expect(resp['access_token']).not_to be_nil
60
+ expect(resp['refresh_token']).to be_nil
61
+ expect(resp['expires_in']).to eq(3600)
62
+ expect(resp['token_type']).to eq('Bearer')
63
+ end
64
+
65
+ it 'raises an error when the token is invalid' do
66
+ expect do
67
+ VCR.use_cassette('oauth2/refresh_error') do
68
+ auth_client.refresh 'incorrect_token'
69
+ end
70
+ end.to raise_error(Lokalise::Error::BadRequest)
71
+ end
72
+ end
73
+ end
@@ -10,20 +10,20 @@ RSpec.describe Lokalise::Client do
10
10
  test_client.branches project_id
11
11
  end.collection
12
12
 
13
- expect(branches.count).to eq(1)
13
+ expect(branches.count).to eq(4)
14
14
  end
15
15
 
16
16
  it 'supports pagination' do
17
17
  branches = VCR.use_cassette('all_branches_pagination') do
18
- test_client.branches project_id, limit: 1, page: 1
18
+ test_client.branches project_id, limit: 2, page: 2
19
19
  end
20
20
 
21
- expect(branches.collection.count).to eq(1)
22
- expect(branches.total_results).to eq(1)
23
- expect(branches.total_pages).to eq(1)
24
- expect(branches.results_per_page).to eq(1)
25
- expect(branches.current_page).to eq(1)
26
- expect(branches.collection.first.name).to eq('ruby-branch')
21
+ expect(branches.collection.count).to eq(2)
22
+ expect(branches.total_results).to eq(4)
23
+ expect(branches.total_pages).to eq(2)
24
+ expect(branches.results_per_page).to eq(2)
25
+ expect(branches.current_page).to eq(2)
26
+ expect(branches.collection.first.name).to eq('merge-me')
27
27
  end
28
28
  end
29
29
 
@@ -73,6 +73,19 @@ RSpec.describe Lokalise::Client do
73
73
  expect(project.team_id).to eq(176_692)
74
74
  end
75
75
 
76
+ context 'with OAuth 2 token' do
77
+ it 'creates a project' do
78
+ name = 'OAuth 2 project'
79
+ description = 'Via OAuth 2'
80
+ project = VCR.use_cassette('oauth2/new_project') do
81
+ test_oauth2_client.create_project name: name, description: description
82
+ end
83
+
84
+ expect(project.name).to eq(name)
85
+ expect(project.description).to eq(description)
86
+ end
87
+ end
88
+
76
89
  specify '#update_project' do
77
90
  project = VCR.use_cassette('update_project') do
78
91
  test_client.update_project new_project_id,
@@ -6,7 +6,6 @@ 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
10
9
  end
11
10
 
12
11
  specify '.reset_client!' do
@@ -16,18 +15,17 @@ RSpec.describe Lokalise do
16
15
  expect(current_client).to be_nil
17
16
  end
18
17
 
19
- specify '.oauth_client' do
20
- expect(test_oauth_client).to be_an_instance_of(Lokalise::OAuthClient)
21
- expect(test_oauth_client.token).to eq("Bearer #{ENV['LOKALISE_API_TOKEN']}")
22
- expect(test_oauth_client.timeout).to be_nil
23
- expect(test_oauth_client.open_timeout).to be_nil
24
- expect(test_oauth_client.enable_compression).to be false
18
+ specify '.oauth2_client' do
19
+ expect(test_oauth2_client).to be_an_instance_of(Lokalise::OAuth2Client)
20
+ expect(test_oauth2_client.token).to eq("Bearer #{ENV['OAUTH2_TOKEN']}")
21
+ expect(test_oauth2_client.timeout).to be_nil
22
+ expect(test_oauth2_client.open_timeout).to be_nil
25
23
  end
26
24
 
27
- specify '.reset_oauth_client!' do
28
- expect(test_oauth_client).to be_an_instance_of(Lokalise::OAuthClient)
29
- described_class.reset_oauth_client!
30
- current_oauth_client = described_class.instance_variable_get :@oauth_client
25
+ specify '.reset_oauth2_client!' do
26
+ expect(test_oauth2_client).to be_an_instance_of(Lokalise::OAuth2Client)
27
+ described_class.reset_oauth2_client!
28
+ current_oauth_client = described_class.instance_variable_get :@oauth2_client
31
29
  expect(current_oauth_client).to be_nil
32
30
  end
33
31
 
@@ -45,10 +43,5 @@ RSpec.describe Lokalise do
45
43
  custom_client = described_class.client(ENV['LOKALISE_API_TOKEN'], open_timeout: 100)
46
44
  expect(custom_client.open_timeout).to eq(100)
47
45
  end
48
-
49
- it 'is possible to customize compression' do
50
- custom_client = described_class.client(ENV['LOKALISE_API_TOKEN'], enable_compression: true)
51
- expect(custom_client.enable_compression).to be true
52
- end
53
46
  end
54
47
  end
@@ -5,7 +5,11 @@ module TestClient
5
5
  Lokalise.client(token || ENV['LOKALISE_API_TOKEN'], params)
6
6
  end
7
7
 
8
- def test_oauth_client(token = nil, params = {})
9
- Lokalise.oauth_client(token || ENV['LOKALISE_API_TOKEN'], params)
8
+ def test_oauth2_client(token = nil, params = {})
9
+ Lokalise.oauth2_client(token || ENV['OAUTH2_TOKEN'], params)
10
+ end
11
+
12
+ def auth_client
13
+ Lokalise.auth_client(ENV['OAUTH2_CLIENT_ID'], ENV['OAUTH2_CLIENT_SECRET'])
10
14
  end
11
15
  end
data/spec/support/vcr.rb CHANGED
@@ -7,4 +7,9 @@ VCR.configure do |c|
7
7
  c.hook_into :faraday
8
8
  c.cassette_library_dir = File.join(File.dirname(__FILE__), '..', 'fixtures', 'vcr_cassettes')
9
9
  c.filter_sensitive_data('<LOKALISE_TOKEN>') { ENV.fetch('LOKALISE_API_TOKEN') }
10
+ c.filter_sensitive_data('<OAUTH2_CLIENT_ID>') { ENV.fetch('OAUTH2_CLIENT_ID') }
11
+ c.filter_sensitive_data('<OAUTH2_CLIENT_SECRET>') { ENV.fetch('OAUTH2_CLIENT_SECRET') }
12
+ c.filter_sensitive_data('<OAUTH2_TOKEN>') { ENV.fetch('OAUTH2_TOKEN') }
13
+ c.filter_sensitive_data('<OAUTH2_CODE>') { ENV.fetch('OAUTH2_CODE') }
14
+ c.filter_sensitive_data('<OAUTH2_REFRESH_TOKEN>') { ENV.fetch('OAUTH2_REFRESH_TOKEN') }
10
15
  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.5.1
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Bodrov-Krukowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-27 00:00:00.000000000 Z
11
+ date: 2022-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
33
+ version: '2.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.0'
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: faraday_middleware
42
+ name: faraday-gzip
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.0'
47
+ version: '0.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.0'
54
+ version: '0.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -224,6 +224,7 @@ files:
224
224
  - README.md
225
225
  - Rakefile
226
226
  - lib/ruby-lokalise-api.rb
227
+ - lib/ruby-lokalise-api/base_request.rb
227
228
  - lib/ruby-lokalise-api/client.rb
228
229
  - lib/ruby-lokalise-api/collections/base.rb
229
230
  - lib/ruby-lokalise-api/collections/branch.rb
@@ -253,7 +254,10 @@ files:
253
254
  - lib/ruby-lokalise-api/data/attributes.json
254
255
  - lib/ruby-lokalise-api/error.rb
255
256
  - lib/ruby-lokalise-api/json_handler.rb
256
- - lib/ruby-lokalise-api/oauth_client.rb
257
+ - lib/ruby-lokalise-api/oauth2/auth.rb
258
+ - lib/ruby-lokalise-api/oauth2/connection.rb
259
+ - lib/ruby-lokalise-api/oauth2/request.rb
260
+ - lib/ruby-lokalise-api/oauth2_client.rb
257
261
  - lib/ruby-lokalise-api/request.rb
258
262
  - lib/ruby-lokalise-api/resources/base.rb
259
263
  - lib/ruby-lokalise-api/resources/branch.rb
@@ -310,6 +314,7 @@ files:
310
314
  - spec/lib/ruby-lokalise-api/connection_spec.rb
311
315
  - spec/lib/ruby-lokalise-api/custom_json_parser_spec.rb
312
316
  - spec/lib/ruby-lokalise-api/error_spec.rb
317
+ - spec/lib/ruby-lokalise-api/oauth2/auth_spec.rb
313
318
  - spec/lib/ruby-lokalise-api/rest/branches_spec.rb
314
319
  - spec/lib/ruby-lokalise-api/rest/comments_spec.rb
315
320
  - spec/lib/ruby-lokalise-api/rest/contributors_spec.rb
@@ -364,6 +369,7 @@ test_files:
364
369
  - spec/lib/ruby-lokalise-api/connection_spec.rb
365
370
  - spec/lib/ruby-lokalise-api/custom_json_parser_spec.rb
366
371
  - spec/lib/ruby-lokalise-api/error_spec.rb
372
+ - spec/lib/ruby-lokalise-api/oauth2/auth_spec.rb
367
373
  - spec/lib/ruby-lokalise-api/rest/branches_spec.rb
368
374
  - spec/lib/ruby-lokalise-api/rest/comments_spec.rb
369
375
  - spec/lib/ruby-lokalise-api/rest/contributors_spec.rb