ruby-lokalise-api 7.1.1 → 8.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruby_lokalise_api/base_client.rb +2 -34
  3. data/lib/ruby_lokalise_api/client.rb +2 -31
  4. data/lib/ruby_lokalise_api/collections/base.rb +97 -70
  5. data/lib/ruby_lokalise_api/collections/branches.rb +11 -0
  6. data/lib/ruby_lokalise_api/collections/contributors.rb +10 -0
  7. data/lib/ruby_lokalise_api/collections/custom_translation_statuses.rb +10 -0
  8. data/lib/ruby_lokalise_api/collections/files.rb +10 -0
  9. data/lib/ruby_lokalise_api/collections/key_comments.rb +11 -0
  10. data/lib/ruby_lokalise_api/collections/keys.rb +10 -0
  11. data/lib/ruby_lokalise_api/collections/orders.rb +10 -0
  12. data/lib/ruby_lokalise_api/collections/payment_cards.rb +10 -0
  13. data/lib/ruby_lokalise_api/collections/project_comments.rb +12 -0
  14. data/lib/ruby_lokalise_api/collections/project_languages.rb +11 -0
  15. data/lib/ruby_lokalise_api/collections/projects.rb +10 -0
  16. data/lib/ruby_lokalise_api/collections/queued_processes.rb +11 -0
  17. data/lib/ruby_lokalise_api/collections/screenshots.rb +10 -0
  18. data/lib/ruby_lokalise_api/collections/segments.rb +10 -0
  19. data/lib/ruby_lokalise_api/collections/snapshots.rb +10 -0
  20. data/lib/ruby_lokalise_api/collections/system_languages.rb +11 -0
  21. data/lib/ruby_lokalise_api/collections/tasks.rb +10 -0
  22. data/lib/ruby_lokalise_api/collections/team_user_groups.rb +11 -0
  23. data/lib/ruby_lokalise_api/collections/team_users.rb +10 -0
  24. data/lib/ruby_lokalise_api/collections/teams.rb +10 -0
  25. data/lib/ruby_lokalise_api/collections/translation_providers.rb +10 -0
  26. data/lib/ruby_lokalise_api/collections/translations.rb +10 -0
  27. data/lib/ruby_lokalise_api/collections/webhooks.rb +10 -0
  28. data/lib/ruby_lokalise_api/concerns/attrs_loadable.rb +31 -0
  29. data/lib/ruby_lokalise_api/concerns/hash_accessible.rb +16 -0
  30. data/lib/ruby_lokalise_api/concerns/unsupportable.rb +16 -0
  31. data/lib/ruby_lokalise_api/connection.rb +18 -9
  32. data/lib/ruby_lokalise_api/data/collection_attributes.yml +52 -0
  33. data/lib/ruby_lokalise_api/data/{attributes.yml → resource_attributes.yml} +64 -6
  34. data/lib/ruby_lokalise_api/endpoints/base_endpoint.rb +66 -0
  35. data/lib/ruby_lokalise_api/endpoints/branches_endpoint.rb +16 -0
  36. data/lib/ruby_lokalise_api/endpoints/contributors_endpoint.rb +16 -0
  37. data/lib/ruby_lokalise_api/endpoints/custom_translation_statuses_endpoint.rb +16 -0
  38. data/lib/ruby_lokalise_api/endpoints/files_endpoint.rb +16 -0
  39. data/lib/ruby_lokalise_api/endpoints/jwts_endpoint.rb +15 -0
  40. data/lib/ruby_lokalise_api/endpoints/key_comments_endpoint.rb +17 -0
  41. data/lib/ruby_lokalise_api/endpoints/keys_endpoint.rb +16 -0
  42. data/lib/ruby_lokalise_api/endpoints/main_endpoint.rb +25 -0
  43. data/lib/ruby_lokalise_api/endpoints/oauth2/oauth2_endpoint.rb +33 -0
  44. data/lib/ruby_lokalise_api/endpoints/orders_endpoint.rb +16 -0
  45. data/lib/ruby_lokalise_api/endpoints/payment_cards_endpoint.rb +15 -0
  46. data/lib/ruby_lokalise_api/endpoints/project_comments_endpoint.rb +15 -0
  47. data/lib/ruby_lokalise_api/endpoints/project_languages_endpoint.rb +16 -0
  48. data/lib/ruby_lokalise_api/endpoints/projects_endpoint.rb +15 -0
  49. data/lib/ruby_lokalise_api/endpoints/queued_processes_endpoint.rb +16 -0
  50. data/lib/ruby_lokalise_api/endpoints/screenshots_endpoint.rb +16 -0
  51. data/lib/ruby_lokalise_api/endpoints/segments_endpoint.rb +17 -0
  52. data/lib/ruby_lokalise_api/endpoints/snapshots_endpoint.rb +16 -0
  53. data/lib/ruby_lokalise_api/endpoints/system_languages_endpoint.rb +15 -0
  54. data/lib/ruby_lokalise_api/endpoints/tasks_endpoint.rb +16 -0
  55. data/lib/ruby_lokalise_api/endpoints/team_user_billing_details_endpoint.rb +15 -0
  56. data/lib/ruby_lokalise_api/endpoints/team_user_groups_endpoint.rb +16 -0
  57. data/lib/ruby_lokalise_api/endpoints/team_users_endpoint.rb +16 -0
  58. data/lib/ruby_lokalise_api/endpoints/teams_endpoint.rb +13 -0
  59. data/lib/ruby_lokalise_api/endpoints/translation_providers_endpoint.rb +16 -0
  60. data/lib/ruby_lokalise_api/endpoints/translations_endpoint.rb +16 -0
  61. data/lib/ruby_lokalise_api/endpoints/webhooks_endpoint.rb +16 -0
  62. data/lib/ruby_lokalise_api/error.rb +1 -0
  63. data/lib/ruby_lokalise_api/generics.rb +25 -0
  64. data/lib/ruby_lokalise_api/json_handler.rb +1 -2
  65. data/lib/ruby_lokalise_api/oauth2/auth.rb +33 -39
  66. data/lib/ruby_lokalise_api/oauth2_client.rb +3 -0
  67. data/lib/ruby_lokalise_api/request.rb +66 -18
  68. data/lib/ruby_lokalise_api/resources/base.rb +41 -181
  69. data/lib/ruby_lokalise_api/resources/branch.rb +2 -21
  70. data/lib/ruby_lokalise_api/resources/comment.rb +11 -0
  71. data/lib/ruby_lokalise_api/resources/contributor.rb +1 -9
  72. data/lib/ruby_lokalise_api/resources/custom_translation_status.rb +1 -13
  73. data/lib/ruby_lokalise_api/resources/file.rb +2 -16
  74. data/lib/ruby_lokalise_api/resources/jwt.rb +2 -5
  75. data/lib/ruby_lokalise_api/resources/key.rb +5 -8
  76. data/lib/ruby_lokalise_api/resources/oauth2_refreshed_token.rb +9 -0
  77. data/lib/ruby_lokalise_api/resources/oauth2_token.rb +9 -0
  78. data/lib/ruby_lokalise_api/resources/order.rb +2 -9
  79. data/lib/ruby_lokalise_api/resources/payment_card.rb +2 -8
  80. data/lib/ruby_lokalise_api/resources/project.rb +85 -16
  81. data/lib/ruby_lokalise_api/resources/project_language.rb +2 -10
  82. data/lib/ruby_lokalise_api/resources/queued_process.rb +3 -10
  83. data/lib/ruby_lokalise_api/resources/screenshot.rb +1 -9
  84. data/lib/ruby_lokalise_api/resources/segment.rb +2 -11
  85. data/lib/ruby_lokalise_api/resources/snapshot.rb +3 -18
  86. data/lib/ruby_lokalise_api/resources/system_language.rb +2 -1
  87. data/lib/ruby_lokalise_api/resources/task.rb +1 -9
  88. data/lib/ruby_lokalise_api/resources/team.rb +2 -0
  89. data/lib/ruby_lokalise_api/resources/team_user.rb +1 -9
  90. data/lib/ruby_lokalise_api/resources/team_user_billing_details.rb +10 -5
  91. data/lib/ruby_lokalise_api/resources/team_user_group.rb +6 -14
  92. data/lib/ruby_lokalise_api/resources/translation.rb +2 -9
  93. data/lib/ruby_lokalise_api/resources/translation_provider.rb +2 -9
  94. data/lib/ruby_lokalise_api/resources/webhook.rb +2 -16
  95. data/lib/ruby_lokalise_api/response.rb +50 -0
  96. data/lib/ruby_lokalise_api/rest/branches.rb +52 -27
  97. data/lib/ruby_lokalise_api/rest/comments.rb +48 -23
  98. data/lib/ruby_lokalise_api/rest/contributors.rb +47 -23
  99. data/lib/ruby_lokalise_api/rest/custom_translation_statuses.rb +60 -36
  100. data/lib/ruby_lokalise_api/rest/files.rb +43 -24
  101. data/lib/ruby_lokalise_api/rest/jwts.rb +21 -0
  102. data/lib/ruby_lokalise_api/rest/keys.rb +67 -34
  103. data/lib/ruby_lokalise_api/rest/languages.rb +57 -28
  104. data/lib/ruby_lokalise_api/rest/orders.rb +36 -14
  105. data/lib/ruby_lokalise_api/rest/payment_cards.rb +29 -12
  106. data/lib/ruby_lokalise_api/rest/projects.rb +55 -32
  107. data/lib/ruby_lokalise_api/rest/queued_processes.rb +21 -13
  108. data/lib/ruby_lokalise_api/rest/screenshots.rb +45 -20
  109. data/lib/ruby_lokalise_api/rest/segments.rb +31 -18
  110. data/lib/ruby_lokalise_api/rest/snapshots.rb +34 -14
  111. data/lib/ruby_lokalise_api/rest/tasks.rb +41 -19
  112. data/lib/ruby_lokalise_api/rest/team_user_billing_details.rb +33 -12
  113. data/lib/ruby_lokalise_api/rest/team_user_groups.rb +82 -50
  114. data/lib/ruby_lokalise_api/rest/team_users.rb +35 -18
  115. data/lib/ruby_lokalise_api/rest/teams.rb +10 -5
  116. data/lib/ruby_lokalise_api/rest/translation_providers.rb +24 -9
  117. data/lib/ruby_lokalise_api/rest/translations.rb +28 -15
  118. data/lib/ruby_lokalise_api/rest/webhooks.rb +54 -30
  119. data/lib/ruby_lokalise_api/rest.rb +31 -0
  120. data/lib/ruby_lokalise_api/utils/attributes.rb +37 -0
  121. data/lib/ruby_lokalise_api/utils/classes.rb +24 -0
  122. data/lib/ruby_lokalise_api/utils/keys.rb +29 -0
  123. data/lib/ruby_lokalise_api/utils/loaders.rb +24 -0
  124. data/lib/ruby_lokalise_api/utils/strings.rb +20 -0
  125. data/lib/ruby_lokalise_api/version.rb +1 -1
  126. data/lib/ruby_lokalise_api.rb +6 -2
  127. data/ruby-lokalise-api.gemspec +2 -2
  128. metadata +76 -41
  129. data/lib/ruby_lokalise_api/base_request.rb +0 -73
  130. data/lib/ruby_lokalise_api/collections/branch.rb +0 -15
  131. data/lib/ruby_lokalise_api/collections/contributor.rb +0 -13
  132. data/lib/ruby_lokalise_api/collections/custom_translation_status.rb +0 -15
  133. data/lib/ruby_lokalise_api/collections/file.rb +0 -13
  134. data/lib/ruby_lokalise_api/collections/key.rb +0 -20
  135. data/lib/ruby_lokalise_api/collections/key_comment.rb +0 -14
  136. data/lib/ruby_lokalise_api/collections/order.rb +0 -13
  137. data/lib/ruby_lokalise_api/collections/payment_card.rb +0 -13
  138. data/lib/ruby_lokalise_api/collections/project.rb +0 -13
  139. data/lib/ruby_lokalise_api/collections/project_comment.rb +0 -13
  140. data/lib/ruby_lokalise_api/collections/project_language.rb +0 -13
  141. data/lib/ruby_lokalise_api/collections/queued_process.rb +0 -15
  142. data/lib/ruby_lokalise_api/collections/screenshot.rb +0 -13
  143. data/lib/ruby_lokalise_api/collections/segment.rb +0 -15
  144. data/lib/ruby_lokalise_api/collections/snapshot.rb +0 -13
  145. data/lib/ruby_lokalise_api/collections/system_language.rb +0 -13
  146. data/lib/ruby_lokalise_api/collections/task.rb +0 -13
  147. data/lib/ruby_lokalise_api/collections/team.rb +0 -13
  148. data/lib/ruby_lokalise_api/collections/team_user.rb +0 -13
  149. data/lib/ruby_lokalise_api/collections/team_user_group.rb +0 -15
  150. data/lib/ruby_lokalise_api/collections/translation.rb +0 -13
  151. data/lib/ruby_lokalise_api/collections/translation_provider.rb +0 -13
  152. data/lib/ruby_lokalise_api/collections/webhook.rb +0 -13
  153. data/lib/ruby_lokalise_api/oauth2/refresh.rb +0 -16
  154. data/lib/ruby_lokalise_api/oauth2/token.rb +0 -16
  155. data/lib/ruby_lokalise_api/resources/key_comment.rb +0 -19
  156. data/lib/ruby_lokalise_api/resources/project_comment.rb +0 -10
  157. data/lib/ruby_lokalise_api/rest/jwt.rb +0 -15
  158. data/lib/ruby_lokalise_api/utils/attribute_helpers.rb +0 -86
  159. data/lib/ruby_lokalise_api/utils/endpoint_helpers.rb +0 -14
  160. data/lib/ruby_lokalise_api/utils/string_utils.rb +0 -33
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyLokaliseApi
4
- module Collections
5
- class TeamUserGroup < Base
6
- DATA_KEY = 'UserGroup'
7
-
8
- class << self
9
- def endpoint(team_id, *_args)
10
- path_from teams: [team_id, 'groups']
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyLokaliseApi
4
- module Collections
5
- class Translation < Base
6
- class << self
7
- def endpoint(project_id, *_args)
8
- path_from projects: [project_id, 'translations']
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyLokaliseApi
4
- module Collections
5
- class TranslationProvider < Base
6
- class << self
7
- def endpoint(team_id, *_args)
8
- path_from teams: [team_id, 'translation_providers']
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyLokaliseApi
4
- module Collections
5
- class Webhook < Base
6
- class << self
7
- def endpoint(project_id, *_args)
8
- path_from projects: [project_id, 'webhooks']
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyLokaliseApi
4
- module OAuth2
5
- class Refresh
6
- attr_reader :access_token, :expires_in, :scope, :token_type
7
-
8
- def initialize(raw_params)
9
- @access_token = raw_params['access_token']
10
- @expires_in = raw_params['expires_in']
11
- @scope = raw_params['scope']
12
- @token_type = raw_params['token_type']
13
- end
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyLokaliseApi
4
- module OAuth2
5
- class Token
6
- attr_reader :access_token, :refresh_token, :expires_in, :token_type
7
-
8
- def initialize(raw_params)
9
- @access_token = raw_params['access_token']
10
- @refresh_token = raw_params['refresh_token']
11
- @expires_in = raw_params['expires_in']
12
- @token_type = raw_params['token_type']
13
- end
14
- end
15
- end
16
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyLokaliseApi
4
- module Resources
5
- class KeyComment < Base
6
- DATA_KEY = 'Comment'
7
- ID_KEY = 'comment_id'
8
- supports :destroy, [:reload_data, '', :find]
9
-
10
- class << self
11
- def endpoint(project_id, key_id, comment_id = nil)
12
- path_from projects: project_id,
13
- keys: key_id,
14
- comments: comment_id
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyLokaliseApi
4
- module Resources
5
- class ProjectComment < Base
6
- ID_KEY = 'comment_id'
7
- DATA_KEY = 'Comment'
8
- end
9
- end
10
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyLokaliseApi
4
- module Rest
5
- module Jwt
6
- # Returns a JWT that can be used to work with OTA
7
- #
8
- # @see https://developers.lokalise.com/reference/get-ota-jwt
9
- # @return [RubyLokaliseApi::Resources::Jwt]
10
- def jwt
11
- c_r RubyLokaliseApi::Resources::Jwt, :find, nil, {}
12
- end
13
- end
14
- end
15
- end
@@ -1,86 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyLokaliseApi
4
- module Utils
5
- module AttributeHelpers
6
- using RubyLokaliseApi::Utils::StringUtils
7
-
8
- UNIFIED_RESOURCES = %w[comment language].freeze
9
-
10
- # Returns the name of the API resource for the given class.
11
- # Most class names correspond to resource names (eg, `Project`, `Team`)
12
- # but some may differ (`ProjectComment` corresponds to `Comment` resource).
13
- # The resource name is in lowercase, with underscores as separators.
14
- # Some resources also have different pluralization rules. For example,
15
- # "CustomTranslationStatus" is "CustomTranslationStatuses" (-es postfix).
16
- # To address that, we try to fetch `DATA_KEY_PLURAL` set for the individual class.
17
- #
18
- # @return [String]
19
- # @param model_class [String]
20
- # @param plural [Boolean] Should the returned value be pluralized?
21
- def data_key_for(model_class:, plural: false, collection: false)
22
- data_key_plural = get_key(
23
- name: 'DATA_KEY_PLURAL',
24
- model_class: model_class,
25
- collection: true,
26
- strict: true
27
- )
28
-
29
- return data_key_plural if collection && data_key_plural
30
-
31
- data_key = get_key name: 'DATA_KEY', model_class: model_class, collection: collection
32
-
33
- return data_key unless plural
34
-
35
- "#{data_key}s"
36
- end
37
-
38
- # Returns key used to determine resource id (for example `user_id` or `project_id`).
39
- # Most ids corresponds to resources' class names, but some may differ (for instance,
40
- # `Contributor` has `user_id` attribute).
41
- #
42
- # @return [String]
43
- # @param model_class [String]
44
- def id_key_for(model_class)
45
- get_key name: 'ID_KEY', model_class: model_class
46
- end
47
-
48
- # Loads attributes for the given resource based on its name
49
- #
50
- # @return [Array<String>]
51
- def attributes_for(klass)
52
- @attributes ||= YAML.load_file(File.expand_path('../data/attributes.yml', __dir__)).freeze
53
-
54
- name = unify klass.name.snakecase
55
- @attributes[name]
56
- end
57
-
58
- private
59
-
60
- def get_key(name:, model_class:, collection: false, strict: false)
61
- key = if collection && Module.const_defined?("RubyLokaliseApi::Collections::#{model_class}::#{name}")
62
- Module.const_get "RubyLokaliseApi::Collections::#{model_class}::#{name}"
63
- elsif Module.const_defined? "RubyLokaliseApi::Resources::#{model_class}::#{name}"
64
- Module.const_get "RubyLokaliseApi::Resources::#{model_class}::#{name}"
65
- else
66
- strict ? nil : model_class
67
- end
68
-
69
- # Sometimes key is nil
70
- key ? key.snakecase : key
71
- end
72
-
73
- # Unify some resources' names (eg, `ProjectComment` and `KeyComment` have the same
74
- # attributes which are stored under `comment`)
75
- #
76
- # @return [String]
77
- def unify(name)
78
- UNIFIED_RESOURCES.each do |u_a|
79
- return u_a if name.match?(/#{u_a}/)
80
- end
81
-
82
- name
83
- end
84
- end
85
- end
86
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubyLokaliseApi
4
- module Utils
5
- module EndpointHelpers
6
- def path_from(raw_mapping)
7
- template = Addressable::Template.new '{/segments*}'
8
- template.expand(
9
- segments: raw_mapping.to_a.flatten
10
- ).to_s
11
- end
12
- end
13
- end
14
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Initial code taken from Facets gem by Rubyworks
4
- # https://github.com/rubyworks/facets/blob/master/lib/core/facets/string/snakecase.rb
5
-
6
- module RubyLokaliseApi
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
21
-
22
- # Turn `Module::Nested::ClassName` to just `ClassName`
23
- def base_class_name
24
- split('::').last
25
- end
26
-
27
- def remove_trailing_slash
28
- delete_suffix '/'
29
- end
30
- end
31
- end
32
- end
33
- end