ruby-lokalise-api 9.7.1 → 9.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d81a97427ff9dc39704702c65784cadf9c9ad5fdec26f2de03dd8e049c0f2518
4
- data.tar.gz: c335bad01a49407da33b5d18b671bbf21560c9daf6f46022b6fea332aa43c4c4
3
+ metadata.gz: 837f5d7d18c692b1f77adc1ab9eeaf651f7fd05472cbb273e4ed9983610c5c43
4
+ data.tar.gz: b2674de6081d84a4a0cf720bbab391c7ba3e1e65e409db27a467dfbb240cf7f9
5
5
  SHA512:
6
- metadata.gz: 52729414d5125f5b612324825084e132e9442898aa8e7f5185ffd7f044f686f1c750f12c545ecaad144a005c967c341efa0fb8266e94e09b6e9204640481dcac
7
- data.tar.gz: 2a8cd86fdb375cc04aae9a366732f9b552b1f2ca44711d5fe0b0498ca280928949ebcea833d69cb168e2deeba812230a2168daedc8837c96c59c0a092940d4f6
6
+ metadata.gz: 41c24ef0abb5e55b866cccfc54b5d5ebff668d3899946634b76150081d0fa1f85ee8c681d3bbd4fe4a887d19858eda938e066e2aacef0ad2697ac661eefe4e90
7
+ data.tar.gz: ba86e2d299f9c0115e3eb9331078f13ad893da888b331f3356f5ef4dbced607fc8ef4b5b0bddbcd16ed2d36ba719e1d426bb45ed67bbb03b95ac900e8fff9893
@@ -4,8 +4,6 @@ module RubyLokaliseApi
4
4
  # This class contains the base client. Inherited by Client (regular API client)
5
5
  # and OAuth2Client (used for OAuth2-based authentication)
6
6
  class BaseClient
7
- include RubyLokaliseApi::Rest
8
-
9
7
  attr_reader :token, :token_header, :api_host
10
8
  attr_accessor :timeout, :open_timeout
11
9
 
@@ -3,6 +3,8 @@
3
3
  module RubyLokaliseApi
4
4
  # Regular API client used to perform requests with a basic API token
5
5
  class Client < BaseClient
6
+ include RubyLokaliseApi::Rest
7
+
6
8
  def initialize(token, params = {})
7
9
  super
8
10
 
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ # API client used to perform requests against new Lokalise API v1
5
+ class ClientV1 < BaseClient
6
+ include RubyLokaliseApi::RestV1
7
+
8
+ def initialize(token, params = {})
9
+ super
10
+
11
+ @token_header = 'x-api-token'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ module Collections
5
+ module V1
6
+ class AuditLogs < Base
7
+ ENDPOINT = RubyLokaliseApi::Endpoints::V1::AuditLogsEndpoint
8
+ RESOURCE = RubyLokaliseApi::Resources::V1::AuditLog
9
+ DATA_KEY = 'data'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ module Collections
5
+ module V1
6
+ # Base collection. Collection is an array of resources. The actual resources can be found
7
+ # by calling the `.collection` method
8
+ class Base
9
+ include Enumerable
10
+ extend Forwardable
11
+
12
+ using RubyLokaliseApi::Utils::Classes
13
+ extend RubyLokaliseApi::Utils::Attributes
14
+ extend RubyLokaliseApi::Concerns::AttrsLoadable
15
+ include RubyLokaliseApi::Utils::Keys
16
+
17
+ ATTRS_FILENAME = 'collection_attributes.yml'
18
+
19
+ def_delegators :collection, :[], :last, :each
20
+
21
+ attr_reader :collection, :next_cursor, :has_more
22
+
23
+ def initialize(response)
24
+ @self_endpoint = response.endpoint
25
+
26
+ populate_common_attrs_from response
27
+ produce_collection_from response
28
+ end
29
+
30
+ # Tries to fetch the next cursor for paginated collection
31
+ # Returns a new collection or nil if the next cursor is not available
32
+ def load_next_cursor
33
+ return nil unless next_cursor?
34
+
35
+ fetch_cursor(next_cursor)
36
+ end
37
+
38
+ # Checks whether the next cursor is available
39
+ # @return [Boolean]
40
+ def next_cursor?
41
+ !next_cursor.nil? && next_cursor != ''
42
+ end
43
+
44
+ private
45
+
46
+ # This method is utilized to recreate an endpoint for the current collection
47
+ def reinit_endpoint(req_params: @self_endpoint.req_params, override_req_params: {})
48
+ @self_endpoint.reinitialize(
49
+ req_params: req_params.merge(override_req_params)
50
+ )
51
+ end
52
+
53
+ def populate_common_attrs_from(response)
54
+ # v1 has no common attrs so far
55
+ # supported_attrs.each do |attrib|
56
+ # instance_variable_set :"@#{attrib}", response.content[attrib]
57
+ # end
58
+
59
+ @next_cursor = response.content['next_cursor']
60
+ @has_more = response.content['has_more']
61
+ end
62
+
63
+ def produce_collection_from(response)
64
+ content = response.content
65
+ return unless content
66
+
67
+ data_key_plural = collection_key_for klass: "V1::#{self.class.base_name}"
68
+
69
+ resources_data = content[data_key_plural]
70
+ other_data = content.except(data_key_plural)
71
+
72
+ @collection = build_collection resources_data, other_data
73
+ end
74
+
75
+ def build_collection(resources_data, other_data)
76
+ resources_data.map do |raw_resource|
77
+ self.class.const_get(:RESOURCE).new(resource_data(raw_resource, other_data))
78
+ end
79
+ end
80
+
81
+ def resource_data(raw_resource, other_data)
82
+ RubyLokaliseApi::Response.new(
83
+ raw_resource.merge(other_data),
84
+ resource_endpoint.new(
85
+ @self_endpoint.client,
86
+ query: query_for(raw_resource, other_data)
87
+ )
88
+ )
89
+ end
90
+
91
+ def query_for(raw_resource, other_data)
92
+ main_params = self.class.const_get(:RESOURCE).const_get(:MAIN_PARAMS).to_array
93
+
94
+ main_params.map do |param|
95
+ other_data[param.to_s] || raw_resource[param.to_s] || nil
96
+ end
97
+ end
98
+
99
+ def resource_endpoint
100
+ klass = self.class
101
+
102
+ klass.const_defined?(:RESOURCES_ENDPOINT) ? klass.const_get(:RESOURCES_ENDPOINT) : klass.const_get(:ENDPOINT)
103
+ end
104
+
105
+ # Helper method to fetch the next cursor
106
+ def fetch_cursor(cursor)
107
+ self.class.new(reinit_endpoint(override_req_params: { cursor: cursor }).do_get)
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -1,3 +1,23 @@
1
+ audit_log:
2
+ - class_uid
3
+ - class_name
4
+ - category_uid
5
+ - category_name
6
+ - activity_id
7
+ - activity_name
8
+ - type_uid
9
+ - type_name
10
+ - severity_id
11
+ - severity
12
+ - status_id
13
+ - status
14
+ - time
15
+ - metadata
16
+ - actor
17
+ - src_endpoint
18
+ - http_request
19
+ - enrichments
20
+ - unmapped
1
21
  branch:
2
22
  - project_id
3
23
  - branch_id
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ module Endpoints
5
+ module V1
6
+ class AuditLogsEndpoint < MainEndpoint
7
+ private
8
+
9
+ def base_query(class_uuid = nil, *_args)
10
+ {
11
+ 'audit-logs': [class_uuid]
12
+ }
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ module Endpoints
5
+ module V1
6
+ class MainEndpoint < BaseEndpoint
7
+ BASE_URL = 'https://api.lokalise.com/v1'
8
+
9
+ def initialize(client, params = {})
10
+ super
11
+
12
+ @uri = partial_uri(base_query(*@query_params))
13
+ end
14
+
15
+ private
16
+
17
+ def partial_uri(segments, *_args)
18
+ template = super
19
+
20
+ template.expand(
21
+ segments: segments.to_a.flatten
22
+ ).to_s
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -3,6 +3,8 @@
3
3
  module RubyLokaliseApi
4
4
  # Client used to perform API requests with an OAuth2 access token
5
5
  class OAuth2Client < Client
6
+ include RubyLokaliseApi::Rest
7
+
6
8
  def initialize(token, params = {})
7
9
  super
8
10
  @token_header = 'Authorization'
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ module Resources
5
+ module V1
6
+ class AuditLog < ::RubyLokaliseApi::Resources::Base
7
+ MAIN_PARAMS = %i[class_uid].freeze
8
+ no_support_for %i[update destroy reload_data]
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ module Rest
5
+ module V1
6
+ module AuditLogs
7
+ # Returns audit logs
8
+ #
9
+ # @see https://developers.lokalise.com/reference/list-audit-logs
10
+ # @return [RubyLokaliseApi::Collections::V1::AuditLogs]
11
+ # @param req_params [Hash]
12
+ def audit_logs(req_params = {})
13
+ name = 'V1::AuditLogs'
14
+ params = { req: req_params }
15
+
16
+ data = endpoint(name: name, params: params).do_get
17
+
18
+ collection name, data
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ module RestV1
5
+ include Utils::Loaders
6
+
7
+ include Rest::V1::AuditLogs
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyLokaliseApi
4
- VERSION = '9.7.1'
4
+ VERSION = '9.8.0'
5
5
  end
@@ -12,11 +12,13 @@ loader.inflector.inflect(
12
12
  'oauth2_client' => 'OAuth2Client',
13
13
  'oauth2_endpoint' => 'OAuth2Endpoint',
14
14
  'oauth2_token' => 'OAuth2Token',
15
- 'oauth2_refreshed_token' => 'OAuth2RefreshedToken'
15
+ 'oauth2_refreshed_token' => 'OAuth2RefreshedToken',
16
+ 'client_v1' => 'ClientV1',
17
+ 'rest_v1' => 'RestV1'
16
18
  )
17
19
  loader.setup
18
20
 
19
- # Official Ruby client for Lokalise APIv2
21
+ # Official Ruby client for Lokalise APIv2 and new V1 API
20
22
  module RubyLokaliseApi
21
23
  class << self
22
24
  # Initializes a new Client object
@@ -28,9 +30,19 @@ module RubyLokaliseApi
28
30
  @client = RubyLokaliseApi::Client.new token, params
29
31
  end
30
32
 
33
+ # Initializes a new Client object for v1 endpoints
34
+ #
35
+ # @return [RubyLokaliseApi::ClientV1]
36
+ # @param token [String]
37
+ # @param params [Hash]
38
+ def client_v1(token, params = {})
39
+ @client_v1 = RubyLokaliseApi::ClientV1.new token, params
40
+ end
41
+
31
42
  # Reset the currently set client
32
43
  def reset_client!
33
44
  @client = nil
45
+ @client_v1 = nil
34
46
  end
35
47
 
36
48
  # Initializes a new OAuth2Client object
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'rubocop-performance', '~> 1.5'
36
36
  spec.add_development_dependency 'rubocop-rake', '~> 0.6'
37
37
  spec.add_development_dependency 'rubocop-rspec', '~> 3.0'
38
- spec.add_development_dependency 'simplecov', '~> 0.21'
38
+ spec.add_development_dependency 'simplecov', '~> 0.22.0'
39
39
  spec.add_development_dependency 'simplecov-lcov', '~> 0.8'
40
40
  spec.add_development_dependency 'webmock', '~> 3.14'
41
41
  spec.metadata = {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lokalise-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.7.1
4
+ version: 9.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Krukowski
@@ -217,14 +217,14 @@ dependencies:
217
217
  requirements:
218
218
  - - "~>"
219
219
  - !ruby/object:Gem::Version
220
- version: '0.21'
220
+ version: 0.22.0
221
221
  type: :development
222
222
  prerelease: false
223
223
  version_requirements: !ruby/object:Gem::Requirement
224
224
  requirements:
225
225
  - - "~>"
226
226
  - !ruby/object:Gem::Version
227
- version: '0.21'
227
+ version: 0.22.0
228
228
  - !ruby/object:Gem::Dependency
229
229
  name: simplecov-lcov
230
230
  requirement: !ruby/object:Gem::Requirement
@@ -268,6 +268,7 @@ files:
268
268
  - lib/ruby_lokalise_api.rb
269
269
  - lib/ruby_lokalise_api/base_client.rb
270
270
  - lib/ruby_lokalise_api/client.rb
271
+ - lib/ruby_lokalise_api/client_v1.rb
271
272
  - lib/ruby_lokalise_api/collections/base.rb
272
273
  - lib/ruby_lokalise_api/collections/branches.rb
273
274
  - lib/ruby_lokalise_api/collections/contributors.rb
@@ -293,6 +294,8 @@ files:
293
294
  - lib/ruby_lokalise_api/collections/teams.rb
294
295
  - lib/ruby_lokalise_api/collections/translation_providers.rb
295
296
  - lib/ruby_lokalise_api/collections/translations.rb
297
+ - lib/ruby_lokalise_api/collections/v1/audit_logs.rb
298
+ - lib/ruby_lokalise_api/collections/v1/base.rb
296
299
  - lib/ruby_lokalise_api/collections/webhooks.rb
297
300
  - lib/ruby_lokalise_api/concerns/attrs_loadable.rb
298
301
  - lib/ruby_lokalise_api/concerns/hash_accessible.rb
@@ -330,6 +333,8 @@ files:
330
333
  - lib/ruby_lokalise_api/endpoints/translation_providers_endpoint.rb
331
334
  - lib/ruby_lokalise_api/endpoints/translations_endpoint.rb
332
335
  - lib/ruby_lokalise_api/endpoints/users_endpoint.rb
336
+ - lib/ruby_lokalise_api/endpoints/v1/audit_logs_endpoint.rb
337
+ - lib/ruby_lokalise_api/endpoints/v1/main_endpoint.rb
333
338
  - lib/ruby_lokalise_api/endpoints/webhooks_endpoint.rb
334
339
  - lib/ruby_lokalise_api/error.rb
335
340
  - lib/ruby_lokalise_api/generics.rb
@@ -366,6 +371,7 @@ files:
366
371
  - lib/ruby_lokalise_api/resources/translation.rb
367
372
  - lib/ruby_lokalise_api/resources/translation_provider.rb
368
373
  - lib/ruby_lokalise_api/resources/user.rb
374
+ - lib/ruby_lokalise_api/resources/v1/audit_log.rb
369
375
  - lib/ruby_lokalise_api/resources/webhook.rb
370
376
  - lib/ruby_lokalise_api/response.rb
371
377
  - lib/ruby_lokalise_api/rest.rb
@@ -394,7 +400,9 @@ files:
394
400
  - lib/ruby_lokalise_api/rest/translation_providers.rb
395
401
  - lib/ruby_lokalise_api/rest/translations.rb
396
402
  - lib/ruby_lokalise_api/rest/users.rb
403
+ - lib/ruby_lokalise_api/rest/v1/audit_logs.rb
397
404
  - lib/ruby_lokalise_api/rest/webhooks.rb
405
+ - lib/ruby_lokalise_api/rest_v1.rb
398
406
  - lib/ruby_lokalise_api/utils/attributes.rb
399
407
  - lib/ruby_lokalise_api/utils/classes.rb
400
408
  - lib/ruby_lokalise_api/utils/keys.rb
@@ -425,7 +433,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
425
433
  - !ruby/object:Gem::Version
426
434
  version: '0'
427
435
  requirements: []
428
- rubygems_version: 4.0.11
436
+ rubygems_version: 4.0.17
429
437
  specification_version: 4
430
438
  summary: Ruby interface to the Lokalise API
431
439
  test_files: []