ruby-lokalise-api 2.5.0 → 2.6.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: ebd0d7d723970806d7d8078803ada29e359b90f6248a34fb17176b55f977f39b
4
- data.tar.gz: 5cbc279f312e4021ed6e6028e843013507aad310cc76f3376a206a65ea391726
3
+ metadata.gz: 8345d20376de0aad91a7947b6a9e480683f63dc9538d3ad95e43e3cf8fafbbdb
4
+ data.tar.gz: 2bfeb6a17148d6572e75580f286e1ac1919e94d850ee8d930d770ca2a3c99695
5
5
  SHA512:
6
- metadata.gz: 99ce24c8248ed892d0a37688a7df26ba661a017be9630f22cac528be128172684e8e3ecc9022d4a94897ef5b2b2fe3cb21182be7b3778eb8f8d8a773984e4b32
7
- data.tar.gz: 4688f964ff6d8f9dccede52a9bf9f8e40a31e3674242d49f1329373ca271bb25cd7b1cd204805e9799982028afebf8e97a0ea4a92a7b8f99acbd4a02105c5d17
6
+ metadata.gz: 6fd93672adc920b30803b0aa5af977487671dbdd6408147fc6494a303c79f6a52d033c8065931d5a2b43824c2b9147f7470bbb7d0ed31dcfd04b2698f662ede4
7
+ data.tar.gz: 59333fc1f5f5dae3c6c05a370e0287eaf61e43f1fd7b4cdbe3f1d2e1b4f1d909a2d5c10fdc4d30e57dc1c81a6014df404fe26ec4d91bf6bd884cc251d03c00b3
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.6.0 (21-Aug-19)
4
+
5
+ * Added [`Webhook` endpoint](https://lokalise.co/api2docs/curl/#resource-webhooks) (thanks to [@snkashis](https://github.com/snkashis) for help!)
6
+
3
7
  ## 2.5.0 (01-Aug-19)
4
8
 
5
9
  * Added `:timeout` and `:open_timeout` options for the client [to customize request timeouts](https://github.com/lokalise/ruby-lokalise-api#setting-timeouts)
data/README.md CHANGED
@@ -30,6 +30,7 @@ Official opinionated Ruby interface for the [Lokalise API](https://lokalise.co/a
30
30
  + [Translations](#translations)
31
31
  + [Translation Providers](#translation-providers)
32
32
  + [Translation Statuses](#translation-statuses)
33
+ + [Webhooks](#webhooks)
33
34
  * [Additional Info](#additional-info)
34
35
  + [Customizing request](#customizing-request)
35
36
  + [Customizing JSON parser](#customizing-json-parser)
@@ -1446,7 +1447,7 @@ status.update(params)
1446
1447
  ## project_id (string, required)
1447
1448
  ## status_id (string or integer, required)
1448
1449
  # Output:
1449
- ## Translation status inside the given project
1450
+ ## Result of the delete operation
1450
1451
  ```
1451
1452
 
1452
1453
  Alternatively:
@@ -1469,6 +1470,92 @@ As long as Lokalise supports only very limited array of color hexadecimal codes
1469
1470
  ## Array of color codes in HEX format
1470
1471
  ```
1471
1472
 
1473
+ ### Webhooks
1474
+
1475
+ [Webhook attributes](https://lokalise.co/api2docs/ruby/#object-webhooks)
1476
+
1477
+ #### Fetch webhooks
1478
+
1479
+ [Doc](https://lokalise.co/api2docs/ruby/#transition-list-all-webhooks-get)
1480
+
1481
+ ```ruby
1482
+ @client.webhooks(project_id, params = {}) # Input:
1483
+ ## project_id (string, required)
1484
+ ## params (hash)
1485
+ ### :page and :limit
1486
+ # Output:
1487
+ ## Collection of webhooks for the project
1488
+ ```
1489
+
1490
+ #### Fetch a single webhook
1491
+
1492
+ [Doc](https://lokalise.co/api2docs/ruby/#transition-retrieve-a-webhook-get)
1493
+
1494
+ ```ruby
1495
+ @client.webhook(project_id, webhook_id) # Input:
1496
+ ## project_id (string, required)
1497
+ ## webhook_id (string or integer, required)
1498
+ # Output:
1499
+ ## Webhook for the given project
1500
+ ```
1501
+
1502
+ #### Create webhook
1503
+
1504
+ [Doc](https://lokalise.co/api2docs/ruby/#transition-create-a-webhook-post)
1505
+
1506
+ ```ruby
1507
+ @client.create_webhook(project_id, params) # Input:
1508
+ ## project_id (string, required)
1509
+ ## params (hash, required)
1510
+ ### :url (string, required) - webhook URL
1511
+ ### :events (array, required) - events to subscribe to. Check the API docs to find the list of supported events
1512
+ ### :event_lang_map (array) - map the event with an array of languages iso codes
1513
+ # Output:
1514
+ ## Created webhook
1515
+ ```
1516
+
1517
+ #### Update webhook
1518
+
1519
+ [Doc](https://lokalise.co/api2docs/ruby/#transition-update-a-webhook-put)
1520
+
1521
+ ```ruby
1522
+ @client.update_webhook(project_id, webhook_id, params) # Input:
1523
+ ## project_id (string, required)
1524
+ ## webhook_id (string or integer, required)
1525
+ ## params (hash)
1526
+ ### :url (string) - webhook URL
1527
+ ### :events (array) - events to subscribe to. Check the API docs to find the list of supported events
1528
+ ### :event_lang_map (array) - map the event with an array of languages iso codes
1529
+ # Output:
1530
+ ## Updated webhook
1531
+ ```
1532
+
1533
+ Alternatively:
1534
+
1535
+ ```ruby
1536
+ webhook = @client.webhook(project_id, webhook_id)
1537
+ webhook.update(params)
1538
+ ```
1539
+
1540
+ #### Delete webhook
1541
+
1542
+ [Doc](https://lokalise.co/api2docs/ruby/#transition-delete-a-webhook-delete)
1543
+
1544
+ ```ruby
1545
+ @client.destroy_webhook(project_id, webhook_id) # Input:
1546
+ ## project_id (string, required)
1547
+ ## webhook_id (string or integer, required)
1548
+ # Output:
1549
+ ## Result of the delete operation
1550
+ ```
1551
+
1552
+ Alternatively:
1553
+
1554
+ ```ruby
1555
+ webhook = @client.webhook(project_id, webhook_id)
1556
+ webhook.destroy
1557
+ ```
1558
+
1472
1559
  ## Additional Info
1473
1560
 
1474
1561
  ### Customizing Request
@@ -31,6 +31,7 @@ require 'ruby-lokalise-api/resources/payment_card'
31
31
  require 'ruby-lokalise-api/resources/translation_provider'
32
32
  require 'ruby-lokalise-api/resources/team_user_group'
33
33
  require 'ruby-lokalise-api/resources/custom_translation_status'
34
+ require 'ruby-lokalise-api/resources/webhook'
34
35
 
35
36
  require 'ruby-lokalise-api/collections/base'
36
37
  require 'ruby-lokalise-api/collections/project'
@@ -52,6 +53,7 @@ require 'ruby-lokalise-api/collections/payment_card'
52
53
  require 'ruby-lokalise-api/collections/translation_provider'
53
54
  require 'ruby-lokalise-api/collections/team_user_group'
54
55
  require 'ruby-lokalise-api/collections/custom_translation_status'
56
+ require 'ruby-lokalise-api/collections/webhook'
55
57
 
56
58
  require 'ruby-lokalise-api/client'
57
59
 
@@ -15,6 +15,7 @@ require 'ruby-lokalise-api/rest/payment_cards'
15
15
  require 'ruby-lokalise-api/rest/translation_providers'
16
16
  require 'ruby-lokalise-api/rest/team_user_group'
17
17
  require 'ruby-lokalise-api/rest/custom_translation_statuses'
18
+ require 'ruby-lokalise-api/rest/webhooks'
18
19
 
19
20
  module Lokalise
20
21
  class Client
@@ -53,12 +53,14 @@ module Lokalise
53
53
  !prev_page?
54
54
  end
55
55
 
56
+ # @return [Integer]
56
57
  def next_page
57
58
  return nil if last_page?
58
59
 
59
60
  fetch_page @current_page + 1
60
61
  end
61
62
 
63
+ # @return [Integer]
62
64
  def prev_page
63
65
  return nil if first_page?
64
66
 
@@ -74,6 +76,7 @@ module Lokalise
74
76
  @current_page = response['x-pagination-page'].to_i
75
77
  end
76
78
 
79
+ # Gets the specified page
77
80
  def fetch_page(page_num)
78
81
  self.class.all @client,
79
82
  @path,
@@ -0,0 +1,11 @@
1
+ module Lokalise
2
+ module Collections
3
+ class Webhook < Base
4
+ class << self
5
+ def endpoint(project_id, *_args)
6
+ path_from projects: [project_id, 'webhooks']
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -16,6 +16,7 @@ module Lokalise
16
16
 
17
17
  private
18
18
 
19
+ # Allows to customize request params per-client
19
20
  def request_params_for(client)
20
21
  {request: {timeout: client.timeout, open_timeout: client.open_timeout}}
21
22
  end
@@ -195,5 +195,12 @@
195
195
  "description",
196
196
  "tiers",
197
197
  "pairs"
198
+ ],
199
+ "webhook": [
200
+ "webhook_id",
201
+ "url",
202
+ "secret",
203
+ "events",
204
+ "event_lang_map"
198
205
  ]
199
206
  }
@@ -3,6 +3,7 @@ module Lokalise
3
3
  include Lokalise::Connection
4
4
  include Lokalise::JsonHandler
5
5
 
6
+ # Lokalise returns pagination info in special headers
6
7
  PAGINATION_HEADERS = %w[x-pagination-total-count x-pagination-page-count x-pagination-limit x-pagination-page].freeze
7
8
 
8
9
  def get(path, client, params = {})
@@ -55,6 +56,7 @@ module Lokalise
55
56
  'path' => uri.path.gsub(%r{/api2/}, ''))
56
57
  end
57
58
 
59
+ # Get only pagination headers
58
60
  def extract_headers_from(response)
59
61
  response.
60
62
  headers.
@@ -127,7 +127,7 @@ module Lokalise
127
127
  # If path already has id - just return it
128
128
  return path if path.match?(/#{id}\z/)
129
129
 
130
- # Otherwise this seems like a collection path, so append the resource id to it
130
+ # Otherwise this looks like a collection path, so append the resource id to it
131
131
  path.remove_trailing_slash + "/#{id}"
132
132
  end
133
133
 
@@ -0,0 +1,14 @@
1
+ module Lokalise
2
+ module Resources
3
+ class Webhook < Base
4
+ supports :update, :destroy
5
+
6
+ class << self
7
+ def endpoint(project_id, webhook_id = nil)
8
+ path_from projects: project_id,
9
+ webhooks: webhook_id
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,54 @@
1
+ module Lokalise
2
+ class Client
3
+ # Returns all webhooks for the given project
4
+ #
5
+ # @see https://lokalise.co/api2docs/ruby/#transition-list-all-webhooks-get
6
+ # @return [Lokalise::Collection::Webhook<Lokalise::Resources::Webhook>]
7
+ # @param project_id [String]
8
+ # @param params [Hash]
9
+ def webhooks(project_id, params = {})
10
+ c_r Lokalise::Collections::Webhook, :all, project_id, params
11
+ end
12
+
13
+ # Returns a single webhook for the given project
14
+ #
15
+ # @see https://lokalise.co/api2docs/ruby/#transition-retrieve-a-webhook-get
16
+ # @return [Lokalise::Resources::Webhook]
17
+ # @param project_id [String]
18
+ # @param webhook_id [String, Integer]
19
+ def webhook(project_id, webhook_id)
20
+ c_r Lokalise::Resources::Webhook, :find, [project_id, webhook_id]
21
+ end
22
+
23
+ # Creates webhook for the given project
24
+ #
25
+ # @see https://lokalise.co/api2docs/ruby/#transition-create-a-webhook-post
26
+ # @return [Lokalise::Resources::Webhook]
27
+ # @param project_id [String]
28
+ # @param params [Hash]
29
+ def create_webhook(project_id, params)
30
+ c_r Lokalise::Resources::Webhook, :create, project_id, params
31
+ end
32
+
33
+ # Updates webhook for the given project
34
+ #
35
+ # @see https://lokalise.co/api2docs/ruby/#transition-update-a-webhook-put
36
+ # @return [Lokalise::Resources::Webhook]
37
+ # @param project_id [String]
38
+ # @param webhook_id [String, Integer]
39
+ # @param params [Hash]
40
+ def update_webhook(project_id, webhook_id, params = {})
41
+ c_r Lokalise::Resources::Webhook, :update, [project_id, webhook_id], params
42
+ end
43
+
44
+ # Deletes webhook for the given project
45
+ #
46
+ # @see https://lokalise.co/api2docs/ruby/#transition-delete-a-webhook-delete
47
+ # @return [Hash]
48
+ # @param project_id [String]
49
+ # @param webhook_id [String, Integer]
50
+ def destroy_webhook(project_id, webhook_id)
51
+ c_r Lokalise::Resources::Webhook, :destroy, [project_id, webhook_id]
52
+ end
53
+ end
54
+ end
@@ -1,3 +1,3 @@
1
1
  module Lokalise
2
- VERSION = '2.5.0'.freeze
2
+ VERSION = '2.6.0'.freeze
3
3
  end
@@ -0,0 +1,74 @@
1
+ RSpec.describe Lokalise::Client do
2
+ let(:project_id) { '803826145ba90b42d5d860.46800099' }
3
+ let(:webhook_id) { 'c7eb7e6e3c2fb2b26d0b64d0de083a5a71675b3d' }
4
+ let(:new_webhook_id) { 'b345ccc6499920c490e8f4fe9487b1378dbf1dbf' }
5
+
6
+ describe '#webhooks' do
7
+ it 'should return all webhooks' do
8
+ webhooks = VCR.use_cassette('webhooks') do
9
+ test_client.webhooks project_id
10
+ end.collection
11
+
12
+ expect(webhooks.count).to eq(3)
13
+ expect(webhooks.first.url).to eq('https://serios.webhook')
14
+ end
15
+
16
+ it 'should support pagination' do
17
+ webhooks = VCR.use_cassette('all_webhooks_pagination') do
18
+ test_client.webhooks project_id, limit: 1, page: 2
19
+ end
20
+
21
+ expect(webhooks.collection.count).to eq(1)
22
+ expect(webhooks.total_results).to eq(3)
23
+ expect(webhooks.total_pages).to eq(3)
24
+ expect(webhooks.results_per_page).to eq(1)
25
+ expect(webhooks.current_page).to eq(2)
26
+ end
27
+ end
28
+
29
+ specify '#webhook' do
30
+ webhook = VCR.use_cassette('webhook') do
31
+ test_client.webhook project_id, webhook_id
32
+ end
33
+
34
+ expect(webhook.webhook_id).to eq(webhook_id)
35
+ expect(webhook.url).to eq('https://canihaz.hook')
36
+ expect(webhook.secret).to eq('a62450cd9eeca8dfc84f3c0cf9b7a6a370267d6f')
37
+ expect(webhook.events).to include('project.snapshot')
38
+ expect(webhook.event_lang_map.first['event']).to eq('project.translation.updated')
39
+ end
40
+
41
+ specify '#create_webhook' do
42
+ webhook = VCR.use_cassette('create_webhook') do
43
+ test_client.create_webhook project_id,
44
+ url: 'http://thatz.ahook',
45
+ events: ['project.imported', 'project.exported']
46
+ end
47
+
48
+ expect(webhook.webhook_id).to eq(new_webhook_id)
49
+ expect(webhook.url).to eq('http://thatz.ahook')
50
+ expect(webhook.events).to include('project.imported', 'project.exported')
51
+ end
52
+
53
+ specify '#update_webhook' do
54
+ webhook = VCR.use_cassette('update_webhook') do
55
+ test_client.update_webhook project_id,
56
+ new_webhook_id,
57
+ url: 'http://ihaz.cheezburger'
58
+ end
59
+
60
+ expect(webhook.webhook_id).to eq(new_webhook_id)
61
+ expect(webhook.url).to eq('http://ihaz.cheezburger')
62
+ expect(webhook.events).to include('project.imported', 'project.exported')
63
+ end
64
+
65
+ specify '#destroy_webhook' do
66
+ response = VCR.use_cassette('destroy_webhook') do
67
+ test_client.destroy_webhook project_id,
68
+ new_webhook_id
69
+ end
70
+
71
+ expect(response['project_id']).to eq(project_id)
72
+ expect(response['webhook_deleted']).to eq(true)
73
+ end
74
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lokalise-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Bodrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-01 00:00:00.000000000 Z
11
+ date: 2019-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -189,6 +189,7 @@ files:
189
189
  - lib/ruby-lokalise-api/collections/team_user_group.rb
190
190
  - lib/ruby-lokalise-api/collections/translation.rb
191
191
  - lib/ruby-lokalise-api/collections/translation_provider.rb
192
+ - lib/ruby-lokalise-api/collections/webhook.rb
192
193
  - lib/ruby-lokalise-api/connection.rb
193
194
  - lib/ruby-lokalise-api/data/attributes.json
194
195
  - lib/ruby-lokalise-api/error.rb
@@ -214,6 +215,7 @@ files:
214
215
  - lib/ruby-lokalise-api/resources/team_user_group.rb
215
216
  - lib/ruby-lokalise-api/resources/translation.rb
216
217
  - lib/ruby-lokalise-api/resources/translation_provider.rb
218
+ - lib/ruby-lokalise-api/resources/webhook.rb
217
219
  - lib/ruby-lokalise-api/rest/comments.rb
218
220
  - lib/ruby-lokalise-api/rest/contributors.rb
219
221
  - lib/ruby-lokalise-api/rest/custom_translation_statuses.rb
@@ -231,6 +233,7 @@ files:
231
233
  - lib/ruby-lokalise-api/rest/teams.rb
232
234
  - lib/ruby-lokalise-api/rest/translation_providers.rb
233
235
  - lib/ruby-lokalise-api/rest/translations.rb
236
+ - lib/ruby-lokalise-api/rest/webhooks.rb
234
237
  - lib/ruby-lokalise-api/utils/attribute_helpers.rb
235
238
  - lib/ruby-lokalise-api/utils/endpoint_helpers.rb
236
239
  - lib/ruby-lokalise-api/utils/string_utils.rb
@@ -256,6 +259,7 @@ files:
256
259
  - spec/lib/ruby-lokalise-api/rest/teams_spec.rb
257
260
  - spec/lib/ruby-lokalise-api/rest/translation_providers_spec.rb
258
261
  - spec/lib/ruby-lokalise-api/rest/translations_spec.rb
262
+ - spec/lib/ruby-lokalise-api/rest/webhooks_spec.rb
259
263
  - spec/lib/ruby-lokalise-api/utils/snakecase_spec.rb
260
264
  - spec/lib/ruby-lokalise-api_spec.rb
261
265
  - spec/spec_helper.rb
@@ -305,6 +309,7 @@ test_files:
305
309
  - spec/lib/ruby-lokalise-api/rest/team_user_groups_spec.rb
306
310
  - spec/lib/ruby-lokalise-api/rest/translations_spec.rb
307
311
  - spec/lib/ruby-lokalise-api/rest/translation_providers_spec.rb
312
+ - spec/lib/ruby-lokalise-api/rest/webhooks_spec.rb
308
313
  - spec/lib/ruby-lokalise-api/utils/snakecase_spec.rb
309
314
  - spec/lib/ruby-lokalise-api_spec.rb
310
315
  - spec/spec_helper.rb