ruby-lokalise-api 4.4.0 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/ruby-lokalise-api/client.rb +2 -0
- data/lib/ruby-lokalise-api/collections/base.rb +19 -8
- data/lib/ruby-lokalise-api/collections/segment.rb +15 -0
- data/lib/ruby-lokalise-api/data/attributes.json +26 -0
- data/lib/ruby-lokalise-api/resources/base.rb +12 -3
- data/lib/ruby-lokalise-api/resources/branch.rb +1 -0
- 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 +3 -0
- data/ruby-lokalise-api.gemspec +18 -15
- data/spec/lib/ruby-lokalise-api/rest/segments_spec.rb +106 -0
- data/spec/lib/ruby-lokalise-api/rest/team_user_billing_details_spec.rb +48 -0
- metadata +15 -7
- data/spec/lib/ruby-lokalise-api/utils/snakecase_spec.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e1ed1ea503db64b5bf145288689885a365e35ba9520e692d65b51b311478fb5
|
4
|
+
data.tar.gz: b1636ef5cd3dafb7d1be6ca64ed6c6807c8f6f12f4383039d8312c4ce4f100b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8141fe2f935cf0cc380f9824278235c5d6a0b12bd8daef9d6947556d0b73b9aa9d097f2c9e32833eb2c8261d84331ab476f7ef25b6c69965a2f8781bf3b284ff
|
7
|
+
data.tar.gz: 4bce32a0012e21830e45b12f58fb188395614a2dc64412c2c28fbd95bda4d8519565d0d38eebed1da9b6a2f7976bd0bc61ee28cb49fd466233b03d1843a90fb4
|
data/README.md
CHANGED
@@ -49,6 +49,8 @@ Alternatively instantiate your client with an [OAuth2 token](http://docs.lokalis
|
|
49
49
|
|
50
50
|
Detailed documentation can be found at [lokalise.github.io/ruby-lokalise-api](https://lokalise.github.io/ruby-lokalise-api/).
|
51
51
|
|
52
|
+
You can also check [this repo containing some usage examples](https://github.com/bodrovis-learning/Lokalise-APIv2-Samples) and [this blog post with explanations](https://lokalise.com/blog/lokalise-apiv2-in-practice).
|
53
|
+
|
52
54
|
## License
|
53
55
|
|
54
56
|
This gem is licensed under the [BSD 3 Clause license](https://github.com/lokalise/ruby-lokalise-api/blob/master/LICENSE). Prior to version 4 the license type was MIT.
|
@@ -20,6 +20,8 @@ require 'ruby-lokalise-api/rest/translation_providers'
|
|
20
20
|
require 'ruby-lokalise-api/rest/team_user_group'
|
21
21
|
require 'ruby-lokalise-api/rest/custom_translation_statuses'
|
22
22
|
require 'ruby-lokalise-api/rest/webhooks'
|
23
|
+
require 'ruby-lokalise-api/rest/segments'
|
24
|
+
require 'ruby-lokalise-api/rest/team_user_billing_details'
|
23
25
|
|
24
26
|
module Lokalise
|
25
27
|
class Client
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module Lokalise
|
4
4
|
module Collections
|
5
5
|
class Base
|
6
|
+
using Lokalise::Utils::StringUtils
|
7
|
+
|
6
8
|
extend Lokalise::Request
|
7
9
|
extend Lokalise::Utils::AttributeHelpers
|
8
10
|
include Lokalise::Utils::AttributeHelpers
|
@@ -19,15 +21,8 @@ module Lokalise
|
|
19
21
|
def initialize(response, params = {})
|
20
22
|
produce_collection_for response
|
21
23
|
populate_pagination_data_for response
|
22
|
-
content = response['content']
|
23
|
-
# Project, team id, user id, and branch may not be present in some cases
|
24
|
-
@project_id = content['project_id']
|
25
|
-
@team_id = content['team_id']
|
26
|
-
@user_id = content['user_id']
|
27
|
-
@branch = content['branch']
|
28
24
|
@request_params = params
|
29
|
-
|
30
|
-
@path = response['path']
|
25
|
+
popular_common_attrs response
|
31
26
|
end
|
32
27
|
|
33
28
|
class << self
|
@@ -91,6 +86,8 @@ module Lokalise
|
|
91
86
|
# Dynamically produces collection of resources based on the given response
|
92
87
|
# Collection example: `{ "content": {"comments": [ ... ]} }`
|
93
88
|
def produce_collection_for(response)
|
89
|
+
return unless response['content']
|
90
|
+
|
94
91
|
model_class = self.class.name.base_class_name
|
95
92
|
data_key_plural = data_key_for model_class: model_class, plural: true, collection: true
|
96
93
|
|
@@ -102,6 +99,20 @@ module Lokalise
|
|
102
99
|
'base_path' => response['path']
|
103
100
|
end
|
104
101
|
end
|
102
|
+
|
103
|
+
def popular_common_attrs(response)
|
104
|
+
@client = response['client']
|
105
|
+
@path = response['path']
|
106
|
+
|
107
|
+
return unless response['content']
|
108
|
+
|
109
|
+
content = response['content']
|
110
|
+
# Project, team id, user id, and branch may not be present in some cases
|
111
|
+
@project_id = content['project_id']
|
112
|
+
@team_id = content['team_id']
|
113
|
+
@user_id = content['user_id']
|
114
|
+
@branch = content['branch']
|
115
|
+
end
|
105
116
|
end
|
106
117
|
end
|
107
118
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lokalise
|
4
|
+
module Collections
|
5
|
+
class Segment < Base
|
6
|
+
class << self
|
7
|
+
def endpoint(project_id, key_id, lang_iso, *_args)
|
8
|
+
path_from projects: project_id,
|
9
|
+
keys: key_id,
|
10
|
+
segments: lang_iso
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -134,6 +134,20 @@
|
|
134
134
|
"created_at",
|
135
135
|
"created_at_timestamp"
|
136
136
|
],
|
137
|
+
"segment": [
|
138
|
+
"segment_number",
|
139
|
+
"language_iso",
|
140
|
+
"modified_at",
|
141
|
+
"modified_at_timestamp",
|
142
|
+
"modified_by",
|
143
|
+
"modified_by_email",
|
144
|
+
"value",
|
145
|
+
"is_fuzzy",
|
146
|
+
"is_reviewed",
|
147
|
+
"reviewed_by",
|
148
|
+
"words",
|
149
|
+
"custom_translation_statuses"
|
150
|
+
],
|
137
151
|
"snapshot": [
|
138
152
|
"snapshot_id",
|
139
153
|
"title",
|
@@ -188,6 +202,18 @@
|
|
188
202
|
"created_at_timestamp",
|
189
203
|
"role"
|
190
204
|
],
|
205
|
+
"team_user_billing_details": [
|
206
|
+
"billing_email",
|
207
|
+
"country_code",
|
208
|
+
"zip",
|
209
|
+
"state_code",
|
210
|
+
"address1",
|
211
|
+
"address2",
|
212
|
+
"city",
|
213
|
+
"phone",
|
214
|
+
"company",
|
215
|
+
"vatnumber"
|
216
|
+
],
|
191
217
|
"team_user_group": [
|
192
218
|
"group_id",
|
193
219
|
"name",
|
@@ -3,12 +3,14 @@
|
|
3
3
|
module Lokalise
|
4
4
|
module Resources
|
5
5
|
class Base
|
6
|
+
using Lokalise::Utils::StringUtils
|
7
|
+
|
6
8
|
extend Lokalise::Request
|
7
9
|
extend Lokalise::Utils::AttributeHelpers
|
8
10
|
include Lokalise::Utils::AttributeHelpers
|
9
11
|
extend Lokalise::Utils::EndpointHelpers
|
10
12
|
|
11
|
-
attr_reader :raw_data, :project_id, :client, :path, :branch, :user_id, :team_id
|
13
|
+
attr_reader :raw_data, :project_id, :client, :path, :branch, :user_id, :team_id, :key_id
|
12
14
|
|
13
15
|
# Initializes a new resource based on the response.
|
14
16
|
# `endpoint_generator` is used in cases when a new instance is generated
|
@@ -132,7 +134,7 @@ module Lokalise
|
|
132
134
|
|
133
135
|
def path_with_id(response, id_key, data_key, endpoint_generator = nil)
|
134
136
|
# Some resources do not have ids at all
|
135
|
-
return
|
137
|
+
return unless response['content'] && (response['content'].key?(id_key) || response['content'].key?(data_key))
|
136
138
|
|
137
139
|
# ID of the resource
|
138
140
|
id = id_from response, id_key, data_key
|
@@ -156,9 +158,11 @@ module Lokalise
|
|
156
158
|
# Content may be `{"project_id": '123', ...}` or {"snapshot": {"snapshot_id": '123', ...}}
|
157
159
|
# Sometimes there is an `id_key` but it has a value of `null`
|
158
160
|
# (for example when we do not place the actual order but only check its price).
|
161
|
+
# In rare cases the actual identifier does not have an "_id" suffix
|
162
|
+
# (for segments that have "segment_number" field instead)
|
159
163
|
# Therefore we must explicitly check if the key is present
|
160
164
|
content = response['content']
|
161
|
-
return content[id_key] if content.key?(id_key)
|
165
|
+
return content[id_key] if content.respond_to?(:key?) && content&.key?(id_key)
|
162
166
|
|
163
167
|
content[data_key][id_key]
|
164
168
|
end
|
@@ -166,6 +170,8 @@ module Lokalise
|
|
166
170
|
# Store all resources attributes under the corresponding instance variables.
|
167
171
|
# `ATTRIBUTES` is defined inside resource-specific classes
|
168
172
|
def populate_attributes_for(content)
|
173
|
+
return unless content
|
174
|
+
|
169
175
|
data_key = data_key_for model_class: self.class.name.base_class_name
|
170
176
|
|
171
177
|
self.class.const_get(:ATTRIBUTES).each do |attr|
|
@@ -183,10 +189,13 @@ module Lokalise
|
|
183
189
|
# Some of them may be absent in certain cases.
|
184
190
|
# rubocop:disable Naming/MemoizedInstanceVariableName
|
185
191
|
def extract_common_attributes_for(content)
|
192
|
+
return unless content
|
193
|
+
|
186
194
|
@raw_data = content
|
187
195
|
@project_id ||= content['project_id']
|
188
196
|
@user_id ||= content['user_id']
|
189
197
|
@team_id ||= content['team_id']
|
198
|
+
@key_id ||= content['key_id']
|
190
199
|
@branch ||= content['branch']
|
191
200
|
end
|
192
201
|
# rubocop:enable Naming/MemoizedInstanceVariableName
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lokalise
|
4
|
+
module Resources
|
5
|
+
class Segment < Base
|
6
|
+
DATA_KEY = 'Segment'
|
7
|
+
ID_KEY = 'segment_number'
|
8
|
+
supports :update, [:reload_data, '', :find]
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def endpoint(project_id, key_id, lang_iso, segment_number = nil)
|
12
|
+
path_from projects: project_id,
|
13
|
+
keys: key_id,
|
14
|
+
segments: [lang_iso, segment_number]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lokalise
|
4
|
+
class Client
|
5
|
+
# Returns all segments for the given key and language ISO code
|
6
|
+
#
|
7
|
+
# @see https://app.lokalise.com/api2docs/curl/#transition-list-all-segments-for-key-language-get
|
8
|
+
# @return [Lokalise::Collection::Segments<Lokalise::Resources::Segment>]
|
9
|
+
# @param project_id [String]
|
10
|
+
# @param key_id [String, Integer]
|
11
|
+
# @param lang_iso [String]
|
12
|
+
# @param params [Hash]
|
13
|
+
def segments(project_id, key_id, lang_iso, params = {})
|
14
|
+
c_r Lokalise::Collections::Segment, :all, [project_id, key_id, lang_iso], params
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns a segment under a given number for the given key and language ISO code
|
18
|
+
#
|
19
|
+
# @see https://app.lokalise.com/api2docs/curl/#transition-retrieve-a-segment-for-key-language-get
|
20
|
+
# @return [Lokalise::Resources::Segment]
|
21
|
+
# @param project_id [String]
|
22
|
+
# @param key_id [String, Integer]
|
23
|
+
# @param lang_iso [String]
|
24
|
+
# @params segment_number [Integer, String]
|
25
|
+
# @param params [Hash]
|
26
|
+
def segment(project_id, key_id, lang_iso, segment_number, params = {})
|
27
|
+
c_r Lokalise::Resources::Segment, :find, [project_id, key_id, lang_iso, segment_number], params
|
28
|
+
end
|
29
|
+
|
30
|
+
# Updates a segment under a given number for the given key and language ISO code
|
31
|
+
#
|
32
|
+
# @see https://app.lokalise.com/api2docs/curl/#transition-update-a-segment-post
|
33
|
+
# @return [Lokalise::Resources::Segment]
|
34
|
+
# @param project_id [String]
|
35
|
+
# @param key_id [String, Integer]
|
36
|
+
# @param lang_iso [String]
|
37
|
+
# @params segment_number [Integer, String]
|
38
|
+
# @param params [Hash]
|
39
|
+
def update_segment(project_id, key_id, lang_iso, segment_number, params = {})
|
40
|
+
c_r Lokalise::Resources::Segment, :update, [project_id, key_id, lang_iso, segment_number], params
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lokalise
|
4
|
+
class Client
|
5
|
+
# Returns team user billing details
|
6
|
+
#
|
7
|
+
# @see https://app.lokalise.com/api2docs/curl/#transition-retrieve-team-user-billing-details-get
|
8
|
+
# @return [Lokalise::Resources::TeamUserBillingDetails]
|
9
|
+
# @param team_id [String]
|
10
|
+
def team_user_billing_details(team_id)
|
11
|
+
c_r Lokalise::Resources::TeamUserBillingDetails, :find, team_id
|
12
|
+
end
|
13
|
+
|
14
|
+
# Creates team user billing details
|
15
|
+
#
|
16
|
+
# @see https://app.lokalise.com/api2docs/curl/#transition-create-team-user-billing-details-post
|
17
|
+
# @return [Lokalise::Resources::TeamUserBillingDetails]
|
18
|
+
# @param team_id [String]
|
19
|
+
# @param params [Hash]
|
20
|
+
def create_team_user_billing_details(team_id, params)
|
21
|
+
c_r Lokalise::Resources::TeamUserBillingDetails, :create, team_id, params
|
22
|
+
end
|
23
|
+
|
24
|
+
# Updates team user billing details
|
25
|
+
#
|
26
|
+
# @see https://app.lokalise.com/api2docs/curl/#transition-create-team-user-billing-details-post
|
27
|
+
# @return [Lokalise::Resources::TeamUserBillingDetails]
|
28
|
+
# @param team_id [String]
|
29
|
+
# @param params [Hash]
|
30
|
+
def update_team_user_billing_details(team_id, params)
|
31
|
+
c_r Lokalise::Resources::TeamUserBillingDetails, :update, team_id, params
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -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,6 +63,7 @@ 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'
|
66
69
|
require 'ruby-lokalise-api/oauth_client'
|
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
|
@@ -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
|
@@ -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
|
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.0
|
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: 2021-
|
11
|
+
date: 2021-12-16 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
|
@@ -268,11 +269,13 @@ files:
|
|
268
269
|
- lib/ruby-lokalise-api/resources/project_language.rb
|
269
270
|
- lib/ruby-lokalise-api/resources/queued_process.rb
|
270
271
|
- lib/ruby-lokalise-api/resources/screenshot.rb
|
272
|
+
- lib/ruby-lokalise-api/resources/segment.rb
|
271
273
|
- lib/ruby-lokalise-api/resources/snapshot.rb
|
272
274
|
- lib/ruby-lokalise-api/resources/system_language.rb
|
273
275
|
- lib/ruby-lokalise-api/resources/task.rb
|
274
276
|
- lib/ruby-lokalise-api/resources/team.rb
|
275
277
|
- lib/ruby-lokalise-api/resources/team_user.rb
|
278
|
+
- lib/ruby-lokalise-api/resources/team_user_billing_details.rb
|
276
279
|
- lib/ruby-lokalise-api/resources/team_user_group.rb
|
277
280
|
- lib/ruby-lokalise-api/resources/translation.rb
|
278
281
|
- lib/ruby-lokalise-api/resources/translation_provider.rb
|
@@ -289,8 +292,10 @@ files:
|
|
289
292
|
- lib/ruby-lokalise-api/rest/projects.rb
|
290
293
|
- lib/ruby-lokalise-api/rest/queued_processes.rb
|
291
294
|
- lib/ruby-lokalise-api/rest/screenshots.rb
|
295
|
+
- lib/ruby-lokalise-api/rest/segments.rb
|
292
296
|
- lib/ruby-lokalise-api/rest/snapshots.rb
|
293
297
|
- lib/ruby-lokalise-api/rest/tasks.rb
|
298
|
+
- lib/ruby-lokalise-api/rest/team_user_billing_details.rb
|
294
299
|
- lib/ruby-lokalise-api/rest/team_user_group.rb
|
295
300
|
- lib/ruby-lokalise-api/rest/team_users.rb
|
296
301
|
- lib/ruby-lokalise-api/rest/teams.rb
|
@@ -317,15 +322,16 @@ files:
|
|
317
322
|
- spec/lib/ruby-lokalise-api/rest/projects_spec.rb
|
318
323
|
- spec/lib/ruby-lokalise-api/rest/queued_processes_spec.rb
|
319
324
|
- spec/lib/ruby-lokalise-api/rest/screenshots_spec.rb
|
325
|
+
- spec/lib/ruby-lokalise-api/rest/segments_spec.rb
|
320
326
|
- spec/lib/ruby-lokalise-api/rest/snapshots_spec.rb
|
321
327
|
- spec/lib/ruby-lokalise-api/rest/tasks_spec.rb
|
328
|
+
- spec/lib/ruby-lokalise-api/rest/team_user_billing_details_spec.rb
|
322
329
|
- spec/lib/ruby-lokalise-api/rest/team_user_groups_spec.rb
|
323
330
|
- spec/lib/ruby-lokalise-api/rest/team_users_spec.rb
|
324
331
|
- spec/lib/ruby-lokalise-api/rest/teams_spec.rb
|
325
332
|
- spec/lib/ruby-lokalise-api/rest/translation_providers_spec.rb
|
326
333
|
- spec/lib/ruby-lokalise-api/rest/translations_spec.rb
|
327
334
|
- spec/lib/ruby-lokalise-api/rest/webhooks_spec.rb
|
328
|
-
- spec/lib/ruby-lokalise-api/utils/snakecase_spec.rb
|
329
335
|
- spec/lib/ruby-lokalise-api_spec.rb
|
330
336
|
- spec/spec_helper.rb
|
331
337
|
- spec/support/test_client.rb
|
@@ -333,7 +339,8 @@ files:
|
|
333
339
|
homepage: https://github.com/lokalise/ruby-lokalise-api
|
334
340
|
licenses:
|
335
341
|
- BSD-3-Clause
|
336
|
-
metadata:
|
342
|
+
metadata:
|
343
|
+
rubygems_mfa_required: 'true'
|
337
344
|
post_install_message:
|
338
345
|
rdoc_options: []
|
339
346
|
require_paths:
|
@@ -349,7 +356,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
349
356
|
- !ruby/object:Gem::Version
|
350
357
|
version: '0'
|
351
358
|
requirements: []
|
352
|
-
rubygems_version: 3.2.
|
359
|
+
rubygems_version: 3.2.33
|
353
360
|
signing_key:
|
354
361
|
specification_version: 4
|
355
362
|
summary: Ruby interface to the Lokalise API
|
@@ -369,15 +376,16 @@ test_files:
|
|
369
376
|
- spec/lib/ruby-lokalise-api/rest/projects_spec.rb
|
370
377
|
- spec/lib/ruby-lokalise-api/rest/queued_processes_spec.rb
|
371
378
|
- spec/lib/ruby-lokalise-api/rest/screenshots_spec.rb
|
379
|
+
- spec/lib/ruby-lokalise-api/rest/segments_spec.rb
|
372
380
|
- spec/lib/ruby-lokalise-api/rest/snapshots_spec.rb
|
373
381
|
- spec/lib/ruby-lokalise-api/rest/tasks_spec.rb
|
382
|
+
- spec/lib/ruby-lokalise-api/rest/team_user_billing_details_spec.rb
|
374
383
|
- spec/lib/ruby-lokalise-api/rest/team_user_groups_spec.rb
|
375
384
|
- spec/lib/ruby-lokalise-api/rest/team_users_spec.rb
|
376
385
|
- spec/lib/ruby-lokalise-api/rest/teams_spec.rb
|
377
386
|
- spec/lib/ruby-lokalise-api/rest/translation_providers_spec.rb
|
378
387
|
- spec/lib/ruby-lokalise-api/rest/translations_spec.rb
|
379
388
|
- spec/lib/ruby-lokalise-api/rest/webhooks_spec.rb
|
380
|
-
- spec/lib/ruby-lokalise-api/utils/snakecase_spec.rb
|
381
389
|
- spec/lib/ruby-lokalise-api_spec.rb
|
382
390
|
- spec/spec_helper.rb
|
383
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
|