ruby-lokalise-api 2.8.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODE_OF_CONDUCT.md +1 -1
  3. data/.github/CONTRIBUTING.md +2 -2
  4. data/CHANGELOG.md +46 -0
  5. data/Gemfile +2 -0
  6. data/README.md +293 -178
  7. data/Rakefile +6 -1
  8. data/lib/ruby-lokalise-api.rb +4 -0
  9. data/lib/ruby-lokalise-api/client.rb +18 -4
  10. data/lib/ruby-lokalise-api/collections/base.rb +6 -2
  11. data/lib/ruby-lokalise-api/collections/branch.rb +3 -1
  12. data/lib/ruby-lokalise-api/collections/contributor.rb +2 -0
  13. data/lib/ruby-lokalise-api/collections/custom_translation_status.rb +3 -1
  14. data/lib/ruby-lokalise-api/collections/file.rb +2 -0
  15. data/lib/ruby-lokalise-api/collections/key.rb +2 -0
  16. data/lib/ruby-lokalise-api/collections/key_comment.rb +2 -0
  17. data/lib/ruby-lokalise-api/collections/order.rb +2 -0
  18. data/lib/ruby-lokalise-api/collections/payment_card.rb +2 -0
  19. data/lib/ruby-lokalise-api/collections/project.rb +2 -0
  20. data/lib/ruby-lokalise-api/collections/project_comment.rb +2 -0
  21. data/lib/ruby-lokalise-api/collections/project_language.rb +2 -0
  22. data/lib/ruby-lokalise-api/collections/queued_process.rb +15 -0
  23. data/lib/ruby-lokalise-api/collections/screenshot.rb +2 -0
  24. data/lib/ruby-lokalise-api/collections/snapshot.rb +2 -0
  25. data/lib/ruby-lokalise-api/collections/system_language.rb +2 -0
  26. data/lib/ruby-lokalise-api/collections/task.rb +2 -0
  27. data/lib/ruby-lokalise-api/collections/team.rb +2 -0
  28. data/lib/ruby-lokalise-api/collections/team_user.rb +2 -0
  29. data/lib/ruby-lokalise-api/collections/team_user_group.rb +3 -1
  30. data/lib/ruby-lokalise-api/collections/translation.rb +2 -0
  31. data/lib/ruby-lokalise-api/collections/translation_provider.rb +2 -0
  32. data/lib/ruby-lokalise-api/collections/webhook.rb +2 -0
  33. data/lib/ruby-lokalise-api/connection.rb +3 -1
  34. data/lib/ruby-lokalise-api/data/attributes.json +28 -13
  35. data/lib/ruby-lokalise-api/error.rb +2 -0
  36. data/lib/ruby-lokalise-api/json_handler.rb +4 -0
  37. data/lib/ruby-lokalise-api/request.rb +10 -1
  38. data/lib/ruby-lokalise-api/resources/base.rb +53 -21
  39. data/lib/ruby-lokalise-api/resources/branch.rb +3 -1
  40. data/lib/ruby-lokalise-api/resources/contributor.rb +4 -2
  41. data/lib/ruby-lokalise-api/resources/custom_translation_status.rb +4 -2
  42. data/lib/ruby-lokalise-api/resources/file.rb +5 -1
  43. data/lib/ruby-lokalise-api/resources/key.rb +3 -1
  44. data/lib/ruby-lokalise-api/resources/key_comment.rb +5 -3
  45. data/lib/ruby-lokalise-api/resources/order.rb +4 -0
  46. data/lib/ruby-lokalise-api/resources/payment_card.rb +3 -1
  47. data/lib/ruby-lokalise-api/resources/project.rb +3 -1
  48. data/lib/ruby-lokalise-api/resources/project_comment.rb +3 -1
  49. data/lib/ruby-lokalise-api/resources/project_language.rb +5 -3
  50. data/lib/ruby-lokalise-api/resources/queued_process.rb +18 -0
  51. data/lib/ruby-lokalise-api/resources/screenshot.rb +3 -1
  52. data/lib/ruby-lokalise-api/resources/snapshot.rb +5 -1
  53. data/lib/ruby-lokalise-api/resources/system_language.rb +3 -1
  54. data/lib/ruby-lokalise-api/resources/task.rb +3 -1
  55. data/lib/ruby-lokalise-api/resources/team.rb +2 -0
  56. data/lib/ruby-lokalise-api/resources/team_user.rb +4 -2
  57. data/lib/ruby-lokalise-api/resources/team_user_group.rb +6 -3
  58. data/lib/ruby-lokalise-api/resources/translation.rb +3 -1
  59. data/lib/ruby-lokalise-api/resources/translation_provider.rb +5 -0
  60. data/lib/ruby-lokalise-api/resources/webhook.rb +13 -3
  61. data/lib/ruby-lokalise-api/rest/branches.rb +2 -0
  62. data/lib/ruby-lokalise-api/rest/comments.rb +7 -5
  63. data/lib/ruby-lokalise-api/rest/contributors.rb +7 -5
  64. data/lib/ruby-lokalise-api/rest/custom_translation_statuses.rb +8 -6
  65. data/lib/ruby-lokalise-api/rest/files.rb +5 -3
  66. data/lib/ruby-lokalise-api/rest/keys.rb +9 -7
  67. data/lib/ruby-lokalise-api/rest/languages.rb +8 -6
  68. data/lib/ruby-lokalise-api/rest/orders.rb +2 -0
  69. data/lib/ruby-lokalise-api/rest/payment_cards.rb +5 -3
  70. data/lib/ruby-lokalise-api/rest/projects.rb +8 -6
  71. data/lib/ruby-lokalise-api/rest/queued_processes.rb +26 -0
  72. data/lib/ruby-lokalise-api/rest/screenshots.rb +7 -5
  73. data/lib/ruby-lokalise-api/rest/snapshots.rb +6 -4
  74. data/lib/ruby-lokalise-api/rest/tasks.rb +7 -5
  75. data/lib/ruby-lokalise-api/rest/team_user_group.rb +6 -4
  76. data/lib/ruby-lokalise-api/rest/team_users.rb +6 -4
  77. data/lib/ruby-lokalise-api/rest/teams.rb +3 -1
  78. data/lib/ruby-lokalise-api/rest/translation_providers.rb +4 -2
  79. data/lib/ruby-lokalise-api/rest/translations.rb +5 -3
  80. data/lib/ruby-lokalise-api/rest/webhooks.rb +18 -5
  81. data/lib/ruby-lokalise-api/utils/attribute_helpers.rb +2 -0
  82. data/lib/ruby-lokalise-api/utils/endpoint_helpers.rb +2 -0
  83. data/lib/ruby-lokalise-api/utils/string_utils.rb +2 -0
  84. data/lib/ruby-lokalise-api/version.rb +3 -1
  85. data/ruby-lokalise-api.gemspec +9 -5
  86. data/spec/lib/ruby-lokalise-api/connection_spec.rb +10 -7
  87. data/spec/lib/ruby-lokalise-api/custom_json_parser_spec.rb +9 -5
  88. data/spec/lib/ruby-lokalise-api/error_spec.rb +15 -4
  89. data/spec/lib/ruby-lokalise-api/rest/branches_spec.rb +19 -5
  90. data/spec/lib/ruby-lokalise-api/rest/comments_spec.rb +19 -5
  91. data/spec/lib/ruby-lokalise-api/rest/contributors_spec.rb +18 -4
  92. data/spec/lib/ruby-lokalise-api/rest/custom_translation_statuses_spec.rb +18 -4
  93. data/spec/lib/ruby-lokalise-api/rest/files_spec.rb +21 -11
  94. data/spec/lib/ruby-lokalise-api/rest/keys_spec.rb +46 -26
  95. data/spec/lib/ruby-lokalise-api/rest/languages_spec.rb +20 -6
  96. data/spec/lib/ruby-lokalise-api/rest/orders_spec.rb +16 -2
  97. data/spec/lib/ruby-lokalise-api/rest/payment_cards_spec.rb +21 -5
  98. data/spec/lib/ruby-lokalise-api/rest/projects_spec.rb +18 -4
  99. data/spec/lib/ruby-lokalise-api/rest/queued_processes_spec.rb +57 -0
  100. data/spec/lib/ruby-lokalise-api/rest/screenshots_spec.rb +18 -4
  101. data/spec/lib/ruby-lokalise-api/rest/snapshots_spec.rb +31 -4
  102. data/spec/lib/ruby-lokalise-api/rest/tasks_spec.rb +18 -4
  103. data/spec/lib/ruby-lokalise-api/rest/team_user_groups_spec.rb +92 -6
  104. data/spec/lib/ruby-lokalise-api/rest/team_users_spec.rb +19 -4
  105. data/spec/lib/ruby-lokalise-api/rest/teams_spec.rb +2 -0
  106. data/spec/lib/ruby-lokalise-api/rest/translation_providers_spec.rb +9 -2
  107. data/spec/lib/ruby-lokalise-api/rest/translations_spec.rb +20 -6
  108. data/spec/lib/ruby-lokalise-api/rest/webhooks_spec.rb +54 -2
  109. data/spec/lib/ruby-lokalise-api/utils/snakecase_spec.rb +2 -0
  110. data/spec/lib/ruby-lokalise-api_spec.rb +12 -9
  111. data/spec/spec_helper.rb +8 -1
  112. data/spec/support/test_client.rb +2 -0
  113. data/spec/support/vcr.rb +2 -0
  114. metadata +59 -12
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class Base
@@ -6,25 +8,27 @@ module Lokalise
6
8
  include Lokalise::Utils::AttributeHelpers
7
9
  extend Lokalise::Utils::EndpointHelpers
8
10
 
9
- attr_reader :raw_data, :project_id, :client, :path
11
+ attr_reader :raw_data, :project_id, :client, :path, :branch, :user_id, :team_id
10
12
 
11
- # Initializes a new resource based on the response
13
+ # Initializes a new resource based on the response.
14
+ # `endpoint_generator` is used in cases when a new instance is generated
15
+ # from a different resource. For example, restoring from a snapshot
16
+ # creates a totally different project which should have a new path.
12
17
  #
13
18
  # @param response [Hash]
19
+ # @param endpoint_generator [Proc] Generate proper paths for certain resources
14
20
  # @return [Lokalise::Resources::Base]
15
- def initialize(response)
21
+ def initialize(response, endpoint_generator = nil)
16
22
  populate_attributes_for response['content']
17
-
18
- @raw_data = response['content']
19
- @project_id = response['content']['project_id']
23
+ extract_common_attributes_for response['content']
20
24
  @client = response['client']
21
- @path = infer_path_from response
25
+ @path = infer_path_from response, endpoint_generator
22
26
  end
23
27
 
24
28
  class << self
25
- # Dynamically add attribute readers for each inherited class.
29
+ # Dynamically adds attribute readers for each inherited class.
26
30
  # Attributes are defined in the `data/attributes.json` file.
27
- # Also set the `ATTRIBUTES` constant to assign values to each attribute later when
31
+ # Also sets the `ATTRIBUTES` constant to assign values to each attribute later when
28
32
  # the response arrives from the API
29
33
  def inherited(subclass)
30
34
  klass_attributes = attributes_for subclass
@@ -41,10 +45,16 @@ module Lokalise
41
45
  # Usage: `supports :update, :destroy, [:complex_method, '/sub/path', :update]`
42
46
  def supports(*methods)
43
47
  methods.each do |m_data|
44
- method_name, sub_path, c_method = m_data.is_a?(Array) ? m_data : [m_data, '', m_data]
48
+ # `method_name` - the method that the resource should support
49
+ # `sub_path` - a string that has to be appended to a base path
50
+ # `c_method` - method name to delegate the work to
51
+ method_name, sub_path, c_method =
52
+ m_data.is_a?(Array) ? m_data : [m_data, '', m_data]
53
+
45
54
  define_method method_name do |params = {}|
46
55
  path = instance_variable_get(:@path)
47
- # If there's a sub_path, preserve the initial path to allow further chaining
56
+ # If there's a sub_path which is a string,
57
+ # preserve the initial path to allow further chaining
48
58
  params = params.merge(_initial_path: path) if sub_path
49
59
  self.class.send c_method, instance_variable_get(:@client),
50
60
  path + sub_path, params
@@ -54,30 +64,34 @@ module Lokalise
54
64
 
55
65
  # Fetches a single record
56
66
  def find(client, path, params = {})
57
- new get(path, client, params)
67
+ new get(path, client, prepare_params(params))
58
68
  end
59
69
 
60
70
  # Creates one or multiple records
61
71
  def create(client, path, params)
62
- response = post path, client, params
63
-
72
+ response = post path, client, prepare_params(params)
64
73
  object_from response, params
65
74
  end
66
75
 
67
76
  # Updates one or multiple records
68
77
  def update(client, path, params)
69
- response = put path, client, params
70
-
78
+ response = put path, client, prepare_params(params)
71
79
  object_from response, params
72
80
  end
73
81
 
74
82
  # Destroys records by given ids
75
83
  def destroy(client, path, params = {})
76
- delete(path, client, params)['content']
84
+ delete(path, client, prepare_params(params))['content']
77
85
  end
78
86
 
79
87
  private
80
88
 
89
+ # Filters out internal attributes that should not be sent to Lokalise
90
+ def prepare_params(params)
91
+ filter_attrs = %i[_initial_path]
92
+ params.reject { |key, _v| filter_attrs.include?(key) }
93
+ end
94
+
81
95
  # Instantiates a new resource or collection based on the given response
82
96
  def object_from(response, params)
83
97
  model_class = name.base_class_name
@@ -94,7 +108,6 @@ module Lokalise
94
108
 
95
109
  def produce_resource(model_class, response)
96
110
  data_key_singular = data_key_for model_class
97
-
98
111
  if response['content'].key? data_key_singular
99
112
  data = response['content'].delete data_key_singular
100
113
  response['content'].merge! data
@@ -109,20 +122,27 @@ module Lokalise
109
122
  end
110
123
 
111
124
  # Generates path for the individual resource based on the path for the collection
112
- def infer_path_from(response)
125
+ def infer_path_from(response, endpoint_generator = nil)
113
126
  id_key = id_key_for self.class.name.base_class_name
114
127
  data_key = data_key_for self.class.name.base_class_name
115
128
 
116
- path_with_id response, id_key, data_key
129
+ path_with_id response, id_key, data_key, endpoint_generator
117
130
  end
118
131
 
119
- def path_with_id(response, id_key, data_key)
132
+ def path_with_id(response, id_key, data_key, endpoint_generator = nil)
120
133
  # Some resources do not have ids at all
121
134
  return nil unless response['content'].key?(id_key) || response['content'].key?(data_key)
122
135
 
123
136
  # ID of the resource
124
137
  id = id_from response, id_key, data_key
125
138
 
139
+ # If `endpoint_generator` is present, generate a new path
140
+ # based on the fetched id
141
+ if endpoint_generator
142
+ path = endpoint_generator.call project_id, id
143
+ return path.remove_trailing_slash
144
+ end
145
+
126
146
  path = response['path'] || response['base_path']
127
147
  # If path already has id - just return it
128
148
  return path if path.match?(/#{id}\z/)
@@ -156,6 +176,18 @@ module Lokalise
156
176
  instance_variable_set "@#{attr}", value
157
177
  end
158
178
  end
179
+
180
+ # Extracts all common attributes that resources have.
181
+ # Some of them may be absent in certain cases.
182
+ # rubocop:disable Naming/MemoizedInstanceVariableName
183
+ def extract_common_attributes_for(content)
184
+ @raw_data = content
185
+ @project_id ||= content['project_id']
186
+ @user_id ||= content['user_id']
187
+ @team_id ||= content['team_id']
188
+ @branch ||= content['branch']
189
+ end
190
+ # rubocop:enable Naming/MemoizedInstanceVariableName
159
191
  end
160
192
  end
161
193
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class Branch < Base
4
- supports :update, :destroy
6
+ supports :update, :destroy, [:reload_data, '', :find]
5
7
 
6
8
  def merge(params = {})
7
9
  self.class.merge @client, self.class.endpoint(project_id, branch_id, :merge), params
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class Contributor < Base
4
- ID_KEY = 'user'.freeze
5
- supports :update, :destroy
6
+ ID_KEY = 'user'
7
+ supports :update, :destroy, [:reload_data, '', :find]
6
8
 
7
9
  class << self
8
10
  def endpoint(project_id, contributor_id = nil)
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class CustomTranslationStatus < Base
4
- ID_KEY = 'status'.freeze
5
- supports :update, :destroy
6
+ ID_KEY = 'status'
7
+ supports :update, :destroy, [:reload_data, '', :find]
6
8
 
7
9
  class << self
8
10
  def colors(client, path, *_args)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class File < Base
@@ -7,7 +9,9 @@ module Lokalise
7
9
  end
8
10
 
9
11
  def upload(client, path, params)
10
- post(path, client, params)['content']
12
+ klass = Lokalise::Resources::QueuedProcess
13
+ klass.new post(path, client, params),
14
+ ->(project_id, id) { klass.endpoint(project_id, id) }
11
15
  end
12
16
 
13
17
  def endpoint(project_id, action = '')
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class Key < Base
4
- supports :update, :destroy
6
+ supports :update, :destroy, [:reload_data, '', :find]
5
7
 
6
8
  class << self
7
9
  def endpoint(project_id, key_id = nil)
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class KeyComment < Base
4
- DATA_KEY = 'Comment'.freeze
5
- ID_KEY = 'comment'.freeze
6
- supports :destroy
6
+ DATA_KEY = 'Comment'
7
+ ID_KEY = 'comment'
8
+ supports :destroy, [:reload_data, '', :find]
7
9
 
8
10
  class << self
9
11
  def endpoint(project_id, key_id, comment_id = nil)
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class Order < Base
6
+ supports [:reload_data, '', :find]
7
+
4
8
  class << self
5
9
  def endpoint(team_id, order_id = nil)
6
10
  path_from teams: team_id,
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class PaymentCard < Base
4
- supports :destroy
6
+ supports :destroy, [:reload_data, '', :find]
5
7
 
6
8
  class << self
7
9
  def endpoint(card_id = nil)
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class Project < Base
4
- supports :update, :destroy
6
+ supports :update, :destroy, [:reload_data, '', :find]
5
7
 
6
8
  def empty
7
9
  self.class.empty @client, @path + '/empty'
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class ProjectComment < Base
4
- DATA_KEY = 'Comment'.freeze
6
+ DATA_KEY = 'Comment'
5
7
  end
6
8
  end
7
9
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class ProjectLanguage < Base
4
- DATA_KEY = 'Language'.freeze
5
- ID_KEY = 'lang'.freeze
6
- supports :update, :destroy
6
+ DATA_KEY = 'Language'
7
+ ID_KEY = 'lang'
8
+ supports :update, :destroy, [:reload_data, '', :find]
7
9
 
8
10
  class << self
9
11
  def endpoint(project_id, language_id = nil)
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lokalise
4
+ module Resources
5
+ class QueuedProcess < Base
6
+ DATA_KEY = 'Process'
7
+ ID_KEY = 'process'
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
16
+ end
17
+ end
18
+ end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class Screenshot < Base
4
- supports :update, :destroy
6
+ supports :update, :destroy, [:reload_data, '', :find]
5
7
 
6
8
  class << self
7
9
  def endpoint(project_id, screenshot_id = nil)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class Snapshot < Base
@@ -9,7 +11,9 @@ module Lokalise
9
11
 
10
12
  class << self
11
13
  def restore(client, path, *_args)
12
- Lokalise::Resources::Project.new post(path, client)
14
+ klass = Lokalise::Resources::Project
15
+ klass.new post(path, client),
16
+ ->(project_id, *_ids) { klass.endpoint(project_id) }
13
17
  end
14
18
 
15
19
  def endpoint(project_id, snapshot_id = nil)
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class SystemLanguage < Base
4
- DATA_KEY = 'Language'.freeze
6
+ DATA_KEY = 'Language'
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class Task < Base
4
- supports :update, :destroy
6
+ supports :update, :destroy, [:reload_data, '', :find]
5
7
 
6
8
  class << self
7
9
  def endpoint(project_id, task_id = nil)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class Team < Base
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class TeamUser < Base
4
- ID_KEY = 'user'.freeze
5
- supports :update, :destroy
6
+ ID_KEY = 'user'
7
+ supports :update, :destroy, [:reload_data, '', :find]
6
8
 
7
9
  class << self
8
10
  def endpoint(team_id, team_user_id = nil)
@@ -1,13 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class TeamUserGroup < Base
4
- DATA_KEY = 'Group'.freeze
5
- ID_KEY = 'group'.freeze
6
+ DATA_KEY = 'Group'
7
+ ID_KEY = 'group'
6
8
  supports :update, :destroy,
7
9
  [:add_projects, '/projects/add', :update],
8
10
  [:remove_projects, '/projects/remove', :update],
9
11
  [:add_users, '/members/add', :update],
10
- [:remove_users, '/members/remove', :update]
12
+ [:remove_users, '/members/remove', :update],
13
+ [:reload_data, '', :find]
11
14
 
12
15
  class << self
13
16
  def endpoint(team_id, team_user_group_id = nil, *actions)
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class Translation < Base
4
- supports :update
6
+ supports :update, [:reload_data, '', :find]
5
7
 
6
8
  class << self
7
9
  def endpoint(project_id, translation_id = nil)
@@ -1,6 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class TranslationProvider < Base
6
+ supports [:reload_data, '', :find]
7
+ ID_KEY = 'provider'
8
+
4
9
  class << self
5
10
  def endpoint(team_id, provider_id = nil)
6
11
  path_from teams: team_id,
@@ -1,12 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Lokalise
2
4
  module Resources
3
5
  class Webhook < Base
4
- supports :update, :destroy
6
+ supports :update, :destroy, [:reload_data, '', :find]
7
+
8
+ def regenerate_secret
9
+ self.class.regenerate_secret @client, @path + '/secret/regenerate'
10
+ end
5
11
 
6
12
  class << self
7
- def endpoint(project_id, webhook_id = nil)
13
+ def regenerate_secret(client, path, *_args)
14
+ patch(path, client)['content']
15
+ end
16
+
17
+ def endpoint(project_id, webhook_id = nil, *actions)
8
18
  path_from projects: project_id,
9
- webhooks: webhook_id
19
+ webhooks: [webhook_id, *actions]
10
20
  end
11
21
  end
12
22
  end