ruby-lokalise-api 4.3.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -2
  3. data/lib/ruby-lokalise-api/base_request.rb +24 -0
  4. data/lib/ruby-lokalise-api/client.rb +5 -3
  5. data/lib/ruby-lokalise-api/collections/base.rb +19 -7
  6. data/lib/ruby-lokalise-api/collections/segment.rb +15 -0
  7. data/lib/ruby-lokalise-api/connection.rb +3 -2
  8. data/lib/ruby-lokalise-api/data/attributes.json +26 -0
  9. data/lib/ruby-lokalise-api/error.rb +2 -2
  10. data/lib/ruby-lokalise-api/oauth2/auth.rb +62 -0
  11. data/lib/ruby-lokalise-api/oauth2/connection.rb +25 -0
  12. data/lib/ruby-lokalise-api/oauth2/request.rb +23 -0
  13. data/lib/ruby-lokalise-api/oauth2_client.rb +11 -0
  14. data/lib/ruby-lokalise-api/request.rb +4 -14
  15. data/lib/ruby-lokalise-api/resources/base.rb +18 -7
  16. data/lib/ruby-lokalise-api/resources/branch.rb +3 -1
  17. data/lib/ruby-lokalise-api/resources/contributor.rb +1 -1
  18. data/lib/ruby-lokalise-api/resources/custom_translation_status.rb +1 -1
  19. data/lib/ruby-lokalise-api/resources/key.rb +1 -0
  20. data/lib/ruby-lokalise-api/resources/key_comment.rb +1 -1
  21. data/lib/ruby-lokalise-api/resources/order.rb +1 -0
  22. data/lib/ruby-lokalise-api/resources/payment_card.rb +1 -0
  23. data/lib/ruby-lokalise-api/resources/project.rb +1 -0
  24. data/lib/ruby-lokalise-api/resources/project_comment.rb +1 -0
  25. data/lib/ruby-lokalise-api/resources/project_language.rb +1 -1
  26. data/lib/ruby-lokalise-api/resources/queued_process.rb +1 -1
  27. data/lib/ruby-lokalise-api/resources/screenshot.rb +1 -0
  28. data/lib/ruby-lokalise-api/resources/segment.rb +19 -0
  29. data/lib/ruby-lokalise-api/resources/snapshot.rb +1 -0
  30. data/lib/ruby-lokalise-api/resources/task.rb +1 -0
  31. data/lib/ruby-lokalise-api/resources/team_user.rb +1 -1
  32. data/lib/ruby-lokalise-api/resources/team_user_billing_details.rb +14 -0
  33. data/lib/ruby-lokalise-api/resources/team_user_group.rb +1 -1
  34. data/lib/ruby-lokalise-api/resources/translation.rb +1 -0
  35. data/lib/ruby-lokalise-api/resources/translation_provider.rb +1 -1
  36. data/lib/ruby-lokalise-api/resources/webhook.rb +1 -0
  37. data/lib/ruby-lokalise-api/rest/segments.rb +43 -0
  38. data/lib/ruby-lokalise-api/rest/team_user_billing_details.rb +34 -0
  39. data/lib/ruby-lokalise-api/utils/attribute_helpers.rb +3 -1
  40. data/lib/ruby-lokalise-api/utils/string_utils.rb +24 -18
  41. data/lib/ruby-lokalise-api/version.rb +1 -1
  42. data/lib/ruby-lokalise-api.rb +30 -2
  43. data/ruby-lokalise-api.gemspec +18 -15
  44. data/spec/lib/ruby-lokalise-api/connection_spec.rb +28 -43
  45. data/spec/lib/ruby-lokalise-api/oauth2/auth_spec.rb +73 -0
  46. data/spec/lib/ruby-lokalise-api/rest/branches_spec.rb +8 -8
  47. data/spec/lib/ruby-lokalise-api/rest/contributors_spec.rb +2 -2
  48. data/spec/lib/ruby-lokalise-api/rest/keys_spec.rb +1 -1
  49. data/spec/lib/ruby-lokalise-api/rest/languages_spec.rb +2 -2
  50. data/spec/lib/ruby-lokalise-api/rest/projects_spec.rb +14 -1
  51. data/spec/lib/ruby-lokalise-api/rest/screenshots_spec.rb +2 -2
  52. data/spec/lib/ruby-lokalise-api/rest/segments_spec.rb +106 -0
  53. data/spec/lib/ruby-lokalise-api/rest/snapshots_spec.rb +1 -1
  54. data/spec/lib/ruby-lokalise-api/rest/tasks_spec.rb +2 -2
  55. data/spec/lib/ruby-lokalise-api/rest/team_user_billing_details_spec.rb +48 -0
  56. data/spec/lib/ruby-lokalise-api/rest/team_users_spec.rb +1 -1
  57. data/spec/lib/ruby-lokalise-api/rest/translations_spec.rb +1 -1
  58. data/spec/lib/ruby-lokalise-api_spec.rb +15 -7
  59. data/spec/support/test_client.rb +8 -0
  60. data/spec/support/vcr.rb +5 -0
  61. metadata +27 -12
  62. 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: 4147ca27a676c98d74fa654c4244212aa7e296855d4bda492fd061a3a3a02347
4
- data.tar.gz: 59c042db99a7f2899baef674319ec18ab9ee193f3581f35b40fd92b0c43118bb
3
+ metadata.gz: b99a57388157ac9dea3e17b78cf19b27ada718b172b9b5e91230e4b0772073f2
4
+ data.tar.gz: fff194faef3d317f122987fc866c9358f3169dbf8d5a1d52fdf5d810bff0cb84
5
5
  SHA512:
6
- metadata.gz: 38e44afa51cb74149fb4b7aff68d958232f39d111bef8927835fc9bd012c8738ac0a4a4c175ab1bc9e7b2a846135a5f4ff5473845d562d45d408200e439abedf
7
- data.tar.gz: 67cc5c58134b64955f65595f5b5797c72adbaa8dbe9e239fff0d434044e3a599c0eea4dd7418bbbb2834b9cd8f9e7572258f07a514f80c048508cfba408cd2d0
6
+ metadata.gz: 478a91cc6130208809c783ac145270d89d3a059d76d9b011133a2e62b8b82bee8d9011004945cfb02b9cd950699f45d6354522281904aaf61b885935aee28dca
7
+ data.tar.gz: 15b10938bcfd13534fbcbea1f7f705b74b39e9f9c02895d413f9c859246a389b020ca4abd1d35c59078388564c7c22995bd558b47aad52b5e233229f34e4bec3
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # Lokalise API v2 official Ruby interface
2
2
 
3
3
  ![Gem](https://img.shields.io/gem/v/ruby-lokalise-api)
4
- [![Build Status](https://travis-ci.com/lokalise/ruby-lokalise-api.svg?branch=master)](https://travis-ci.com/github/lokalise/ruby-lokalise-api)
4
+ ![CI](https://github.com/lokalise/ruby-lokalise-api/actions/workflows/ci.yml/badge.svg)
5
5
  [![Test Coverage](https://codecov.io/gh/lokalise/ruby-lokalise-api/graph/badge.svg)](https://codecov.io/gh/lokalise/ruby-lokalise-api)
6
6
  ![Downloads total](https://img.shields.io/gem/dt/ruby-lokalise-api)
7
7
 
8
8
  Official opinionated Ruby interface for the [Lokalise API](https://app.lokalise.com/api2docs/curl/) that represents returned data as Ruby objects.
9
9
 
10
- Looking for a Rails integration? Try the new [lokalise_rails gem](https://github.com/bodrovis/lokalise_rails).
10
+ Looking for a Rails integration? Try the [lokalise_rails gem](https://github.com/bodrovis/lokalise_rails). Also you can use a [lokalise_manager gem](https://github.com/bodrovis/lokalise_manager) which allows to exchange translation files between Lokalise and *any* Ruby script.
11
11
 
12
12
  ## Quickstart
13
13
 
@@ -39,10 +39,18 @@ process = @client.upload_file project_id,
39
39
  process.status
40
40
  ```
41
41
 
42
+ Alternatively instantiate your client with an [OAuth2 token](http://docs.lokalise.com/en/articles/5574713-oauth-2):
43
+
44
+ ```ruby
45
+ @client = Lokalise.oauth2_client 'YOUR_OAUTH2_TOKEN_HERE'
46
+ ```
47
+
42
48
  ## Usage
43
49
 
44
50
  Detailed documentation can be found at [lokalise.github.io/ruby-lokalise-api](https://lokalise.github.io/ruby-lokalise-api/).
45
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
+
46
54
  ## License
47
55
 
48
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.
@@ -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
@@ -20,17 +20,19 @@ 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
26
- attr_reader :token
27
- attr_accessor :timeout, :open_timeout, :enable_compression
28
+ attr_reader :token, :token_header
29
+ attr_accessor :timeout, :open_timeout
28
30
 
29
31
  def initialize(token, params = {})
30
32
  @token = token
31
33
  @timeout = params.fetch(:timeout, nil)
32
34
  @open_timeout = params.fetch(:open_timeout, nil)
33
- @enable_compression = params.fetch(:enable_compression, false)
35
+ @token_header = 'x-api-token'
34
36
  end
35
37
 
36
38
  # rubocop:disable Metrics/ParameterLists
@@ -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,14 +21,8 @@ module Lokalise
19
21
  def initialize(response, params = {})
20
22
  produce_collection_for response
21
23
  populate_pagination_data_for response
22
- # Project, team id, user id, and branch may not be present in some cases
23
- @project_id = response['content']['project_id']
24
- @team_id = response['content']['team_id']
25
- @user_id = response['content']['user_id']
26
- @branch = response['content']['branch']
27
24
  @request_params = params
28
- @client = response['client']
29
- @path = response['path']
25
+ popular_common_attrs response
30
26
  end
31
27
 
32
28
  class << self
@@ -90,6 +86,8 @@ module Lokalise
90
86
  # Dynamically produces collection of resources based on the given response
91
87
  # Collection example: `{ "content": {"comments": [ ... ]} }`
92
88
  def produce_collection_for(response)
89
+ return unless response['content']
90
+
93
91
  model_class = self.class.name.base_class_name
94
92
  data_key_plural = data_key_for model_class: model_class, plural: true, collection: true
95
93
 
@@ -101,6 +99,20 @@ module Lokalise
101
99
  'base_path' => response['path']
102
100
  end
103
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
104
116
  end
105
117
  end
106
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
@@ -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,7 +18,8 @@ module Lokalise
18
18
  headers: {
19
19
  accept: 'application/json',
20
20
  user_agent: "ruby-lokalise-api gem/#{Lokalise::VERSION}",
21
- 'x-api-token': client.token
21
+ accept_encoding: 'gzip,deflate,br',
22
+ client.token_header => client.token
22
23
  },
23
24
  url: BASE_URL
24
25
  }
@@ -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",
@@ -13,7 +13,7 @@ module Lokalise
13
13
  TooManyRequests = Class.new(ClientError)
14
14
  Forbidden = Class.new(ClientError)
15
15
  Locked = Class.new(ClientError)
16
- MethodNowAllowed = Class.new(ClientError)
16
+ MethodNotAllowed = Class.new(ClientError)
17
17
 
18
18
  NotImplemented = Class.new(ServerError)
19
19
  BadGateway = Class.new(ServerError)
@@ -25,7 +25,7 @@ module Lokalise
25
25
  401 => Lokalise::Error::Unauthorized,
26
26
  403 => Lokalise::Error::Forbidden,
27
27
  404 => Lokalise::Error::NotFound,
28
- 405 => Lokalise::Error::MethodNowAllowed,
28
+ 405 => Lokalise::Error::MethodNotAllowed,
29
29
  406 => Lokalise::Error::NotAcceptable,
30
30
  409 => Lokalise::Error::Conflict,
31
31
  423 => Lokalise::Error::Locked,
@@ -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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lokalise
4
+ class OAuth2Client < Client
5
+ def initialize(token, params = {})
6
+ super(token, params)
7
+ @token_header = 'Authorization'
8
+ @token = "Bearer #{@token}"
9
+ end
10
+ end
11
+ end
@@ -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,33 +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
- respond_with_error response.status, body if response.status.between?(400, 599) || (body.respond_to?(:has_key?) && body.key?('error'))
56
+ status = response.status
57
+ raise_on_error! status, body
62
58
  extract_headers_from(response).
63
59
  merge('content' => body,
64
60
  'client' => client,
65
61
  'path' => uri.path.gsub(%r{/api2/}, ''))
66
62
  end
67
63
 
68
- # Get only pagination headers
64
+ # Keep only pagination headers
69
65
  def extract_headers_from(response)
70
66
  response.
71
67
  headers.
72
68
  to_h.
73
69
  keep_if { |k, _v| PAGINATION_HEADERS.include?(k) }
74
70
  end
75
-
76
- def respond_with_error(code, body)
77
- raise(Lokalise::Error, body['error'] || body) unless Lokalise::Error::ERRORS.key? code
78
-
79
- raise Lokalise::Error::ERRORS[code].from_response(body)
80
- end
81
71
  end
82
72
  end
@@ -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
@@ -107,10 +109,11 @@ module Lokalise
107
109
  end
108
110
 
109
111
  def produce_resource(model_class, response)
112
+ content = response['content']
110
113
  data_key_singular = data_key_for model_class: model_class
111
- if response['content'].key? data_key_singular
112
- data = response['content'].delete data_key_singular
113
- response['content'].merge! data
114
+ if content.key? data_key_singular
115
+ data = content.delete data_key_singular
116
+ content.merge! data
114
117
  end
115
118
 
116
119
  new response
@@ -131,7 +134,7 @@ module Lokalise
131
134
 
132
135
  def path_with_id(response, id_key, data_key, endpoint_generator = nil)
133
136
  # Some resources do not have ids at all
134
- return nil unless response['content'].key?(id_key) || response['content'].key?(data_key)
137
+ return unless response['content'] && (response['content'].key?(id_key) || response['content'].key?(data_key))
135
138
 
136
139
  # ID of the resource
137
140
  id = id_from response, id_key, data_key
@@ -155,15 +158,20 @@ module Lokalise
155
158
  # Content may be `{"project_id": '123', ...}` or {"snapshot": {"snapshot_id": '123', ...}}
156
159
  # Sometimes there is an `id_key` but it has a value of `null`
157
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)
158
163
  # Therefore we must explicitly check if the key is present
159
- return response['content'][id_key] if response['content'].key?(id_key)
164
+ content = response['content']
165
+ return content[id_key] if content.respond_to?(:key?) && content&.key?(id_key)
160
166
 
161
- response['content'][data_key][id_key]
167
+ content[data_key][id_key]
162
168
  end
163
169
 
164
170
  # Store all resources attributes under the corresponding instance variables.
165
171
  # `ATTRIBUTES` is defined inside resource-specific classes
166
172
  def populate_attributes_for(content)
173
+ return unless content
174
+
167
175
  data_key = data_key_for model_class: self.class.name.base_class_name
168
176
 
169
177
  self.class.const_get(:ATTRIBUTES).each do |attr|
@@ -181,10 +189,13 @@ module Lokalise
181
189
  # Some of them may be absent in certain cases.
182
190
  # rubocop:disable Naming/MemoizedInstanceVariableName
183
191
  def extract_common_attributes_for(content)
192
+ return unless content
193
+
184
194
  @raw_data = content
185
195
  @project_id ||= content['project_id']
186
196
  @user_id ||= content['user_id']
187
197
  @team_id ||= content['team_id']
198
+ @key_id ||= content['key_id']
188
199
  @branch ||= content['branch']
189
200
  end
190
201
  # rubocop:enable Naming/MemoizedInstanceVariableName
@@ -3,10 +3,12 @@
3
3
  module Lokalise
4
4
  module Resources
5
5
  class Branch < Base
6
+ ID_KEY = 'branch_id'
6
7
  supports :update, :destroy, [:reload_data, '', :find]
7
8
 
8
9
  def merge(params = {})
9
- self.class.merge @client, self.class.endpoint(project_id, branch_id, :merge), params
10
+ klass = self.class
11
+ klass.merge @client, klass.endpoint(project_id, branch_id, :merge), params
10
12
  end
11
13
 
12
14
  class << self
@@ -3,7 +3,7 @@
3
3
  module Lokalise
4
4
  module Resources
5
5
  class Contributor < Base
6
- ID_KEY = 'user'
6
+ ID_KEY = 'user_id'
7
7
  supports :update, :destroy, [:reload_data, '', :find]
8
8
 
9
9
  class << self
@@ -3,7 +3,7 @@
3
3
  module Lokalise
4
4
  module Resources
5
5
  class CustomTranslationStatus < Base
6
- ID_KEY = 'status'
6
+ ID_KEY = 'status_id'
7
7
  supports :update, :destroy, [:reload_data, '', :find]
8
8
 
9
9
  class << self
@@ -3,6 +3,7 @@
3
3
  module Lokalise
4
4
  module Resources
5
5
  class Key < Base
6
+ ID_KEY = 'key_id'
6
7
  supports :update, :destroy, [:reload_data, '', :find]
7
8
 
8
9
  class << self
@@ -4,7 +4,7 @@ module Lokalise
4
4
  module Resources
5
5
  class KeyComment < Base
6
6
  DATA_KEY = 'Comment'
7
- ID_KEY = 'comment'
7
+ ID_KEY = 'comment_id'
8
8
  supports :destroy, [:reload_data, '', :find]
9
9
 
10
10
  class << self
@@ -3,6 +3,7 @@
3
3
  module Lokalise
4
4
  module Resources
5
5
  class Order < Base
6
+ ID_KEY = 'order_id'
6
7
  supports [:reload_data, '', :find]
7
8
 
8
9
  class << self
@@ -3,6 +3,7 @@
3
3
  module Lokalise
4
4
  module Resources
5
5
  class PaymentCard < Base
6
+ ID_KEY = 'card_id'
6
7
  supports :destroy, [:reload_data, '', :find]
7
8
 
8
9
  class << self
@@ -3,6 +3,7 @@
3
3
  module Lokalise
4
4
  module Resources
5
5
  class Project < Base
6
+ ID_KEY = 'project_id'
6
7
  supports :update, :destroy, [:reload_data, '', :find]
7
8
 
8
9
  def empty
@@ -3,6 +3,7 @@
3
3
  module Lokalise
4
4
  module Resources
5
5
  class ProjectComment < Base
6
+ ID_KEY = 'comment_id'
6
7
  DATA_KEY = 'Comment'
7
8
  end
8
9
  end
@@ -4,7 +4,7 @@ module Lokalise
4
4
  module Resources
5
5
  class ProjectLanguage < Base
6
6
  DATA_KEY = 'Language'
7
- ID_KEY = 'lang'
7
+ ID_KEY = 'lang_id'
8
8
  supports :update, :destroy, [:reload_data, '', :find]
9
9
 
10
10
  class << self
@@ -4,7 +4,7 @@ module Lokalise
4
4
  module Resources
5
5
  class QueuedProcess < Base
6
6
  DATA_KEY = 'Process'
7
- ID_KEY = 'process'
7
+ ID_KEY = 'process_id'
8
8
  supports [:reload_data, '', :find]
9
9
 
10
10
  class << self
@@ -3,6 +3,7 @@
3
3
  module Lokalise
4
4
  module Resources
5
5
  class Screenshot < Base
6
+ ID_KEY = 'screenshot_id'
6
7
  supports :update, :destroy, [:reload_data, '', :find]
7
8
 
8
9
  class << self
@@ -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
@@ -3,6 +3,7 @@
3
3
  module Lokalise
4
4
  module Resources
5
5
  class Snapshot < Base
6
+ ID_KEY = 'snapshot_id'
6
7
  supports :destroy
7
8
 
8
9
  def restore
@@ -3,6 +3,7 @@
3
3
  module Lokalise
4
4
  module Resources
5
5
  class Task < Base
6
+ ID_KEY = 'task_id'
6
7
  supports :update, :destroy, [:reload_data, '', :find]
7
8
 
8
9
  class << self
@@ -3,7 +3,7 @@
3
3
  module Lokalise
4
4
  module Resources
5
5
  class TeamUser < Base
6
- ID_KEY = 'user'
6
+ ID_KEY = 'user_id'
7
7
  supports :update, :destroy, [:reload_data, '', :find]
8
8
 
9
9
  class << self