crowdin-api 1.9.0 → 1.11.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: eb6299e8ac24c4e3bf9e7bbcf3d9741ded36842d56a7e294f9f534f4c05535a5
4
- data.tar.gz: 04a58a1803638e00dd1c8b6a833fed4b8e01f56d19201a272ecbdeca4e0fd515
3
+ metadata.gz: 22ed7c31fb89ca5299a07d1fe3c828f7686e36d74ad710dc5e1b115598f90fe7
4
+ data.tar.gz: fd8069c348ff758595bbc18a3f8684f6d220b1a53d00fac2fc0af0751b213087
5
5
  SHA512:
6
- metadata.gz: bb87a4d984c5f9955ac03908ba2d57eaa4ad5a06723de4683f513e3cf696a6b1013bcc1d2473a2aa231eea207afb8688a0baff61d9acc67fa53351a5284eaddd
7
- data.tar.gz: d11b9902322de9ff89c6575e0b7915968d5627d887c144bcbe196021056399d80ded2f0ccae66e4a1b88eb8124b080f28cc30b552ca4df25d64b829bc4071ec6
6
+ metadata.gz: 6014441ccc9d7c0a1e6a11e20611ee686cff396da2d596c12a1293d701f0395d5ff4adc730098301b4563f3167e5d7af54d15579e401578f822dadeb65066101
7
+ data.tar.gz: afa63e70a5616430e750429bb5b99e4d30e89ae92bbec440eb3fa2e5b7fbeb1319ff4c4947812ae8878597cd7850725f58018c094aa6d0ea2a02230b0ed8e799
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- crowdin-api (1.9.0)
4
+ crowdin-api (1.11.0)
5
5
  open-uri (>= 0.1.0, < 0.2.0)
6
6
  rest-client (>= 2.0.0, < 2.2.0)
7
7
 
@@ -39,7 +39,7 @@ GEM
39
39
  public_suffix (5.0.4)
40
40
  racc (1.7.3)
41
41
  rainbow (3.1.1)
42
- rake (13.1.0)
42
+ rake (13.2.1)
43
43
  regexp_parser (2.8.3)
44
44
  rest-client (2.1.0)
45
45
  http-accept (>= 1.7.0, < 2.0)
data/README.md CHANGED
@@ -35,7 +35,7 @@ Crowdin API is a full-featured RESTful API that helps you to integrate localizat
35
35
  Add this line to your application's Gemfile:
36
36
 
37
37
  ```gemfile
38
- gem 'crowdin-api', '~> 1.9.0'
38
+ gem 'crowdin-api', '~> 1.11.0'
39
39
  ```
40
40
 
41
41
  And then execute:
@@ -78,6 +78,7 @@ crowdin = Crowdin::Client.new do |config|
78
78
  config.organization_domain = 'YourOrganizationDomain' # [String] optional
79
79
  config.project_id = 'YourProjectId' # [Integer] nil by default
80
80
  config.enable_logger = true # [Boolean] false by default
81
+ config.request_timeout = 60 # [nil, Integer] disabled by default
81
82
  end
82
83
  # Note: Client will initialize default Logger instance if you have specify
83
84
  # enable_logger to true, you can change it by crowdin.logger = YourLogger
@@ -84,7 +84,37 @@ module Crowdin
84
84
  response = ::RestClient::Request.execute(
85
85
  {
86
86
  method: :delete,
87
- url: config.base_url + config.target_api_url + "/projects/#{project_id}/labels/#{label_id}",
87
+ url: config.base_url + config.target_api_url + "/projects/#{project_id}/labels/#{label_id}/strings",
88
+ payload: query.to_json
89
+ }.merge(@options)
90
+ )
91
+
92
+ response.body.empty? ? response.code : JSON.parse(response.body)
93
+ rescue StandardError => e
94
+ e.message
95
+ end
96
+
97
+ def assign_label_to_screenshots(label_id = nil, query = {}, project_id = config.project_id)
98
+ label_id || raise_parameter_is_required_error(:label_id)
99
+ project_id || raise_project_id_is_required_error
100
+
101
+ request = Web::Request.new(
102
+ connection,
103
+ :post,
104
+ "#{config.target_api_url}/projects/#{project_id}/labels/#{label_id}/screenshots",
105
+ { params: query }
106
+ )
107
+ Web::SendRequest.new(request).perform
108
+ end
109
+
110
+ def unassign_label_from_screenshots(label_id = nil, query = {}, project_id = config.project_id)
111
+ label_id || raise_parameter_is_required_error(:label_id)
112
+ project_id || raise_project_id_is_required_error
113
+
114
+ response = ::RestClient::Request.execute(
115
+ {
116
+ method: :delete,
117
+ url: config.base_url + config.target_api_url + "/projects/#{project_id}/labels/#{label_id}/screenshots",
88
118
  payload: query.to_json
89
119
  }.merge(@options)
90
120
  )
@@ -64,6 +64,18 @@ module Crowdin
64
64
  )
65
65
  Web::SendRequest.new(request).perform
66
66
  end
67
+
68
+ def string_batch_operations(query = {}, project_id = config.project_id)
69
+ project_id || raise_project_id_is_required_error
70
+
71
+ request = Web::Request.new(
72
+ connection,
73
+ :patch,
74
+ "#{config.target_api_url}/projects/#{project_id}/strings",
75
+ { params: query }
76
+ )
77
+ Web::SendRequest.new(request).perform
78
+ end
67
79
  end
68
80
  end
69
81
  end
@@ -5,6 +5,7 @@ module Crowdin
5
5
  attr_accessor :api_token
6
6
  attr_accessor :project_id
7
7
  attr_accessor :organization_domain
8
+ attr_accessor :request_timeout
8
9
 
9
10
  attr_accessor :enable_logger
10
11
  alias logger_enabled? enable_logger
@@ -18,7 +19,7 @@ module Crowdin
18
19
  def options
19
20
  {
20
21
  headers: {},
21
- timeout: nil,
22
+ timeout: request_timeout,
22
23
  json: true
23
24
  }
24
25
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Crowdin
4
4
  class Client
5
- VERSION = '1.9.0'
5
+ VERSION = '1.11.0'
6
6
  end
7
7
  end
@@ -3,7 +3,7 @@
3
3
  describe Crowdin::ApiResources::Labels do
4
4
  describe 'Default endpoints' do
5
5
  describe '#list_labels' do
6
- it 'when request are valid', :default do
6
+ it 'returns 200 when request is valid', :default do
7
7
  stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels")
8
8
  list_labels = @crowdin.list_labels({}, project_id)
9
9
  expect(list_labels).to eq(200)
@@ -11,7 +11,7 @@ describe Crowdin::ApiResources::Labels do
11
11
  end
12
12
 
13
13
  describe '#add_label' do
14
- it 'when request are valid', :default do
14
+ it 'returns 200 when request is valid', :default do
15
15
  stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels")
16
16
  add_label = @crowdin.add_label({}, project_id)
17
17
  expect(add_label).to eq(200)
@@ -21,7 +21,7 @@ describe Crowdin::ApiResources::Labels do
21
21
  describe '#get_label' do
22
22
  let(:label_id) { 1 }
23
23
 
24
- it 'when request are valid', :default do
24
+ it 'returns 200 when request is valid', :default do
25
25
  stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}")
26
26
  get_label = @crowdin.get_label(label_id, project_id)
27
27
  expect(get_label).to eq(200)
@@ -31,7 +31,7 @@ describe Crowdin::ApiResources::Labels do
31
31
  describe '#delete_label' do
32
32
  let(:label_id) { 1 }
33
33
 
34
- it 'when request are valid', :default do
34
+ it 'returns 200 when request is valid', :default do
35
35
  stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}")
36
36
  delete_label = @crowdin.delete_label(label_id, project_id)
37
37
  expect(delete_label).to eq(200)
@@ -41,7 +41,7 @@ describe Crowdin::ApiResources::Labels do
41
41
  describe '#edit_label' do
42
42
  let(:label_id) { 1 }
43
43
 
44
- it 'when request are valid', :default do
44
+ it 'returns 200 when request is valid', :default do
45
45
  stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}")
46
46
  edit_label = @crowdin.edit_label(label_id, {}, project_id)
47
47
  expect(edit_label).to eq(200)
@@ -51,7 +51,7 @@ describe Crowdin::ApiResources::Labels do
51
51
  describe '#assign_label_to_strings' do
52
52
  let(:label_id) { 1 }
53
53
 
54
- it 'when request are valid', :default do
54
+ it 'returns 200 when request is valid', :default do
55
55
  stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}/strings")
56
56
  assign_label_to_strings = @crowdin.assign_label_to_strings(label_id, {}, project_id)
57
57
  expect(assign_label_to_strings).to eq(200)
@@ -61,11 +61,43 @@ describe Crowdin::ApiResources::Labels do
61
61
  describe '#unassign_label_from_strings' do
62
62
  let(:label_id) { 1 }
63
63
 
64
- it 'when request are valid', :default do
65
- stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}")
64
+ it 'returns 200 when request is valid', :default do
65
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}/strings")
66
66
  unassign_label_from_strings = @crowdin.unassign_label_from_strings(label_id, {}, project_id)
67
67
  expect(unassign_label_from_strings).to eq(200)
68
68
  end
69
+
70
+ it 'returns error message when request was processed with an error' do
71
+ allow(RestClient::Request).to receive(:execute).and_raise('Error')
72
+ unassign_label_from_strings = @crowdin.unassign_label_from_strings(label_id, {}, project_id)
73
+ expect(unassign_label_from_strings).to eq('Error')
74
+ end
75
+ end
76
+
77
+ describe '#assign_label_to_screenshots' do
78
+ let(:label_id) { 1 }
79
+
80
+ it 'returns 200 when request is valid', :default do
81
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}/screenshots")
82
+ assign_label_to_screenshots = @crowdin.assign_label_to_screenshots(label_id, {}, project_id)
83
+ expect(assign_label_to_screenshots).to eq(200)
84
+ end
85
+ end
86
+
87
+ describe '#unassign_label_from_screenshots' do
88
+ let(:label_id) { 1 }
89
+
90
+ it 'returns 200 when request is valid', :default do
91
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/labels/#{label_id}/screenshots")
92
+ unassign_label_from_screenshots = @crowdin.unassign_label_from_screenshots(label_id, {}, project_id)
93
+ expect(unassign_label_from_screenshots).to eq(200)
94
+ end
95
+
96
+ it 'returns error message when request was processed with an error' do
97
+ allow(RestClient::Request).to receive(:execute).and_raise('Error')
98
+ unassign_label_from_screenshots = @crowdin.unassign_label_from_screenshots(label_id, {}, project_id)
99
+ expect(unassign_label_from_screenshots).to eq('Error')
100
+ end
69
101
  end
70
102
  end
71
103
  end
@@ -3,7 +3,7 @@
3
3
  describe Crowdin::ApiResources::SourceStrings do
4
4
  describe 'Default endpoints' do
5
5
  describe '#list_strings' do
6
- it 'when request are valid', :default do
6
+ it 'returns 200 when request is valid', :default do
7
7
  stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/strings")
8
8
  list_strings = @crowdin.list_strings({}, project_id)
9
9
  expect(list_strings).to eq(200)
@@ -11,7 +11,7 @@ describe Crowdin::ApiResources::SourceStrings do
11
11
  end
12
12
 
13
13
  describe '#add_string' do
14
- it 'when request are valid', :default do
14
+ it 'returns 200 when request is valid', :default do
15
15
  stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/strings")
16
16
  add_string = @crowdin.add_string({}, project_id)
17
17
  expect(add_string).to eq(200)
@@ -21,7 +21,7 @@ describe Crowdin::ApiResources::SourceStrings do
21
21
  describe '#get_string' do
22
22
  let(:string_id) { 1 }
23
23
 
24
- it 'when request are valid', :default do
24
+ it 'returns 200 when request is valid', :default do
25
25
  stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/strings/#{string_id}")
26
26
  get_string = @crowdin.get_string(string_id, {}, project_id)
27
27
  expect(get_string).to eq(200)
@@ -31,7 +31,7 @@ describe Crowdin::ApiResources::SourceStrings do
31
31
  describe '#delete_string' do
32
32
  let(:string_id) { 1 }
33
33
 
34
- it 'when request are valid', :default do
34
+ it 'returns 200 when request is valid', :default do
35
35
  stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/strings/#{string_id}")
36
36
  delete_string = @crowdin.delete_string(string_id, project_id)
37
37
  expect(delete_string).to eq(200)
@@ -41,11 +41,19 @@ describe Crowdin::ApiResources::SourceStrings do
41
41
  describe '#edit_string' do
42
42
  let(:string_id) { 1 }
43
43
 
44
- it 'when request are valid', :default do
44
+ it 'returns 200 when request is valid', :default do
45
45
  stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/strings/#{string_id}")
46
46
  edit_string = @crowdin.edit_string(string_id, {}, project_id)
47
47
  expect(edit_string).to eq(200)
48
48
  end
49
49
  end
50
+
51
+ describe '#string_batch_operations' do
52
+ it 'returns 200 when request is valid', :default do
53
+ stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/strings")
54
+ string_batch_operations = @crowdin.string_batch_operations({}, project_id)
55
+ expect(string_batch_operations).to eq(200)
56
+ end
57
+ end
50
58
  end
51
59
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe 'Crowdin Client' do
4
+ let(:crowdin_client) { Crowdin::Client.new }
5
+
4
6
  it 'should have a list of API Resources' do
5
7
  expect(Crowdin::API_RESOURCES_MODULES).to_not be_nil
6
8
  end
@@ -21,6 +23,7 @@ describe 'Crowdin Client' do
21
23
  it 'should have options and headers for RestClient', :default do
22
24
  expect(@crowdin.options.class).to eq(Hash)
23
25
  expect(@crowdin.options).to include(:headers)
26
+ expect(@crowdin.options).to include(timeout: nil)
24
27
  end
25
28
 
26
29
  it 'should have a Config instance', :default do
@@ -94,4 +97,26 @@ describe 'Crowdin Client' do
94
97
  expect { @crowdin.fetch_all(:export_bundle).to raise_error(Crowdin::Errors::FetchAllProcessingError) }
95
98
  end
96
99
  end
100
+
101
+ describe 'connection' do
102
+ subject(:connection) { crowdin_client.connection }
103
+
104
+ it 'timeout is disabled by default' do
105
+ is_expected.to have_attributes(options: include(timeout: be_nil))
106
+ end
107
+
108
+ context 'when new request timeout config is set' do
109
+ let(:new_request_timeout) { 60 }
110
+
111
+ let(:crowdin_client) do
112
+ Crowdin::Client.new do |config|
113
+ config.request_timeout = new_request_timeout
114
+ end
115
+ end
116
+
117
+ it 'timeout option is changed to new value' do
118
+ is_expected.to have_attributes(options: include(timeout: new_request_timeout))
119
+ end
120
+ end
121
+ end
97
122
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crowdin-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Crowdin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-17 00:00:00.000000000 Z
11
+ date: 2024-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: open-uri
@@ -286,7 +286,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
286
  - !ruby/object:Gem::Version
287
287
  version: '0'
288
288
  requirements: []
289
- rubygems_version: 3.5.3
289
+ rubygems_version: 3.5.9
290
290
  signing_key:
291
291
  specification_version: 4
292
292
  summary: Ruby Client for the Crowdin API