ruby-lokalise-api 7.2.0 → 8.0.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.
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 +32 -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 +17 -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 +48 -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 -185
  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 +28 -0
  122. data/lib/ruby_lokalise_api/utils/keys.rb +33 -0
  123. data/lib/ruby_lokalise_api/utils/loaders.rb +27 -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 +3 -3
  128. metadata +76 -47
  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,221 +1,77 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyLokaliseApi
4
+ # Base resource class. A resource is an individual object returned by the API
4
5
  module Resources
5
6
  class Base
6
- using RubyLokaliseApi::Utils::StringUtils
7
+ using RubyLokaliseApi::Utils::Classes
8
+ extend RubyLokaliseApi::Utils::Attributes
9
+ extend RubyLokaliseApi::Concerns::Unsupportable
10
+ extend RubyLokaliseApi::Concerns::AttrsLoadable
11
+ include RubyLokaliseApi::Concerns::HashAccessible
12
+ include RubyLokaliseApi::Utils::Keys
7
13
 
8
- extend RubyLokaliseApi::Request
9
- extend RubyLokaliseApi::Utils::AttributeHelpers
10
- include RubyLokaliseApi::Utils::AttributeHelpers
11
- extend RubyLokaliseApi::Utils::EndpointHelpers
14
+ ATTRS_FILENAME = 'resource_attributes.yml'
12
15
 
13
- attr_reader :raw_data, :project_id, :client, :path, :branch, :user_id, :team_id, :key_id
16
+ def initialize(response)
17
+ @self_endpoint = response.endpoint
14
18
 
15
- # Initializes a new resource based on the response.
16
- # `endpoint_generator` is used in cases when a new instance is generated
17
- # from a different resource. For example, restoring from a snapshot
18
- # creates a totally different project which should have a new path.
19
- #
20
- # @param response [Hash]
21
- # @param endpoint_generator [Proc] Generate proper paths for certain resources
22
- # @return [RubyLokaliseApi::Resources::Base]
23
- def initialize(response, endpoint_generator = nil)
24
- populate_attributes_for response['content']
25
- extract_common_attributes_for response['content']
26
- @client = response['client']
27
- @path = infer_path_from response, endpoint_generator
19
+ populate_attrs_from response.content
28
20
  end
29
21
 
30
- # Returns object attribute with [] notation by calling
31
- # the corresponding method on the object if the
32
- # instance variable named after the requested key exists
33
- #
34
- # @param raw_key_attr [String or Hash]
35
- def [](raw_key_attr)
36
- key_attr = raw_key_attr.to_s.to_sym
22
+ # Updates the current resource
23
+ def update(params)
24
+ self.class.new reinit_endpoint(params).do_put
25
+ end
37
26
 
38
- return nil unless instance_variables.include?(:"@#{key_attr}")
27
+ # Deletes the current resource
28
+ def destroy
29
+ RubyLokaliseApi::Generics::DeletedResource.new(
30
+ reinit_endpoint.do_delete.content
31
+ )
32
+ end
39
33
 
40
- send key_attr
34
+ # Reloads the current resource with new values from the API
35
+ def reload_data
36
+ self.class.new reinit_endpoint.do_get
41
37
  end
42
38
 
43
39
  class << self
44
- # Dynamically adds attribute readers for each inherited class.
45
- # Attributes are defined in the `data/attributes.json` file.
46
- # Also sets the `ATTRIBUTES` constant to assign values to each attribute later when
47
- # the response arrives from the API
48
- def inherited(subclass)
49
- klass_attributes = attributes_for subclass
50
- subclass.class_exec do
51
- const_set :ATTRIBUTES, klass_attributes
52
- attr_reader(*klass_attributes)
53
- end
54
- super
55
- end
56
-
57
- # Defines CRUD instance methods. In the simplest case it delegates work to the
58
- # class method. In more complex case it is possible to specify sub-path and the
59
- # class method name to call.
60
- # Usage: `supports :update, :destroy, [:complex_method, '/sub/path', :update]`
61
- def supports(*methods)
62
- methods.each do |m_data|
63
- # `method_name` - the method that the resource should support
64
- # `sub_path` - a string that has to be appended to a base path
65
- # `c_method` - method name to delegate the work to
66
- method_name, sub_path, c_method =
67
- m_data.is_a?(Array) ? m_data : [m_data, '', m_data]
68
-
69
- define_method method_name do |params = {}|
70
- path = instance_variable_get(:@path)
71
- # If there's a sub_path which is a string,
72
- # preserve the initial path to allow further chaining
73
- params = params.merge(_initial_path: path) if sub_path
74
- self.class.send c_method, instance_variable_get(:@client),
75
- path + sub_path, params
76
- end
77
- end
78
- end
79
-
80
- # Fetches a single record
81
- def find(client, path, params = {})
82
- new get(path, client, prepare_params(params))
83
- end
84
-
85
- # Creates one or multiple records
86
- def create(client, path, params)
87
- response = post path, client, prepare_params(params)
88
- object_from response, params
89
- end
90
-
91
- # Updates one or multiple records
92
- def update(client, path, params)
93
- response = put path, client, prepare_params(params)
94
- object_from response, params
95
- end
96
-
97
- # Destroys records by given ids
98
- def destroy(client, path, params = {})
99
- delete(path, client, prepare_params(params))['content']
100
- end
101
-
102
- private
103
-
104
- # Filters out internal attributes that should not be sent to Lokalise
105
- def prepare_params(params)
106
- filter_attrs = %i[_initial_path]
107
- params.reject { |key, _v| filter_attrs.include?(key) }
108
- end
109
-
110
- # Instantiates a new resource or collection based on the given response
111
- def object_from(response, params)
112
- model_class = name.base_class_name
113
- data_key_plural = data_key_for model_class: model_class, plural: true
114
- # Preserve the initial path to allow chaining
115
- response['path'] = params.delete(:_initial_path) if params.key?(:_initial_path)
116
-
117
- if response['content'].key?(data_key_plural)
118
- produce_collection model_class, response, params
119
- else
120
- produce_resource model_class, response
121
- end
122
- end
123
-
124
- def produce_resource(model_class, response)
125
- content = response['content']
126
- data_key_singular = data_key_for model_class: model_class
127
- if content.key? data_key_singular
128
- data = content.delete data_key_singular
129
- if data.is_a?(Hash)
130
- content.merge! data
131
- else
132
- content[data_key_singular] = data
133
- end
40
+ # Delegates instance method calls to the client methods
41
+ def delegate_call(from, to = nil)
42
+ define_method(from) do |*args|
43
+ @self_endpoint.client.send((to || from), *read_main_params.push(*args))
134
44
  end
135
-
136
- new response
137
- end
138
-
139
- def produce_collection(model_class, response, params)
140
- Module.const_get("RubyLokaliseApi::Collections::#{model_class}").new(response, params)
141
45
  end
142
46
  end
143
47
 
144
- # Generates path for the individual resource based on the path for the collection
145
- def infer_path_from(response, endpoint_generator = nil)
146
- id_key = id_key_for self.class.name.base_class_name
147
- data_key = data_key_for model_class: self.class.name.base_class_name
148
-
149
- path_with_id response, id_key, data_key, endpoint_generator
150
- end
48
+ private
151
49
 
152
- def path_with_id(response, id_key, data_key, endpoint_generator = nil)
153
- # Some resources do not have ids at all
154
- return unless response['content'] && (response['content'].key?(id_key) || response['content'].key?(data_key))
155
-
156
- # ID of the resource
157
- id = id_from response, id_key, data_key
158
-
159
- # If `endpoint_generator` is present, generate a new path
160
- # based on the fetched id
161
- if endpoint_generator
162
- path = endpoint_generator.call project_id, id
163
- return path.remove_trailing_slash
50
+ def read_main_params
51
+ self.class.const_get(:MAIN_PARAMS).to_array.map do |param|
52
+ instance_variable_get "@#{param}"
164
53
  end
165
-
166
- path = response['path'] || response['base_path']
167
- # If path already has id - just return it
168
- return path if path.match?(/#{id}\z/)
169
-
170
- # Otherwise this looks like a collection path, so append the resource id to it
171
- path.remove_trailing_slash + "/#{id}"
172
54
  end
173
55
 
174
- def id_from(response, id_key, data_key)
175
- # Content may be `{"project_id": '123', ...}` or {"snapshot": {"snapshot_id": '123', ...}}
176
- # Sometimes there is an `id_key` but it has a value of `null`
177
- # (for example when we do not place the actual order but only check its price).
178
- # In rare cases the actual identifier does not have an "_id" suffix
179
- # (for segments that have "segment_number" field instead)
180
- # Therefore we must explicitly check if the key is present
181
- content = response['content']
182
- return content[id_key] if content.respond_to?(:key?) && content&.key?(id_key)
183
-
184
- content[data_key][id_key]
56
+ def reinit_endpoint(req_params = {})
57
+ @self_endpoint.reinitialize(query_params: read_main_params, req_params: req_params)
185
58
  end
186
59
 
187
- # Store all resources attributes under the corresponding instance variables.
188
- # `ATTRIBUTES` is defined inside resource-specific classes
189
- def populate_attributes_for(content)
60
+ def populate_attrs_from(content)
190
61
  return unless content
191
62
 
192
- data_key = data_key_for model_class: self.class.name.base_class_name
63
+ data_key = data_key_for klass: self.class.base_name
193
64
 
194
- self.class.const_get(:ATTRIBUTES).each do |attr|
195
- value = if content.key?(data_key) && content[data_key].is_a?(Hash)
196
- content[data_key][attr]
65
+ supported_attrs.each do |attrib|
66
+ value = if content.key?(data_key) && content[data_key].is_a?(Hash) && content[data_key].key?(attrib)
67
+ content[data_key][attrib]
197
68
  else
198
- content[attr]
69
+ content[attrib]
199
70
  end
200
71
 
201
- instance_variable_set "@#{attr}", value
72
+ instance_variable_set "@#{attrib}", value
202
73
  end
203
74
  end
204
-
205
- # Extracts all common attributes that resources have.
206
- # Some of them may be absent in certain cases.
207
- # rubocop:disable Naming/MemoizedInstanceVariableName
208
- def extract_common_attributes_for(content)
209
- return unless content
210
-
211
- @raw_data = content
212
- @project_id ||= content['project_id']
213
- @user_id ||= content['user_id']
214
- @team_id ||= content['team_id']
215
- @key_id ||= content['key_id']
216
- @branch ||= content['branch']
217
- end
218
- # rubocop:enable Naming/MemoizedInstanceVariableName
219
75
  end
220
76
  end
221
77
  end
@@ -3,28 +3,9 @@
3
3
  module RubyLokaliseApi
4
4
  module Resources
5
5
  class Branch < Base
6
- ID_KEY = 'branch_id'
7
- supports :update, :destroy, [:reload_data, '', :find]
6
+ MAIN_PARAMS = %i[project_id branch_id].freeze
8
7
 
9
- def merge(params = {})
10
- klass = self.class
11
- klass.merge @client, klass.endpoint(project_id, branch_id, :merge), params
12
- end
13
-
14
- class << self
15
- def merge(client, path, params, *_args)
16
- post(path, client, params)['content']
17
- end
18
-
19
- def endpoint(project_id, branch_id = nil, action = nil)
20
- params = {projects: project_id,
21
- branches: branch_id}
22
-
23
- params[:merge] = '' if action == :merge
24
-
25
- path_from params
26
- end
27
- end
8
+ delegate_call :merge, :merge_branch
28
9
  end
29
10
  end
30
11
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ module Resources
5
+ class Comment < Base
6
+ MAIN_PARAMS = %i[project_id key_id comment_id].freeze
7
+
8
+ no_support_for %i[update]
9
+ end
10
+ end
11
+ end
@@ -3,15 +3,7 @@
3
3
  module RubyLokaliseApi
4
4
  module Resources
5
5
  class Contributor < Base
6
- ID_KEY = 'user_id'
7
- supports :update, :destroy, [:reload_data, '', :find]
8
-
9
- class << self
10
- def endpoint(project_id, contributor_id = nil)
11
- path_from projects: project_id,
12
- contributors: contributor_id
13
- end
14
- end
6
+ MAIN_PARAMS = %i[project_id user_id].freeze
15
7
  end
16
8
  end
17
9
  end
@@ -3,19 +3,7 @@
3
3
  module RubyLokaliseApi
4
4
  module Resources
5
5
  class CustomTranslationStatus < Base
6
- ID_KEY = 'status_id'
7
- supports :update, :destroy, [:reload_data, '', :find]
8
-
9
- class << self
10
- def colors(client, path, *_args)
11
- get(path, client)['content']['colors']
12
- end
13
-
14
- def endpoint(project_id, status_id = nil)
15
- path_from projects: project_id,
16
- custom_translation_statuses: status_id
17
- end
18
- end
6
+ MAIN_PARAMS = %i[project_id status_id].freeze
19
7
  end
20
8
  end
21
9
  end
@@ -3,22 +3,8 @@
3
3
  module RubyLokaliseApi
4
4
  module Resources
5
5
  class File < Base
6
- class << self
7
- def download(client, path, params)
8
- post(path, client, params)['content']
9
- end
10
-
11
- def upload(client, path, params)
12
- klass = RubyLokaliseApi::Resources::QueuedProcess
13
- klass.new post(path, client, params),
14
- ->(project_id, id) { klass.endpoint(project_id, id) }
15
- end
16
-
17
- def endpoint(project_id, action = '')
18
- path_from projects: project_id,
19
- files: action
20
- end
21
- end
6
+ MAIN_PARAMS = %i[project_id file_id].freeze
7
+ no_support_for %i[update reload_data]
22
8
  end
23
9
  end
24
10
  end
@@ -3,11 +3,8 @@
3
3
  module RubyLokaliseApi
4
4
  module Resources
5
5
  class Jwt < Base
6
- class << self
7
- def endpoint(project_id, *_args)
8
- path_from projects: project_id, tokens: ''
9
- end
10
- end
6
+ MAIN_PARAMS = :project_id
7
+ no_support_for %i[update destroy reload_data]
11
8
  end
12
9
  end
13
10
  end
@@ -3,15 +3,12 @@
3
3
  module RubyLokaliseApi
4
4
  module Resources
5
5
  class Key < Base
6
- ID_KEY = 'key_id'
7
- supports :update, :destroy, [:reload_data, '', :find]
6
+ MAIN_PARAMS = %i[project_id key_id].freeze
8
7
 
9
- class << self
10
- def endpoint(project_id, key_id = nil)
11
- path_from projects: project_id,
12
- keys: key_id
13
- end
14
- end
8
+ delegate_call :key_comment, :comment
9
+ delegate_call :key_comments, :comments
10
+ delegate_call :create_comments
11
+ delegate_call :destroy_comment
15
12
  end
16
13
  end
17
14
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ module Resources
5
+ class OAuth2RefreshedToken < Base
6
+ no_support_for %i[update destroy reload_data]
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ module Resources
5
+ class OAuth2Token < Base
6
+ no_support_for %i[update destroy reload_data]
7
+ end
8
+ end
9
+ end
@@ -3,15 +3,8 @@
3
3
  module RubyLokaliseApi
4
4
  module Resources
5
5
  class Order < Base
6
- ID_KEY = 'order_id'
7
- supports [:reload_data, '', :find]
8
-
9
- class << self
10
- def endpoint(team_id, order_id = nil)
11
- path_from teams: team_id,
12
- orders: order_id
13
- end
14
- end
6
+ MAIN_PARAMS = %i[team_id order_id].freeze
7
+ no_support_for %i[update destroy]
15
8
  end
16
9
  end
17
10
  end
@@ -3,14 +3,8 @@
3
3
  module RubyLokaliseApi
4
4
  module Resources
5
5
  class PaymentCard < Base
6
- ID_KEY = 'card_id'
7
- supports :destroy, [:reload_data, '', :find]
8
-
9
- class << self
10
- def endpoint(card_id = nil)
11
- path_from payment_cards: card_id
12
- end
13
- end
6
+ MAIN_PARAMS = %i[card_id].freeze
7
+ no_support_for %i[update]
14
8
  end
15
9
  end
16
10
  end
@@ -3,22 +3,91 @@
3
3
  module RubyLokaliseApi
4
4
  module Resources
5
5
  class Project < Base
6
- ID_KEY = 'project_id'
7
- supports :update, :destroy, [:reload_data, '', :find]
8
-
9
- def empty
10
- self.class.empty @client, "#{@path}/empty"
11
- end
12
-
13
- class << self
14
- def empty(client, path, *_args)
15
- put(path, client)['content']
16
- end
17
-
18
- def endpoint(project_id = nil, action = nil)
19
- path_from projects: [project_id, action]
20
- end
21
- end
6
+ MAIN_PARAMS = :project_id
7
+
8
+ delegate_call :empty, :empty_project
9
+
10
+ delegate_call :branches
11
+ delegate_call :branch
12
+ delegate_call :create_branch
13
+ delegate_call :update_branch
14
+ delegate_call :destroy_branch
15
+ delegate_call :merge_branch
16
+
17
+ delegate_call :key_comment, :comment
18
+ delegate_call :key_comments, :comments
19
+ delegate_call :project_comments
20
+ delegate_call :create_comments
21
+ delegate_call :destroy_comment
22
+
23
+ delegate_call :contributor
24
+ delegate_call :contributors
25
+ delegate_call :create_contributors
26
+ delegate_call :update_contributor
27
+ delegate_call :destroy_contributor
28
+
29
+ delegate_call :custom_translation_status
30
+ delegate_call :custom_translation_statuses
31
+ delegate_call :create_custom_translation_status
32
+ delegate_call :update_custom_translation_status
33
+ delegate_call :destroy_custom_translation_status
34
+ delegate_call :custom_translation_status_colors
35
+
36
+ delegate_call :files
37
+ delegate_call :upload_file
38
+ delegate_call :download_files
39
+ delegate_call :destroy_file
40
+
41
+ delegate_call :create_jwt
42
+
43
+ delegate_call :keys
44
+ delegate_call :key
45
+ delegate_call :create_keys
46
+ delegate_call :update_key
47
+ delegate_call :update_keys
48
+ delegate_call :destroy_key
49
+ delegate_call :destroy_keys
50
+
51
+ delegate_call :languages, :project_languages
52
+ delegate_call :language, :project_language
53
+ delegate_call :create_languages, :create_project_languages
54
+ delegate_call :update_language, :update_project_language
55
+ delegate_call :destroy_language, :destroy_project_language
56
+
57
+ delegate_call :queued_process
58
+ delegate_call :queued_processes
59
+
60
+ delegate_call :segments
61
+ delegate_call :segment
62
+ delegate_call :update_segment
63
+
64
+ delegate_call :screenshots
65
+ delegate_call :screenshot
66
+ delegate_call :create_screenshots
67
+ delegate_call :update_screenshot
68
+ delegate_call :destroy_screenshot
69
+
70
+ delegate_call :snapshots
71
+ delegate_call :create_snapshot
72
+ delegate_call :restore_snapshot
73
+ delegate_call :destroy_snapshot
74
+
75
+ delegate_call :tasks
76
+ delegate_call :task
77
+ delegate_call :create_task
78
+ delegate_call :update_task
79
+ delegate_call :destroy_task
80
+
81
+ delegate_call :translations
82
+ delegate_call :translation
83
+ delegate_call :update_translation
84
+
85
+ delegate_call :webhooks
86
+ delegate_call :webhook
87
+ delegate_call :create_webhook
88
+ delegate_call :update_webhook
89
+ delegate_call :regenerate_webhook_secret
90
+ delegate_call :destroy_webhook
22
91
  end
23
92
  end
24
93
  end
@@ -3,16 +3,8 @@
3
3
  module RubyLokaliseApi
4
4
  module Resources
5
5
  class ProjectLanguage < Base
6
- DATA_KEY = 'Language'
7
- ID_KEY = 'lang_id'
8
- supports :update, :destroy, [:reload_data, '', :find]
9
-
10
- class << self
11
- def endpoint(project_id, language_id = nil)
12
- path_from projects: project_id,
13
- languages: language_id
14
- end
15
- end
6
+ MAIN_PARAMS = %i[project_id lang_id].freeze
7
+ DATA_KEY = 'language'
16
8
  end
17
9
  end
18
10
  end
@@ -3,16 +3,9 @@
3
3
  module RubyLokaliseApi
4
4
  module Resources
5
5
  class QueuedProcess < Base
6
- DATA_KEY = 'Process'
7
- ID_KEY = 'process_id'
8
- supports [:reload_data, '', :find]
9
-
10
- class << self
11
- def endpoint(project_id, process_id = nil)
12
- path_from projects: project_id,
13
- processes: process_id
14
- end
15
- end
6
+ MAIN_PARAMS = %i[project_id process_id].freeze
7
+ no_support_for %i[update destroy]
8
+ DATA_KEY = 'process'
16
9
  end
17
10
  end
18
11
  end
@@ -3,15 +3,7 @@
3
3
  module RubyLokaliseApi
4
4
  module Resources
5
5
  class Screenshot < Base
6
- ID_KEY = 'screenshot_id'
7
- supports :update, :destroy, [:reload_data, '', :find]
8
-
9
- class << self
10
- def endpoint(project_id, screenshot_id = nil)
11
- path_from projects: project_id,
12
- screenshots: screenshot_id
13
- end
14
- end
6
+ MAIN_PARAMS = %i[project_id screenshot_id].freeze
15
7
  end
16
8
  end
17
9
  end
@@ -3,17 +3,8 @@
3
3
  module RubyLokaliseApi
4
4
  module Resources
5
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
6
+ MAIN_PARAMS = %i[project_id key_id language_iso segment_number].freeze
7
+ no_support_for %i[destroy]
17
8
  end
18
9
  end
19
10
  end