ruby-lokalise-api 2.10.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) 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 +23 -0
  5. data/README.md +275 -180
  6. data/lib/ruby-lokalise-api.rb +2 -0
  7. data/lib/ruby-lokalise-api/client.rb +1 -0
  8. data/lib/ruby-lokalise-api/collections/base.rb +3 -2
  9. data/lib/ruby-lokalise-api/collections/queued_process.rb +15 -0
  10. data/lib/ruby-lokalise-api/data/attributes.json +12 -1
  11. data/lib/ruby-lokalise-api/resources/base.rb +33 -17
  12. data/lib/ruby-lokalise-api/resources/branch.rb +1 -1
  13. data/lib/ruby-lokalise-api/resources/contributor.rb +1 -1
  14. data/lib/ruby-lokalise-api/resources/custom_translation_status.rb +1 -1
  15. data/lib/ruby-lokalise-api/resources/file.rb +4 -1
  16. data/lib/ruby-lokalise-api/resources/key.rb +1 -1
  17. data/lib/ruby-lokalise-api/resources/key_comment.rb +1 -1
  18. data/lib/ruby-lokalise-api/resources/order.rb +2 -0
  19. data/lib/ruby-lokalise-api/resources/payment_card.rb +1 -1
  20. data/lib/ruby-lokalise-api/resources/project.rb +1 -1
  21. data/lib/ruby-lokalise-api/resources/queued_process.rb +18 -0
  22. data/lib/ruby-lokalise-api/resources/screenshot.rb +1 -1
  23. data/lib/ruby-lokalise-api/resources/snapshot.rb +3 -1
  24. data/lib/ruby-lokalise-api/resources/task.rb +1 -1
  25. data/lib/ruby-lokalise-api/resources/team_user.rb +1 -1
  26. data/lib/ruby-lokalise-api/resources/translation.rb +1 -1
  27. data/lib/ruby-lokalise-api/resources/webhook.rb +1 -1
  28. data/lib/ruby-lokalise-api/rest/comments.rb +5 -5
  29. data/lib/ruby-lokalise-api/rest/contributors.rb +5 -5
  30. data/lib/ruby-lokalise-api/rest/custom_translation_statuses.rb +6 -6
  31. data/lib/ruby-lokalise-api/rest/files.rb +3 -3
  32. data/lib/ruby-lokalise-api/rest/keys.rb +7 -7
  33. data/lib/ruby-lokalise-api/rest/languages.rb +6 -6
  34. data/lib/ruby-lokalise-api/rest/payment_cards.rb +3 -3
  35. data/lib/ruby-lokalise-api/rest/projects.rb +6 -6
  36. data/lib/ruby-lokalise-api/rest/queued_processes.rb +26 -0
  37. data/lib/ruby-lokalise-api/rest/screenshots.rb +5 -5
  38. data/lib/ruby-lokalise-api/rest/snapshots.rb +4 -4
  39. data/lib/ruby-lokalise-api/rest/tasks.rb +5 -5
  40. data/lib/ruby-lokalise-api/rest/team_users.rb +4 -4
  41. data/lib/ruby-lokalise-api/rest/teams.rb +1 -1
  42. data/lib/ruby-lokalise-api/rest/translation_providers.rb +2 -2
  43. data/lib/ruby-lokalise-api/rest/translations.rb +3 -3
  44. data/lib/ruby-lokalise-api/rest/webhooks.rb +5 -5
  45. data/lib/ruby-lokalise-api/version.rb +1 -1
  46. data/ruby-lokalise-api.gemspec +1 -2
  47. data/spec/lib/ruby-lokalise-api/error_spec.rb +8 -0
  48. data/spec/lib/ruby-lokalise-api/rest/branches_spec.rb +12 -0
  49. data/spec/lib/ruby-lokalise-api/rest/comments_spec.rb +12 -0
  50. data/spec/lib/ruby-lokalise-api/rest/contributors_spec.rb +12 -0
  51. data/spec/lib/ruby-lokalise-api/rest/custom_translation_statuses_spec.rb +12 -0
  52. data/spec/lib/ruby-lokalise-api/rest/files_spec.rb +17 -9
  53. data/spec/lib/ruby-lokalise-api/rest/keys_spec.rb +12 -0
  54. data/spec/lib/ruby-lokalise-api/rest/orders_spec.rb +12 -0
  55. data/spec/lib/ruby-lokalise-api/rest/payment_cards_spec.rb +12 -0
  56. data/spec/lib/ruby-lokalise-api/rest/projects_spec.rb +12 -0
  57. data/spec/lib/ruby-lokalise-api/rest/queued_processes_spec.rb +58 -0
  58. data/spec/lib/ruby-lokalise-api/rest/screenshots_spec.rb +12 -0
  59. data/spec/lib/ruby-lokalise-api/rest/snapshots_spec.rb +25 -0
  60. data/spec/lib/ruby-lokalise-api/rest/tasks_spec.rb +12 -0
  61. data/spec/lib/ruby-lokalise-api/rest/team_users_spec.rb +12 -0
  62. data/spec/lib/ruby-lokalise-api/rest/translations_spec.rb +12 -0
  63. data/spec/lib/ruby-lokalise-api/rest/webhooks_spec.rb +13 -0
  64. metadata +11 -6
@@ -4,7 +4,7 @@ module Lokalise
4
4
  class Client
5
5
  # Returns all teams available to the user
6
6
  #
7
- # @see https://lokalise.co/api2docs/ruby/#transition-list-all-teams-get
7
+ # @see https://app.lokalise.com/api2docs/curl/#transition-list-all-teams-get
8
8
  # @return [Lokalise::Collection::Team<Lokalise::Resources::Team>]
9
9
  # @param params [Hash]
10
10
  def teams(params = {})
@@ -4,7 +4,7 @@ module Lokalise
4
4
  class Client
5
5
  # Returns all translation providers for the given team
6
6
  #
7
- # @see https://lokalise.co/api2docs/ruby/#transition-list-all-providers-get
7
+ # @see https://app.lokalise.com/api2docs/curl/#transition-list-all-providers-get
8
8
  # @return [Lokalise::Collection::TranslationProvider<Lokalise::Resources::TranslationProvider>]
9
9
  # @param team_id [String]
10
10
  # @param params [Hash]
@@ -14,7 +14,7 @@ module Lokalise
14
14
 
15
15
  # Returns a single translation provider for the given team
16
16
  #
17
- # @see https://lokalise.co/api2docs/ruby/#transition-retrieve-a-provider-get
17
+ # @see https://app.lokalise.com/api2docs/curl/#transition-retrieve-a-provider-get
18
18
  # @return [Lokalise::Resources::TranslationProvider]
19
19
  # @param team_id [String]
20
20
  # @param provider_id [String, Integer]
@@ -4,7 +4,7 @@ module Lokalise
4
4
  class Client
5
5
  # Returns all translations for the given project (ungrouped)
6
6
  #
7
- # @see https://lokalise.co/api2docs/ruby/#transition-list-all-translations-get
7
+ # @see https://app.lokalise.com/api2docs/curl/#transition-list-all-translations-get
8
8
  # @return [Lokalise::Collection::Translation<Lokalise::Resources::Translation>]
9
9
  # @param project_id [String]
10
10
  # @param params [Hash]
@@ -14,7 +14,7 @@ module Lokalise
14
14
 
15
15
  # Returns translation of the given project
16
16
  #
17
- # @see https://lokalise.co/api2docs/ruby/#transition-retrieve-a-translation-get
17
+ # @see https://app.lokalise.com/api2docs/curl/#transition-retrieve-a-translation-get
18
18
  # @return [Lokalise::Resources::Translation]
19
19
  # @param project_id [String]
20
20
  # @param translation_id [String, Integer]
@@ -25,7 +25,7 @@ module Lokalise
25
25
 
26
26
  # Updates translation of the given project
27
27
  #
28
- # @see https://lokalise.co/api2docs/ruby/#transition-update-a-translation-put
28
+ # @see https://app.lokalise.com/api2docs/curl/#transition-update-a-translation-put
29
29
  # @return [Lokalise::Resources::Translation]
30
30
  # @param project_id [String]
31
31
  # @param translation_id [String, Integer]
@@ -4,7 +4,7 @@ module Lokalise
4
4
  class Client
5
5
  # Returns all webhooks for the given project
6
6
  #
7
- # @see https://lokalise.co/api2docs/ruby/#transition-list-all-webhooks-get
7
+ # @see https://app.lokalise.com/api2docs/curl/#transition-list-all-webhooks-get
8
8
  # @return [Lokalise::Collection::Webhook<Lokalise::Resources::Webhook>]
9
9
  # @param project_id [String]
10
10
  # @param params [Hash]
@@ -14,7 +14,7 @@ module Lokalise
14
14
 
15
15
  # Returns a single webhook for the given project
16
16
  #
17
- # @see https://lokalise.co/api2docs/ruby/#transition-retrieve-a-webhook-get
17
+ # @see https://app.lokalise.com/api2docs/curl/#transition-retrieve-a-webhook-get
18
18
  # @return [Lokalise::Resources::Webhook]
19
19
  # @param project_id [String]
20
20
  # @param webhook_id [String, Integer]
@@ -24,7 +24,7 @@ module Lokalise
24
24
 
25
25
  # Creates webhook for the given project
26
26
  #
27
- # @see https://lokalise.co/api2docs/ruby/#transition-create-a-webhook-post
27
+ # @see https://app.lokalise.com/api2docs/curl/#transition-create-a-webhook-post
28
28
  # @return [Lokalise::Resources::Webhook]
29
29
  # @param project_id [String]
30
30
  # @param params [Hash]
@@ -34,7 +34,7 @@ module Lokalise
34
34
 
35
35
  # Updates webhook for the given project
36
36
  #
37
- # @see https://lokalise.co/api2docs/ruby/#transition-update-a-webhook-put
37
+ # @see https://app.lokalise.com/api2docs/curl/#transition-update-a-webhook-put
38
38
  # @return [Lokalise::Resources::Webhook]
39
39
  # @param project_id [String]
40
40
  # @param webhook_id [String, Integer]
@@ -45,7 +45,7 @@ module Lokalise
45
45
 
46
46
  # Deletes webhook for the given project
47
47
  #
48
- # @see https://lokalise.co/api2docs/ruby/#transition-delete-a-webhook-delete
48
+ # @see https://app.lokalise.com/api2docs/curl/#transition-delete-a-webhook-delete
49
49
  # @return [Hash]
50
50
  # @param project_id [String]
51
51
  # @param webhook_id [String, Integer]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lokalise
4
- VERSION = '2.10.0'
4
+ VERSION = '3.0.0'
5
5
  end
@@ -12,7 +12,6 @@ Gem::Specification.new do |spec|
12
12
  spec.homepage = 'https://github.com/lokalise/ruby-lokalise-api'
13
13
  spec.license = 'MIT'
14
14
  spec.platform = Gem::Platform::RUBY
15
- spec.required_ruby_version = '>= 2.4.0'
16
15
 
17
16
  spec.files = Dir['README.md', 'LICENSE',
18
17
  'CHANGELOG.md', 'lib/**/*.rb', 'lib/ruby-lokalise-api/data/attributes.json',
@@ -28,7 +27,7 @@ Gem::Specification.new do |spec|
28
27
 
29
28
  spec.add_development_dependency 'codecov', '~> 0.1'
30
29
  spec.add_development_dependency 'dotenv', '~> 2.5'
31
- spec.add_development_dependency 'oj', '~> 3.8'
30
+ spec.add_development_dependency 'oj', '~> 3.10'
32
31
  spec.add_development_dependency 'rake', '~> 13.0'
33
32
  spec.add_development_dependency 'rspec', '~> 3.6'
34
33
  spec.add_development_dependency 'rubocop', '~> 0.60'
@@ -7,6 +7,14 @@ RSpec.describe Lokalise::Error do
7
7
 
8
8
  after { Lokalise.reset_client! }
9
9
 
10
+ it 'raises a generic error when the code is unknown' do
11
+ expect do
12
+ VCR.use_cassette('error_unknown_code') do
13
+ get 'projects', Lokalise.client('invalid')
14
+ end
15
+ end.to raise_error(described_class)
16
+ end
17
+
10
18
  it 'raises BadRequest when API token is invalid' do
11
19
  expect do
12
20
  VCR.use_cassette('error_invalid_token') do
@@ -40,6 +40,18 @@ RSpec.describe Lokalise::Client do
40
40
  expect(branch.created_by_email).to eq('bodrovis@protonmail.com')
41
41
  end
42
42
 
43
+ specify '#reload_data' do
44
+ branch = VCR.use_cassette('branch') do
45
+ test_client.branch project_id, branch_id
46
+ end
47
+
48
+ reloaded_branch = VCR.use_cassette('branch') do
49
+ branch.reload_data
50
+ end
51
+
52
+ expect(reloaded_branch.branch_id).to eq(branch.branch_id)
53
+ end
54
+
43
55
  specify '#create_branch' do
44
56
  branch = VCR.use_cassette('create_branch') do
45
57
  test_client.create_branch project_id, name: 'ruby-branch'
@@ -49,6 +49,18 @@ RSpec.describe Lokalise::Client do
49
49
  expect(comment.added_at_timestamp).to eq(1_544_380_904)
50
50
  end
51
51
 
52
+ specify '#reload_data' do
53
+ comment = VCR.use_cassette('comment') do
54
+ test_client.comment project_id, another_key_id, '800746'
55
+ end
56
+
57
+ reloaded_comment = VCR.use_cassette('comment') do
58
+ comment.reload_data
59
+ end
60
+
61
+ expect(reloaded_comment.key_id).to eq(comment.key_id)
62
+ end
63
+
52
64
  specify '#create_comments' do
53
65
  comments = VCR.use_cassette('create_comments') do
54
66
  test_client.create_comments project_id, key_id, [
@@ -48,6 +48,18 @@ RSpec.describe Lokalise::Client do
48
48
  expect(contributor.created_at_timestamp).to eq(1_534_865_725)
49
49
  end
50
50
 
51
+ specify '#reload_data' do
52
+ contributor = VCR.use_cassette('contributor') do
53
+ test_client.contributor project_id, '20181'
54
+ end
55
+
56
+ reloaded_contributor = VCR.use_cassette('contributor') do
57
+ contributor.reload_data
58
+ end
59
+
60
+ expect(reloaded_contributor.user_id).to eq(contributor.user_id)
61
+ end
62
+
51
63
  specify '#create_contributors' do
52
64
  contributor = VCR.use_cassette('create_contributors') do
53
65
  test_client.create_contributors project_id,
@@ -43,6 +43,18 @@ RSpec.describe Lokalise::Client do
43
43
  expect(status.color).to eq('#0079bf')
44
44
  end
45
45
 
46
+ specify '#reload_data' do
47
+ status = VCR.use_cassette('translation_status') do
48
+ test_client.translation_status project_id, status_id
49
+ end
50
+
51
+ reloaded_status = VCR.use_cassette('translation_status') do
52
+ status.reload_data
53
+ end
54
+
55
+ expect(reloaded_status.status_id).to eq(status.status_id)
56
+ end
57
+
46
58
  specify '#create_translation_status' do
47
59
  title = 'Reviewed by doctors'
48
60
  color = '#f2d600'
@@ -35,8 +35,8 @@ RSpec.describe Lokalise::Client do
35
35
  specify '#download_files' do
36
36
  response = VCR.use_cassette('download_files') do
37
37
  test_client.download_files project_id,
38
- "format": 'po',
39
- "original_filenames": true
38
+ format: 'po',
39
+ original_filenames: true
40
40
  end
41
41
 
42
42
  expect(response['project_id']).to eq(project_id)
@@ -44,15 +44,23 @@ RSpec.describe Lokalise::Client do
44
44
  end
45
45
 
46
46
  specify '#upload_file' do
47
- response = VCR.use_cassette('upload_file') do
47
+ process = VCR.use_cassette('upload_file') do
48
48
  test_client.upload_file project_id,
49
- "data": 'ZnI6DQogIHRlc3Q6IHRyYW5zbGF0aW9u',
50
- "filename": 'rspec.yml',
51
- 'lang_iso': 'ru'
49
+ data: 'ZnI6DQogIHRlc3Q6IHRyYW5zbGF0aW9u',
50
+ filename: 'rspec_async.yml',
51
+ lang_iso: 'ru'
52
52
  end
53
53
 
54
- expect(response['project_id']).to eq(project_id)
55
- expect(response['file']).to eq('rspec.yml')
56
- expect(response['result']['skipped']).to eq(1)
54
+ expect(process).to be_an_instance_of(Lokalise::Resources::QueuedProcess)
55
+ expect(process.process_id).to eq('ff1876382b7ba81f2bb465da8f030196ec401fa6')
56
+ expect(process.status).to eq('queued')
57
+
58
+ reloaded_process = VCR.use_cassette('upload_file_queued_reload') do
59
+ process.reload_data
60
+ end
61
+
62
+ expect(reloaded_process.process_id).to eq(process.process_id)
63
+ expect(reloaded_process.status).to eq('finished')
64
+ expect(reloaded_process.details['files'][0]['status']).to eq('finished')
57
65
  end
58
66
  end
@@ -58,6 +58,18 @@ RSpec.describe Lokalise::Client do
58
58
  expect(key.base_words).to eq(1)
59
59
  end
60
60
 
61
+ specify '#reload_data' do
62
+ key = VCR.use_cassette('key') do
63
+ test_client.key project_id, key_id, disable_references: 0
64
+ end
65
+
66
+ reloaded_key = VCR.use_cassette('key') do
67
+ key.reload_data disable_references: 0
68
+ end
69
+
70
+ expect(reloaded_key.key_id).to eq(key.key_id)
71
+ end
72
+
61
73
  specify '#create_keys' do
62
74
  keys = VCR.use_cassette('create_keys') do
63
75
  test_client.create_keys project_id, key_name: 'rspec_k', platforms: %w[ios]
@@ -54,6 +54,18 @@ RSpec.describe Lokalise::Client do
54
54
  expect(order.total).to eq(0.07)
55
55
  end
56
56
 
57
+ specify '#reload_data' do
58
+ order = VCR.use_cassette('order') do
59
+ test_client.order team_id, order_id
60
+ end
61
+
62
+ reloaded_order = VCR.use_cassette('order') do
63
+ order.reload_data
64
+ end
65
+
66
+ expect(reloaded_order.order_id).to eq(order.order_id)
67
+ end
68
+
57
69
  specify '#create_order' do
58
70
  order = VCR.use_cassette('create_order') do
59
71
  test_client.create_order team_id,
@@ -55,6 +55,18 @@ RSpec.describe Lokalise::Client do
55
55
  expect(card.created_at).to eq('2019-03-19 17:01:22 (Etc/UTC)')
56
56
  end
57
57
 
58
+ specify '#reload_data' do
59
+ card = VCR.use_cassette('payment_card') do
60
+ test_client.payment_card card_id
61
+ end
62
+
63
+ reloaded_card = VCR.use_cassette('payment_card') do
64
+ card.reload_data
65
+ end
66
+
67
+ expect(reloaded_card.card_id).to eq(card.card_id)
68
+ end
69
+
58
70
  specify '#destroy_payment_card' do
59
71
  result = VCR.use_cassette('destroy_payment_card') do
60
72
  test_client.destroy_payment_card card_id
@@ -51,6 +51,18 @@ RSpec.describe Lokalise::Client do
51
51
  expect(project.statistics['progress_total']).to eq(18)
52
52
  end
53
53
 
54
+ specify '#reload_data' do
55
+ project = VCR.use_cassette('project') do
56
+ test_client.project '803826145ba90b42d5d860.46800099'
57
+ end
58
+
59
+ reloaded_project = VCR.use_cassette('project') do
60
+ project.reload_data
61
+ end
62
+
63
+ expect(reloaded_project.project_id).to eq(project.project_id)
64
+ end
65
+
54
66
  specify '#create_project' do
55
67
  project = VCR.use_cassette('new_project') do
56
68
  test_client.create_project name: 'rspec proj', description: 'demo project for rspec'
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Lokalise::Client do
4
+ let(:project_id) { '803826145ba90b42d5d860.46800099' }
5
+ let(:process_id) { '3b943469e6b3e324b5bdad639b122a623e6e7a1a' }
6
+ let(:queued_process_id) { 'ff1876382b7ba81f2bb465da8f030196ec401fa6' }
7
+
8
+ describe '#queued_processes' do
9
+ it 'returns all queued processes' do
10
+ processes = VCR.use_cassette('all_queued_processes') do
11
+ test_client.queued_processes project_id
12
+ end
13
+
14
+ expect(processes.branch).to eq('master')
15
+ processes = processes.collection
16
+ puts processes.count
17
+ expect(processes.count).to eq(8)
18
+ expect(processes.first.process_id).to eq(process_id)
19
+ end
20
+ end
21
+
22
+ specify '#queued_process' do
23
+ process = VCR.use_cassette('queued_process') do
24
+ test_client.queued_process project_id, process_id
25
+ end
26
+
27
+ expect(process.branch).to eq('master')
28
+ expect(process.process_id).to eq(process_id)
29
+ expect(process.type).to eq('file-import')
30
+ expect(process.status).to eq('finished')
31
+ expect(process.message).to eq('')
32
+ expect(process.created_by).to eq(20_181)
33
+ expect(process.created_by_email).to eq('bodrovis@protonmail.com')
34
+ expect(process.created_at).to eq('2020-05-13 11:24:37 (Etc/UTC)')
35
+ expect(process.created_at_timestamp).to eq(1_589_369_077)
36
+ files = process.details['files']
37
+ expect(files.count).to eq(1)
38
+ expect(files[0]['status']).to eq('finished')
39
+ expect(files[0]['name_original']).to eq('test_async.json')
40
+ end
41
+
42
+ describe 'process status check' do
43
+ specify '#reload_data' do
44
+ queued_process = VCR.use_cassette('upload_file_status') do
45
+ test_client.queued_process project_id, queued_process_id
46
+ end
47
+
48
+ expect(queued_process.status).to eq('queued')
49
+
50
+ reloaded_process = VCR.use_cassette('upload_file_queued_reload') do
51
+ queued_process.reload_data
52
+ end
53
+
54
+ expect(reloaded_process.process_id).to eq(queued_process.process_id)
55
+ expect(reloaded_process.status).to eq('finished')
56
+ end
57
+ end
58
+ end
@@ -41,6 +41,18 @@ RSpec.describe Lokalise::Client do
41
41
  expect(screenshot.height).to eq(32)
42
42
  end
43
43
 
44
+ specify '#reload_data' do
45
+ screenshot = VCR.use_cassette('screenshot') do
46
+ test_client.screenshot project_id, screenshot_id
47
+ end
48
+
49
+ reloaded_screenshot = VCR.use_cassette('screenshot') do
50
+ screenshot.reload_data
51
+ end
52
+
53
+ expect(reloaded_screenshot.screenshot_id).to eq(screenshot.screenshot_id)
54
+ end
55
+
44
56
  specify '#create_screenshots' do
45
57
  screenshot_from_file do |file|
46
58
  screenshot = VCR.use_cassette('create_screenshots') do
@@ -68,6 +68,31 @@ RSpec.describe Lokalise::Client do
68
68
  end
69
69
 
70
70
  context 'when snapshot methods are chained' do
71
+ it 'allows restored project to receive chained methods' do
72
+ snapshot = VCR.use_cassette('create_snapshot_for_chained') do
73
+ test_client.create_snapshot project_id, title: 'chained rspec snap'
74
+ end
75
+
76
+ new_project = VCR.use_cassette('restore_snapshot_for_chained') do
77
+ snapshot.restore
78
+ end
79
+
80
+ updated_project = VCR.use_cassette('restored_updated_project') do
81
+ new_project.update name: 'Restored and updated'
82
+ end
83
+
84
+ expect(updated_project.client).to eq(test_client)
85
+ expect(updated_project.name).to eq('Restored and updated')
86
+ expect(updated_project.project_id).to eq(new_project.project_id)
87
+
88
+ response = VCR.use_cassette('delete_restored_project') do
89
+ updated_project.destroy
90
+ end
91
+
92
+ expect(response['project_id']).to eq(updated_project.project_id)
93
+ expect(response['project_deleted']).to eq(true)
94
+ end
95
+
71
96
  it 'supports destroy and restore' do
72
97
  snapshot = VCR.use_cassette('create_another_snapshot') do
73
98
  test_client.create_snapshot project_id, title: 'chained'