ruby-lokalise-api 4.3.0 → 4.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CONTRIBUTING.md +1 -1
- data/README.md +11 -3
- data/lib/ruby-lokalise-api/client.rb +4 -1
- data/lib/ruby-lokalise-api/collections/base.rb +19 -7
- data/lib/ruby-lokalise-api/collections/segment.rb +15 -0
- data/lib/ruby-lokalise-api/connection.rb +1 -1
- data/lib/ruby-lokalise-api/data/attributes.json +26 -0
- data/lib/ruby-lokalise-api/error.rb +4 -3
- data/lib/ruby-lokalise-api/oauth_client.rb +11 -0
- data/lib/ruby-lokalise-api/request.rb +3 -2
- data/lib/ruby-lokalise-api/resources/base.rb +18 -7
- data/lib/ruby-lokalise-api/resources/branch.rb +3 -1
- data/lib/ruby-lokalise-api/resources/contributor.rb +1 -1
- data/lib/ruby-lokalise-api/resources/custom_translation_status.rb +1 -1
- data/lib/ruby-lokalise-api/resources/key.rb +1 -0
- data/lib/ruby-lokalise-api/resources/key_comment.rb +1 -1
- data/lib/ruby-lokalise-api/resources/order.rb +1 -0
- data/lib/ruby-lokalise-api/resources/payment_card.rb +1 -0
- data/lib/ruby-lokalise-api/resources/project.rb +1 -0
- data/lib/ruby-lokalise-api/resources/project_comment.rb +1 -0
- data/lib/ruby-lokalise-api/resources/project_language.rb +1 -1
- data/lib/ruby-lokalise-api/resources/queued_process.rb +1 -1
- data/lib/ruby-lokalise-api/resources/screenshot.rb +1 -0
- data/lib/ruby-lokalise-api/resources/segment.rb +19 -0
- data/lib/ruby-lokalise-api/resources/snapshot.rb +1 -0
- data/lib/ruby-lokalise-api/resources/task.rb +1 -0
- data/lib/ruby-lokalise-api/resources/team_user.rb +1 -1
- data/lib/ruby-lokalise-api/resources/team_user_billing_details.rb +14 -0
- data/lib/ruby-lokalise-api/resources/team_user_group.rb +1 -1
- data/lib/ruby-lokalise-api/resources/translation.rb +1 -0
- data/lib/ruby-lokalise-api/resources/translation_provider.rb +1 -1
- data/lib/ruby-lokalise-api/resources/webhook.rb +1 -0
- data/lib/ruby-lokalise-api/rest/segments.rb +43 -0
- data/lib/ruby-lokalise-api/rest/team_user_billing_details.rb +34 -0
- data/lib/ruby-lokalise-api/utils/attribute_helpers.rb +3 -1
- data/lib/ruby-lokalise-api/utils/string_utils.rb +24 -18
- data/lib/ruby-lokalise-api/version.rb +1 -1
- data/lib/ruby-lokalise-api.rb +19 -1
- data/ruby-lokalise-api.gemspec +18 -15
- data/spec/lib/ruby-lokalise-api/connection_spec.rb +6 -0
- data/spec/lib/ruby-lokalise-api/error_spec.rb +8 -0
- data/spec/lib/ruby-lokalise-api/rest/contributors_spec.rb +2 -2
- data/spec/lib/ruby-lokalise-api/rest/keys_spec.rb +1 -1
- data/spec/lib/ruby-lokalise-api/rest/languages_spec.rb +2 -2
- data/spec/lib/ruby-lokalise-api/rest/projects_spec.rb +1 -1
- data/spec/lib/ruby-lokalise-api/rest/screenshots_spec.rb +2 -2
- data/spec/lib/ruby-lokalise-api/rest/segments_spec.rb +106 -0
- data/spec/lib/ruby-lokalise-api/rest/snapshots_spec.rb +1 -1
- data/spec/lib/ruby-lokalise-api/rest/tasks_spec.rb +2 -2
- data/spec/lib/ruby-lokalise-api/rest/team_user_billing_details_spec.rb +48 -0
- data/spec/lib/ruby-lokalise-api/rest/team_users_spec.rb +1 -1
- data/spec/lib/ruby-lokalise-api/rest/translations_spec.rb +1 -1
- data/spec/lib/ruby-lokalise-api_spec.rb +16 -1
- data/spec/support/test_client.rb +4 -0
- metadata +19 -10
- data/spec/lib/ruby-lokalise-api/utils/snakecase_spec.rb +0 -19
@@ -3,6 +3,8 @@
|
|
3
3
|
module Lokalise
|
4
4
|
module Utils
|
5
5
|
module AttributeHelpers
|
6
|
+
using Lokalise::Utils::StringUtils
|
7
|
+
|
6
8
|
UNIFIED_RESOURCES = %w[comment language].freeze
|
7
9
|
|
8
10
|
# Returns the name of the API resource for the given class.
|
@@ -40,7 +42,7 @@ module Lokalise
|
|
40
42
|
# @return [String]
|
41
43
|
# @param model_class [String]
|
42
44
|
def id_key_for(model_class)
|
43
|
-
|
45
|
+
get_key name: 'ID_KEY', model_class: model_class
|
44
46
|
end
|
45
47
|
|
46
48
|
# Loads attributes for the given resource based on its name
|
@@ -3,25 +3,31 @@
|
|
3
3
|
# Initial code taken from Facets gem by Rubyworks
|
4
4
|
# https://github.com/rubyworks/facets/blob/master/lib/core/facets/string/snakecase.rb
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
module Lokalise
|
7
|
+
module Utils
|
8
|
+
module StringUtils
|
9
|
+
refine String do
|
10
|
+
# Underscore a string such that camelcase, dashes and spaces are
|
11
|
+
# replaced by underscores.
|
12
|
+
def snakecase
|
13
|
+
base_class_name.
|
14
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
15
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
16
|
+
tr('-', '_').
|
17
|
+
gsub(/\s/, '_').
|
18
|
+
gsub(/__+/, '_').
|
19
|
+
downcase
|
20
|
+
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
# Turn `Module::Nested::ClassName` to just `ClassName`
|
23
|
+
def base_class_name
|
24
|
+
split('::').last
|
25
|
+
end
|
23
26
|
|
24
|
-
|
25
|
-
|
27
|
+
def remove_trailing_slash
|
28
|
+
delete_suffix '/'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
data/lib/ruby-lokalise-api.rb
CHANGED
@@ -37,6 +37,8 @@ require 'ruby-lokalise-api/resources/translation_provider'
|
|
37
37
|
require 'ruby-lokalise-api/resources/team_user_group'
|
38
38
|
require 'ruby-lokalise-api/resources/custom_translation_status'
|
39
39
|
require 'ruby-lokalise-api/resources/webhook'
|
40
|
+
require 'ruby-lokalise-api/resources/segment'
|
41
|
+
require 'ruby-lokalise-api/resources/team_user_billing_details'
|
40
42
|
|
41
43
|
require 'ruby-lokalise-api/collections/base'
|
42
44
|
require 'ruby-lokalise-api/collections/branch'
|
@@ -61,8 +63,10 @@ require 'ruby-lokalise-api/collections/translation_provider'
|
|
61
63
|
require 'ruby-lokalise-api/collections/team_user_group'
|
62
64
|
require 'ruby-lokalise-api/collections/custom_translation_status'
|
63
65
|
require 'ruby-lokalise-api/collections/webhook'
|
66
|
+
require 'ruby-lokalise-api/collections/segment'
|
64
67
|
|
65
68
|
require 'ruby-lokalise-api/client'
|
69
|
+
require 'ruby-lokalise-api/oauth_client'
|
66
70
|
|
67
71
|
module Lokalise
|
68
72
|
class << self
|
@@ -72,12 +76,26 @@ module Lokalise
|
|
72
76
|
# @param token [String]
|
73
77
|
# @param params [Hash]
|
74
78
|
def client(token, params = {})
|
75
|
-
@client
|
79
|
+
@client = Lokalise::Client.new token, params
|
76
80
|
end
|
77
81
|
|
78
82
|
# Reset the currently set client
|
79
83
|
def reset_client!
|
80
84
|
@client = nil
|
81
85
|
end
|
86
|
+
|
87
|
+
# Initializes a new OAuthClient object
|
88
|
+
#
|
89
|
+
# @return [Lokalise::OAuthClient]
|
90
|
+
# @param token [String]
|
91
|
+
# @param params [Hash]
|
92
|
+
def oauth_client(token, params = {})
|
93
|
+
@oauth_client = Lokalise::OAuthClient.new token, params
|
94
|
+
end
|
95
|
+
|
96
|
+
# Reset the currently set OAuth client
|
97
|
+
def reset_oauth_client!
|
98
|
+
@oauth_client = nil
|
99
|
+
end
|
82
100
|
end
|
83
101
|
end
|
data/ruby-lokalise-api.gemspec
CHANGED
@@ -5,7 +5,7 @@ require File.expand_path('lib/ruby-lokalise-api/version', __dir__)
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'ruby-lokalise-api'
|
7
7
|
spec.version = Lokalise::VERSION
|
8
|
-
spec.authors = ['Ilya Bodrov']
|
8
|
+
spec.authors = ['Ilya Bodrov-Krukowski']
|
9
9
|
spec.email = ['golosizpru@gmail.com']
|
10
10
|
spec.summary = 'Ruby interface to the Lokalise API'
|
11
11
|
spec.description = 'Opinionated Ruby client for the Lokalise platform API allowing to work with translations, projects, users and other resources as with Ruby objects.'
|
@@ -22,19 +22,22 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.extra_rdoc_files = ['README.md']
|
23
23
|
spec.require_paths = ['lib']
|
24
24
|
|
25
|
-
spec.add_dependency 'addressable',
|
26
|
-
spec.add_dependency 'faraday',
|
27
|
-
spec.add_dependency 'faraday_middleware',
|
28
|
-
spec.add_dependency 'json',
|
25
|
+
spec.add_dependency 'addressable', '~> 2.5'
|
26
|
+
spec.add_dependency 'faraday', '~> 1.0'
|
27
|
+
spec.add_dependency 'faraday_middleware', '~> 1.0'
|
28
|
+
spec.add_dependency 'json', '>= 1.8.0'
|
29
29
|
|
30
|
-
spec.add_development_dependency 'codecov',
|
31
|
-
spec.add_development_dependency 'dotenv',
|
32
|
-
spec.add_development_dependency 'oj',
|
33
|
-
spec.add_development_dependency 'rake',
|
34
|
-
spec.add_development_dependency 'rspec',
|
35
|
-
spec.add_development_dependency 'rubocop',
|
36
|
-
spec.add_development_dependency 'rubocop-performance',
|
37
|
-
spec.add_development_dependency 'rubocop-rspec',
|
38
|
-
spec.add_development_dependency 'simplecov',
|
39
|
-
spec.add_development_dependency 'vcr',
|
30
|
+
spec.add_development_dependency 'codecov', '~> 0.1'
|
31
|
+
spec.add_development_dependency 'dotenv', '~> 2.5'
|
32
|
+
spec.add_development_dependency 'oj', '~> 3.10'
|
33
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.6'
|
35
|
+
spec.add_development_dependency 'rubocop', '~> 1.6'
|
36
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.5'
|
37
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.0'
|
38
|
+
spec.add_development_dependency 'simplecov', '~> 0.16'
|
39
|
+
spec.add_development_dependency 'vcr', '~> 6.0'
|
40
|
+
spec.metadata = {
|
41
|
+
'rubygems_mfa_required' => 'true'
|
42
|
+
}
|
40
43
|
end
|
@@ -13,6 +13,12 @@ RSpec.describe Lokalise::Connection do
|
|
13
13
|
Faraday.default_adapter = :net_http
|
14
14
|
end
|
15
15
|
|
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}")
|
19
|
+
expect(conn.headers['X-api-token']).to be_nil
|
20
|
+
end
|
21
|
+
|
16
22
|
it 'timeouts and compression should not be set by default but the token must be present' do
|
17
23
|
conn = connection test_client
|
18
24
|
expect(conn.options.timeout).to be_nil
|
@@ -15,6 +15,14 @@ RSpec.describe Lokalise::Error do
|
|
15
15
|
end.to raise_error(described_class)
|
16
16
|
end
|
17
17
|
|
18
|
+
it 'handles an exception when the response does not contain an error key' do
|
19
|
+
expect do
|
20
|
+
VCR.use_cassette('error_no_error_key') do
|
21
|
+
get 'projects', Lokalise.client('invalid')
|
22
|
+
end
|
23
|
+
end.to raise_error(Lokalise::Error::BadRequest)
|
24
|
+
end
|
25
|
+
|
18
26
|
it 'raises BadRequest when API token is invalid' do
|
19
27
|
expect do
|
20
28
|
VCR.use_cassette('error_invalid_token') do
|
@@ -106,7 +106,7 @@ RSpec.describe Lokalise::Client do
|
|
106
106
|
languages: [{lang_iso: 'en'}]
|
107
107
|
end.collection.first
|
108
108
|
|
109
|
-
expect(contributor.client).to eq(test_client)
|
109
|
+
expect(contributor.client.token).to eq(test_client.token)
|
110
110
|
expect(contributor.fullname).to eq('chained')
|
111
111
|
|
112
112
|
id = contributor.user_id
|
@@ -116,7 +116,7 @@ RSpec.describe Lokalise::Client do
|
|
116
116
|
contributor.update fullname: 'updated!'
|
117
117
|
end
|
118
118
|
|
119
|
-
expect(updated_contributor.client).to eq(test_client)
|
119
|
+
expect(updated_contributor.client.token).to eq(test_client.token)
|
120
120
|
expect(updated_contributor.fullname).to eq('updated!')
|
121
121
|
expect(updated_contributor.user_id).to eq(id)
|
122
122
|
expect(updated_contributor.path).to eq(path)
|
@@ -160,7 +160,7 @@ RSpec.describe Lokalise::Client do
|
|
160
160
|
key.update key_name: 'updated!'
|
161
161
|
end
|
162
162
|
|
163
|
-
expect(updated_key.client).to eq(test_client)
|
163
|
+
expect(updated_key.client.token).to eq(test_client.token)
|
164
164
|
expect(updated_key.key_name['ios']).to eq('updated!')
|
165
165
|
expect(updated_key.path).to eq(path)
|
166
166
|
|
@@ -109,7 +109,7 @@ RSpec.describe Lokalise::Client do
|
|
109
109
|
test_client.create_languages project_id, lang_iso: 'ab', custom_name: 'chained lang'
|
110
110
|
end.collection.first
|
111
111
|
|
112
|
-
expect(language.client).to eq(test_client)
|
112
|
+
expect(language.client.token).to eq(test_client.token)
|
113
113
|
expect(language.lang_name).to eq('chained lang')
|
114
114
|
|
115
115
|
path = language.path
|
@@ -118,7 +118,7 @@ RSpec.describe Lokalise::Client do
|
|
118
118
|
language.update lang_name: 'updated!'
|
119
119
|
end
|
120
120
|
|
121
|
-
expect(updated_language.client).to eq(test_client)
|
121
|
+
expect(updated_language.client.token).to eq(test_client.token)
|
122
122
|
expect(updated_language.lang_name).to eq('updated!')
|
123
123
|
expect(updated_language.lang_id).to eq(language.lang_id)
|
124
124
|
expect(updated_language.path).to eq(path)
|
@@ -115,7 +115,7 @@ RSpec.describe Lokalise::Client do
|
|
115
115
|
project.update name: 'updated!'
|
116
116
|
end
|
117
117
|
|
118
|
-
expect(updated_project.client).to eq(test_client)
|
118
|
+
expect(updated_project.client.token).to eq(test_client.token)
|
119
119
|
expect(updated_project.name).to eq('updated!')
|
120
120
|
expect(updated_project.path).to eq(path)
|
121
121
|
|
@@ -91,7 +91,7 @@ RSpec.describe Lokalise::Client do
|
|
91
91
|
end.collection.first
|
92
92
|
end
|
93
93
|
|
94
|
-
expect(screenshot.client).to eq(test_client)
|
94
|
+
expect(screenshot.client.token).to eq(test_client.token)
|
95
95
|
expect(screenshot.title).to eq('chained screen')
|
96
96
|
|
97
97
|
path = screenshot.path
|
@@ -100,7 +100,7 @@ RSpec.describe Lokalise::Client do
|
|
100
100
|
screenshot.update title: 'updated!'
|
101
101
|
end
|
102
102
|
|
103
|
-
expect(updated_screenshot.client).to eq(test_client)
|
103
|
+
expect(updated_screenshot.client.token).to eq(test_client.token)
|
104
104
|
expect(updated_screenshot.title).to eq('updated!')
|
105
105
|
expect(updated_screenshot.screenshot_id).to eq(screenshot.screenshot_id)
|
106
106
|
expect(updated_screenshot.path).to eq(path)
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Lokalise::Client do
|
4
|
+
let(:project_id) { '39066161618d4ecb9fdc12.00274309' }
|
5
|
+
let(:key_id) { 129_358_815 }
|
6
|
+
|
7
|
+
describe '#segments' do
|
8
|
+
it 'returns all segments for a key under lang_iso' do
|
9
|
+
segments = VCR.use_cassette('all_key_segments') do
|
10
|
+
test_client.segments project_id, key_id, 'en'
|
11
|
+
end.collection
|
12
|
+
|
13
|
+
expect(segments.count).to eq(4)
|
14
|
+
expect(segments.first.value).to eq('Hello!')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#segment' do
|
19
|
+
it 'returns a single segment' do
|
20
|
+
lang_iso = 'en'
|
21
|
+
segment_number = 2
|
22
|
+
|
23
|
+
segment = VCR.use_cassette('key_segment') do
|
24
|
+
test_client.segment project_id, key_id, lang_iso, segment_number
|
25
|
+
end
|
26
|
+
|
27
|
+
expect(segment.key_id).to eq(key_id)
|
28
|
+
expect(segment.segment_number).to eq(segment_number)
|
29
|
+
expect(segment.language_iso).to eq(lang_iso)
|
30
|
+
expect(segment.modified_at).to eq('2021-11-22 16:46:50 (Etc/UTC)')
|
31
|
+
expect(segment.modified_at_timestamp).to eq(1_637_599_610)
|
32
|
+
expect(segment.modified_by).to eq(20_181)
|
33
|
+
expect(segment.modified_by_email).to eq('bodrovis@protonmail.com')
|
34
|
+
expect(segment.value).to eq('This is just a simple text.')
|
35
|
+
expect(segment.is_fuzzy).to eq(false)
|
36
|
+
expect(segment.is_reviewed).to eq(false)
|
37
|
+
expect(segment.reviewed_by).to eq(0)
|
38
|
+
expect(segment.words).to eq(6)
|
39
|
+
expect(segment.custom_translation_statuses.first['color']).to eq('#61bd4f')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'allows to pass params' do
|
43
|
+
lang_iso = 'en'
|
44
|
+
segment_number = 2
|
45
|
+
|
46
|
+
segment = VCR.use_cassette('key_segment_params') do
|
47
|
+
test_client.segment project_id, key_id, lang_iso, segment_number, disable_references: '1'
|
48
|
+
end
|
49
|
+
|
50
|
+
expect(segment.segment_number).to eq(segment_number)
|
51
|
+
expect(segment.value).to eq('This is just a simple text.')
|
52
|
+
expect(segment.language_iso).to eq(lang_iso)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
specify '#update_segment' do
|
57
|
+
lang_iso = 'en'
|
58
|
+
segment_number = 3
|
59
|
+
|
60
|
+
segment = VCR.use_cassette('update_key_segment') do
|
61
|
+
test_client.update_segment project_id, key_id, lang_iso, segment_number,
|
62
|
+
value: 'Updated via API',
|
63
|
+
is_reviewed: true
|
64
|
+
end
|
65
|
+
|
66
|
+
expect(segment.segment_number).to eq(segment_number)
|
67
|
+
expect(segment.value).to eq('Updated via API')
|
68
|
+
expect(segment.language_iso).to eq(lang_iso)
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when segment methods are chained' do
|
72
|
+
specify '#reload_data' do
|
73
|
+
lang_iso = 'en'
|
74
|
+
segment_number = 2
|
75
|
+
|
76
|
+
segment = VCR.use_cassette('key_segment') do
|
77
|
+
test_client.segment project_id, key_id, lang_iso, segment_number
|
78
|
+
end
|
79
|
+
|
80
|
+
reloaded_segment = VCR.use_cassette('reload_key_segment') do
|
81
|
+
segment.reload_data
|
82
|
+
end
|
83
|
+
|
84
|
+
expect(reloaded_segment.segment_number).to eq(segment_number)
|
85
|
+
expect(reloaded_segment.key_id).to eq(key_id)
|
86
|
+
end
|
87
|
+
|
88
|
+
specify '#update' do
|
89
|
+
lang_iso = 'en'
|
90
|
+
segment_number = 4
|
91
|
+
|
92
|
+
segment = VCR.use_cassette('another_key_segment') do
|
93
|
+
test_client.segment project_id, key_id, lang_iso, segment_number
|
94
|
+
end
|
95
|
+
|
96
|
+
updated_segment = VCR.use_cassette('update_key_segment_chained') do
|
97
|
+
segment.update value: 'Chain Updated',
|
98
|
+
is_fuzzy: true
|
99
|
+
end
|
100
|
+
|
101
|
+
expect(updated_segment.segment_number).to eq(segment_number)
|
102
|
+
expect(updated_segment.is_fuzzy).to eq(true)
|
103
|
+
expect(updated_segment.value).to eq('Chain Updated')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -81,7 +81,7 @@ RSpec.describe Lokalise::Client do
|
|
81
81
|
new_project.update name: 'Restored and updated'
|
82
82
|
end
|
83
83
|
|
84
|
-
expect(updated_project.client).to eq(test_client)
|
84
|
+
expect(updated_project.client.token).to eq(test_client.token)
|
85
85
|
expect(updated_project.name).to eq('Restored and updated')
|
86
86
|
expect(updated_project.project_id).to eq(new_project.project_id)
|
87
87
|
|
@@ -120,7 +120,7 @@ RSpec.describe Lokalise::Client do
|
|
120
120
|
]
|
121
121
|
end
|
122
122
|
|
123
|
-
expect(task.client).to eq(test_client)
|
123
|
+
expect(task.client.token).to eq(test_client.token)
|
124
124
|
expect(task.title).to eq('chained')
|
125
125
|
|
126
126
|
path = task.path
|
@@ -129,7 +129,7 @@ RSpec.describe Lokalise::Client do
|
|
129
129
|
task.update title: 'updated!'
|
130
130
|
end
|
131
131
|
|
132
|
-
expect(updated_task.client).to eq(test_client)
|
132
|
+
expect(updated_task.client.token).to eq(test_client.token)
|
133
133
|
expect(updated_task.title).to eq('updated!')
|
134
134
|
expect(updated_task.task_id).to eq(task.task_id)
|
135
135
|
expect(updated_task.path).to eq(path)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Lokalise::Client do
|
4
|
+
let(:team_id) { 176_692 }
|
5
|
+
let(:team_id2) { 273_879 }
|
6
|
+
|
7
|
+
specify '#team_user_billing_details' do
|
8
|
+
details = VCR.use_cassette('team_user_billing_details') do
|
9
|
+
test_client.team_user_billing_details team_id
|
10
|
+
end
|
11
|
+
|
12
|
+
expect(details.billing_email).to eq('hello@example.com')
|
13
|
+
expect(details.country_code).to eq('LV')
|
14
|
+
expect(details.zip).to eq('LV-6543')
|
15
|
+
expect(details.state_code).to eq('')
|
16
|
+
expect(details.address1).to eq('Sample line 1')
|
17
|
+
expect(details.address2).to eq('Sample line 2')
|
18
|
+
expect(details.city).to eq('Riga')
|
19
|
+
expect(details.phone).to eq('+371123456')
|
20
|
+
expect(details.company).to eq('Self-employed')
|
21
|
+
expect(details.vatnumber).to eq('123')
|
22
|
+
end
|
23
|
+
|
24
|
+
specify '#create_team_user_billing_details' do
|
25
|
+
details = VCR.use_cassette('create_team_user_billing_details') do
|
26
|
+
test_client.create_team_user_billing_details team_id2, billing_email: 'ruby@example.com',
|
27
|
+
country_code: 'LV',
|
28
|
+
zip: 'LV-1111'
|
29
|
+
end
|
30
|
+
|
31
|
+
expect(details.billing_email).to eq('ruby@example.com')
|
32
|
+
expect(details.country_code).to eq('LV')
|
33
|
+
expect(details.address1).to eq('')
|
34
|
+
end
|
35
|
+
|
36
|
+
specify '#update_team_user_billing_details' do
|
37
|
+
details = VCR.use_cassette('update_team_user_billing_details') do
|
38
|
+
test_client.update_team_user_billing_details team_id2, billing_email: 'ruby_rspec@example.com',
|
39
|
+
country_code: 'LV',
|
40
|
+
zip: 'LV-1111',
|
41
|
+
address1: 'Addr line 1'
|
42
|
+
end
|
43
|
+
|
44
|
+
expect(details.billing_email).to eq('ruby_rspec@example.com')
|
45
|
+
expect(details.country_code).to eq('LV')
|
46
|
+
expect(details.address1).to eq('Addr line 1')
|
47
|
+
end
|
48
|
+
end
|
@@ -81,7 +81,7 @@ RSpec.describe Lokalise::Client do
|
|
81
81
|
team_user.update role: 'admin'
|
82
82
|
end
|
83
83
|
|
84
|
-
expect(updated_team_user.client).to eq(test_client)
|
84
|
+
expect(updated_team_user.client.token).to eq(test_client.token)
|
85
85
|
expect(updated_team_user.role).to eq('admin')
|
86
86
|
|
87
87
|
delete_response = VCR.use_cassette('delete_team_user_chained') do
|
@@ -110,7 +110,7 @@ RSpec.describe Lokalise::Client do
|
|
110
110
|
translation.update translation: 'chained updated'
|
111
111
|
end
|
112
112
|
|
113
|
-
expect(updated_translation.client).to eq(test_client)
|
113
|
+
expect(updated_translation.client.token).to eq(test_client.token)
|
114
114
|
expect(updated_translation.translation).to eq('chained updated')
|
115
115
|
expect(updated_translation.translation_id).to eq(translation.translation_id)
|
116
116
|
end
|
@@ -12,10 +12,25 @@ RSpec.describe Lokalise do
|
|
12
12
|
specify '.reset_client!' do
|
13
13
|
expect(test_client).to be_an_instance_of(Lokalise::Client)
|
14
14
|
described_class.reset_client!
|
15
|
-
current_client = described_class.instance_variable_get
|
15
|
+
current_client = described_class.instance_variable_get :@client
|
16
16
|
expect(current_client).to be_nil
|
17
17
|
end
|
18
18
|
|
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
|
25
|
+
end
|
26
|
+
|
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
|
31
|
+
expect(current_oauth_client).to be_nil
|
32
|
+
end
|
33
|
+
|
19
34
|
context 'with client params' do
|
20
35
|
before { described_class.reset_client! }
|
21
36
|
|
data/spec/support/test_client.rb
CHANGED
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.
|
4
|
+
version: 4.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Ilya Bodrov
|
7
|
+
- Ilya Bodrov-Krukowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -239,6 +239,7 @@ files:
|
|
239
239
|
- lib/ruby-lokalise-api/collections/project_language.rb
|
240
240
|
- lib/ruby-lokalise-api/collections/queued_process.rb
|
241
241
|
- lib/ruby-lokalise-api/collections/screenshot.rb
|
242
|
+
- lib/ruby-lokalise-api/collections/segment.rb
|
242
243
|
- lib/ruby-lokalise-api/collections/snapshot.rb
|
243
244
|
- lib/ruby-lokalise-api/collections/system_language.rb
|
244
245
|
- lib/ruby-lokalise-api/collections/task.rb
|
@@ -252,6 +253,7 @@ files:
|
|
252
253
|
- lib/ruby-lokalise-api/data/attributes.json
|
253
254
|
- lib/ruby-lokalise-api/error.rb
|
254
255
|
- lib/ruby-lokalise-api/json_handler.rb
|
256
|
+
- lib/ruby-lokalise-api/oauth_client.rb
|
255
257
|
- lib/ruby-lokalise-api/request.rb
|
256
258
|
- lib/ruby-lokalise-api/resources/base.rb
|
257
259
|
- lib/ruby-lokalise-api/resources/branch.rb
|
@@ -267,11 +269,13 @@ files:
|
|
267
269
|
- lib/ruby-lokalise-api/resources/project_language.rb
|
268
270
|
- lib/ruby-lokalise-api/resources/queued_process.rb
|
269
271
|
- lib/ruby-lokalise-api/resources/screenshot.rb
|
272
|
+
- lib/ruby-lokalise-api/resources/segment.rb
|
270
273
|
- lib/ruby-lokalise-api/resources/snapshot.rb
|
271
274
|
- lib/ruby-lokalise-api/resources/system_language.rb
|
272
275
|
- lib/ruby-lokalise-api/resources/task.rb
|
273
276
|
- lib/ruby-lokalise-api/resources/team.rb
|
274
277
|
- lib/ruby-lokalise-api/resources/team_user.rb
|
278
|
+
- lib/ruby-lokalise-api/resources/team_user_billing_details.rb
|
275
279
|
- lib/ruby-lokalise-api/resources/team_user_group.rb
|
276
280
|
- lib/ruby-lokalise-api/resources/translation.rb
|
277
281
|
- lib/ruby-lokalise-api/resources/translation_provider.rb
|
@@ -288,8 +292,10 @@ files:
|
|
288
292
|
- lib/ruby-lokalise-api/rest/projects.rb
|
289
293
|
- lib/ruby-lokalise-api/rest/queued_processes.rb
|
290
294
|
- lib/ruby-lokalise-api/rest/screenshots.rb
|
295
|
+
- lib/ruby-lokalise-api/rest/segments.rb
|
291
296
|
- lib/ruby-lokalise-api/rest/snapshots.rb
|
292
297
|
- lib/ruby-lokalise-api/rest/tasks.rb
|
298
|
+
- lib/ruby-lokalise-api/rest/team_user_billing_details.rb
|
293
299
|
- lib/ruby-lokalise-api/rest/team_user_group.rb
|
294
300
|
- lib/ruby-lokalise-api/rest/team_users.rb
|
295
301
|
- lib/ruby-lokalise-api/rest/teams.rb
|
@@ -316,15 +322,16 @@ files:
|
|
316
322
|
- spec/lib/ruby-lokalise-api/rest/projects_spec.rb
|
317
323
|
- spec/lib/ruby-lokalise-api/rest/queued_processes_spec.rb
|
318
324
|
- spec/lib/ruby-lokalise-api/rest/screenshots_spec.rb
|
325
|
+
- spec/lib/ruby-lokalise-api/rest/segments_spec.rb
|
319
326
|
- spec/lib/ruby-lokalise-api/rest/snapshots_spec.rb
|
320
327
|
- spec/lib/ruby-lokalise-api/rest/tasks_spec.rb
|
328
|
+
- spec/lib/ruby-lokalise-api/rest/team_user_billing_details_spec.rb
|
321
329
|
- spec/lib/ruby-lokalise-api/rest/team_user_groups_spec.rb
|
322
330
|
- spec/lib/ruby-lokalise-api/rest/team_users_spec.rb
|
323
331
|
- spec/lib/ruby-lokalise-api/rest/teams_spec.rb
|
324
332
|
- spec/lib/ruby-lokalise-api/rest/translation_providers_spec.rb
|
325
333
|
- spec/lib/ruby-lokalise-api/rest/translations_spec.rb
|
326
334
|
- spec/lib/ruby-lokalise-api/rest/webhooks_spec.rb
|
327
|
-
- spec/lib/ruby-lokalise-api/utils/snakecase_spec.rb
|
328
335
|
- spec/lib/ruby-lokalise-api_spec.rb
|
329
336
|
- spec/spec_helper.rb
|
330
337
|
- spec/support/test_client.rb
|
@@ -332,7 +339,8 @@ files:
|
|
332
339
|
homepage: https://github.com/lokalise/ruby-lokalise-api
|
333
340
|
licenses:
|
334
341
|
- BSD-3-Clause
|
335
|
-
metadata:
|
342
|
+
metadata:
|
343
|
+
rubygems_mfa_required: 'true'
|
336
344
|
post_install_message:
|
337
345
|
rdoc_options: []
|
338
346
|
require_paths:
|
@@ -348,7 +356,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
348
356
|
- !ruby/object:Gem::Version
|
349
357
|
version: '0'
|
350
358
|
requirements: []
|
351
|
-
rubygems_version: 3.
|
359
|
+
rubygems_version: 3.3.5
|
352
360
|
signing_key:
|
353
361
|
specification_version: 4
|
354
362
|
summary: Ruby interface to the Lokalise API
|
@@ -368,15 +376,16 @@ test_files:
|
|
368
376
|
- spec/lib/ruby-lokalise-api/rest/projects_spec.rb
|
369
377
|
- spec/lib/ruby-lokalise-api/rest/queued_processes_spec.rb
|
370
378
|
- spec/lib/ruby-lokalise-api/rest/screenshots_spec.rb
|
379
|
+
- spec/lib/ruby-lokalise-api/rest/segments_spec.rb
|
371
380
|
- spec/lib/ruby-lokalise-api/rest/snapshots_spec.rb
|
372
381
|
- spec/lib/ruby-lokalise-api/rest/tasks_spec.rb
|
373
|
-
- spec/lib/ruby-lokalise-api/rest/
|
374
|
-
- spec/lib/ruby-lokalise-api/rest/team_users_spec.rb
|
382
|
+
- spec/lib/ruby-lokalise-api/rest/team_user_billing_details_spec.rb
|
375
383
|
- spec/lib/ruby-lokalise-api/rest/team_user_groups_spec.rb
|
376
|
-
- spec/lib/ruby-lokalise-api/rest/
|
384
|
+
- spec/lib/ruby-lokalise-api/rest/team_users_spec.rb
|
385
|
+
- spec/lib/ruby-lokalise-api/rest/teams_spec.rb
|
377
386
|
- spec/lib/ruby-lokalise-api/rest/translation_providers_spec.rb
|
387
|
+
- spec/lib/ruby-lokalise-api/rest/translations_spec.rb
|
378
388
|
- spec/lib/ruby-lokalise-api/rest/webhooks_spec.rb
|
379
|
-
- spec/lib/ruby-lokalise-api/utils/snakecase_spec.rb
|
380
389
|
- spec/lib/ruby-lokalise-api_spec.rb
|
381
390
|
- spec/spec_helper.rb
|
382
391
|
- spec/support/test_client.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe String do
|
4
|
-
let(:snake_result) { 'snake_case' }
|
5
|
-
let(:bc_result) { 'Klass' }
|
6
|
-
|
7
|
-
specify '#snakecase' do
|
8
|
-
expect('SnakeCase'.snakecase).to eq snake_result
|
9
|
-
expect('Snake-Case'.snakecase).to eq snake_result
|
10
|
-
expect('Snake Case'.snakecase).to eq snake_result
|
11
|
-
expect('Snake - Case'.snakecase).to eq snake_result
|
12
|
-
end
|
13
|
-
|
14
|
-
specify '#base_class_name' do
|
15
|
-
expect('Namespace::Nested::Klass'.base_class_name).to eq bc_result
|
16
|
-
expect('Nested::Klass'.base_class_name).to eq bc_result
|
17
|
-
expect('Klass'.base_class_name).to eq bc_result
|
18
|
-
end
|
19
|
-
end
|