crowdin-api 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65f8ac7742b9d609ae45c9f63c6772903990c3a4a853e8a2759e1401d82342cd
4
- data.tar.gz: e1e2739d09730e35b083316b891b8e43d8d6a3cb7845e7200a4940d461fb80cd
3
+ metadata.gz: cc71aeec74dd34cef85bb90b9accdd273d18ce3fd8ba9888eb3ce6a073e6aff0
4
+ data.tar.gz: 39e8290a34930ad659e1ad5879f4f91283f82f88f2316c7f64f03ef524de35cc
5
5
  SHA512:
6
- metadata.gz: b204059241859851f34e3cb9a5e04109536aaac231a4b0bb5e08577974832dc29df7eed547844a9ccdf4e668281e97c731c3f913fc4ec3f671a04ef5bd5b770f
7
- data.tar.gz: 7acb153132b0634bff479f0e5a038f1ef73281b19bb6700b723788d248f7e48f97e3bf216c6e53b89f788fb20b463982f1edcfc0c34d027d928d69c9f9f38f40
6
+ metadata.gz: d95cbb784a0148eab14bce79dff1dd70735e60aecad95f3be2402ac525581bae5c42dfce8f888ab7255fa3096f7153201a3256d3a6f41821a35f9eaec215abab
7
+ data.tar.gz: 4b9604fa346136d64a69beb7643beff66433cbbc9102242f56bac6b3f9ebd23e29cc70339e63b9c1a754ce77cf71a6c624d1b97120a5b7f82fb3dbdcb3b23054
data/.gitignore CHANGED
@@ -1,9 +1,12 @@
1
- # Ruby logs
1
+ # Ignore Ruby logs
2
2
  .ruby-version
3
3
  .idea
4
4
 
5
- # MacOS logs
5
+ # Ignore MacOS logs
6
6
  .DS_Store
7
7
 
8
- # Versioning
8
+ # Ignore versioning file
9
9
  Gemfile.lock
10
+
11
+ # Ignore tests coverage folder
12
+ coverage
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2021-11-29 03:21:36 UTC using RuboCop version 1.23.0.
3
+ # on 2021-12-13 20:26:23 UTC using RuboCop version 1.23.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -21,6 +21,13 @@ Gemspec/RequiredRubyVersion:
21
21
  Exclude:
22
22
  - 'crowdin-api.gemspec'
23
23
 
24
+ # Offense count: 2
25
+ # Cop supports --auto-correct.
26
+ # Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
27
+ Layout/ExtraSpacing:
28
+ Exclude:
29
+ - 'bin/crowdin-console'
30
+
24
31
  # Offense count: 1
25
32
  # Cop supports --auto-correct.
26
33
  # Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
@@ -29,20 +36,21 @@ Layout/SpaceAroundOperators:
29
36
  Exclude:
30
37
  - 'crowdin-api.gemspec'
31
38
 
32
- # Offense count: 1
33
- Lint/MissingSuper:
34
- Exclude:
35
- - 'lib/crowdin-api/core/errors.rb'
36
-
37
39
  # Offense count: 2
38
40
  # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
39
41
  Metrics/AbcSize:
40
- Max: 20
42
+ Max: 23
43
+
44
+ # Offense count: 1
45
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
46
+ # IgnoredMethods: refine
47
+ Metrics/BlockLength:
48
+ Max: 54
41
49
 
42
50
  # Offense count: 4
43
51
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
44
52
  Metrics/MethodLength:
45
- Max: 14
53
+ Max: 18
46
54
 
47
55
  # Offense count: 2
48
56
  # Configuration parameters: CountComments, CountAsOne.
@@ -69,6 +77,13 @@ Naming/FileName:
69
77
  - 'spec/core/config-instance_spec.rb'
70
78
  - 'spec/crowdin-api_spec.rb'
71
79
 
80
+ # Offense count: 3
81
+ # Configuration parameters: EnforcedStyleForLeadingUnderscores.
82
+ # SupportedStylesForLeadingUnderscores: disallowed, required, optional
83
+ Naming/MemoizedInstanceVariableName:
84
+ Exclude:
85
+ - 'lib/crowdin-api/client/client.rb'
86
+
72
87
  # Offense count: 3
73
88
  # Cop supports --auto-correct.
74
89
  # Configuration parameters: PreferredName.
@@ -85,13 +100,13 @@ Style/AccessorGrouping:
85
100
  - 'lib/crowdin-api/client/client.rb'
86
101
  - 'lib/crowdin-api/client/configuration.rb'
87
102
 
88
- # Offense count: 1
103
+ # Offense count: 2
89
104
  # Cop supports --auto-correct.
90
105
  Style/CollectionCompact:
91
106
  Exclude:
92
- - 'lib/crowdin-api/core/payload.rb'
107
+ - 'lib/crowdin-api/core/request.rb'
93
108
 
94
- # Offense count: 11
109
+ # Offense count: 12
95
110
  # Configuration parameters: AllowedConstants.
96
111
  Style/Documentation:
97
112
  Exclude:
@@ -100,13 +115,14 @@ Style/Documentation:
100
115
  - 'lib/crowdin-api/api-resources/languages.rb'
101
116
  - 'lib/crowdin-api/api-resources/projects.rb'
102
117
  - 'lib/crowdin-api/api-resources/source_files.rb'
118
+ - 'lib/crowdin-api/api-resources/source_strings.rb'
103
119
  - 'lib/crowdin-api/api-resources/storages.rb'
104
120
  - 'lib/crowdin-api/api-resources/translation_status.rb'
105
121
  - 'lib/crowdin-api/api-resources/translations.rb'
122
+ - 'lib/crowdin-api/api-resources/workflows.rb'
106
123
  - 'lib/crowdin-api/client/client.rb'
107
124
  - 'lib/crowdin-api/client/configuration.rb'
108
- - 'lib/crowdin-api/core/errors.rb'
109
- - 'lib/crowdin-api/core/payload.rb'
125
+ - 'lib/crowdin-api/core/api_errors_raiser.rb'
110
126
  - 'lib/crowdin-api/core/request.rb'
111
127
 
112
128
  # Offense count: 1
@@ -116,3 +132,8 @@ Style/Documentation:
116
132
  Style/FrozenStringLiteralComment:
117
133
  Exclude:
118
134
  - 'bin/crowdin-console'
135
+
136
+ # Offense count: 1
137
+ Style/MixinUsage:
138
+ Exclude:
139
+ - 'bin/crowdin-console'
data/README.md CHANGED
@@ -17,11 +17,9 @@ For more about Crowdin API v2 see the documentation:
17
17
  [![Gem](https://img.shields.io/gem/dtv/crowdin-api?cacheSeconds=1800)](https://rubygems.org/gems/crowdin-api)
18
18
 
19
19
  [![Test and Lint](https://github.com/crowdin/crowdin-api-client-ruby/actions/workflows/test-and-lint.yml/badge.svg)](https://github.com/crowdin/crowdin-api-client-ruby/actions/workflows/test-and-lint.yml)
20
- [![Build and Publish](https://github.com/crowdin/crowdin-api-client-ruby/actions/workflows/build-and-publish.yml/badge.svg)](https://github.com/crowdin/crowdin-api-client-ruby/actions/workflows/build-and-publish.yml)
21
- [![codecov](https://codecov.io/gh/crowdin/crowdin-api-client-ruby/branch/master/graph/badge.svg?token=OJsyJwQbFM)](https://codecov.io/gh/crowdin/crowdin-api-client-ruby)
22
-
20
+ [![codecov](https://codecov.io/gh/crowdin/crowdin-api-client-ruby/branch/main/graph/badge.svg?token=OJsyJwQbFM)](https://codecov.io/gh/crowdin/crowdin-api-client-ruby)
23
21
  [![GitHub issues](https://img.shields.io/github/issues/crowdin/crowdin-api-client-ruby?cacheSeconds=1800)](https://github.com/crowdin/crowdin-api-client-ruby/issues)
24
- [![GitHub](https://img.shields.io/github/license/crowdin/crowdin-api-client-ruby?cacheSeconds=18000)](https://github.com/crowdin/crowdin-api-client-ruby/blob/main/LICENSE)
22
+ [![GitHub](https://img.shields.io/github/license/crowdin/crowdin-api-client-ruby?cacheSeconds=1800)](https://github.com/crowdin/crowdin-api-client-ruby/blob/main/LICENSE)
25
23
 
26
24
  ## Table of Contents
27
25
  * [Installation](#installation)
@@ -38,7 +36,7 @@ For more about Crowdin API v2 see the documentation:
38
36
  Add this line to your application's Gemfile:
39
37
 
40
38
  ```gemfile
41
- gem 'crowdin-api', '~> 1.0.0'
39
+ gem 'crowdin-api', '~> 1.1.0'
42
40
  ```
43
41
 
44
42
  And then execute:
@@ -67,25 +65,31 @@ gem install crowdin-api
67
65
  ```ruby
68
66
  require 'crowdin-api'
69
67
 
70
- # Create a new Crowdin Client object.
68
+ # Initialize a new Client instance with config options
71
69
  crowdin = Crowdin::Client.new do |config|
72
70
  config.api_token = 'YourApiToken'
73
71
  end
74
- # or you can create Enterprise instance by specify your organization_domain
72
+
73
+ # Or you can intialize Enterprise Client instance by specifying your organization_domain in config options
75
74
  crowdin = Crowdin::Client.new do |config|
76
75
  config.api_token = 'YourEnterpriseApiToken'
77
76
  config.organization_domain = 'YourOrganizationDomain'
78
77
  end
78
+ # Note: we use full specified organization domain if that includes .com
79
+ # config.organization_domain = your_domain -> https://your_domain.api.crowdin.com
80
+ # config.organization_domain = your_domain.com -> your_domain.com
79
81
 
80
- # Also you can specify project_id to handle it in methods
81
-
82
- # All Crowdin Client config options:
82
+ # All supported Crowdin Client config options now:
83
83
  crowdin = Crowdin::Client.new do |config|
84
84
  config.api_token = 'YourApiToken' # [String] required
85
85
  config.organization_domain = 'YourOrganizationDomain' # [String] optional
86
86
  config.project_id = 'YourProjectId' # [Integer] nil by default
87
87
  config.enable_logger = true # [Boolean] false by default
88
88
  end
89
+ # Note: Client will initialize default Logger instance if you have specify enable_logger to true,
90
+ # you can change it by crowdin.logger = YourLogger
91
+
92
+ # Also you can specify proxy by adding it to ENV['http_proxy'] before Client initialization
89
93
  ```
90
94
 
91
95
  To generate a new token in Crowdin, follow these steps:
@@ -96,25 +100,25 @@ To generate a new token in Crowdin Enterprise, follow these steps:
96
100
  - Go to *Account Settings* > *Access tokens* tab and click *New token*.
97
101
  - Specify *Token Name*, select *Scopes* and *Projects*, click *Create*.
98
102
 
99
- ### How to call methods
103
+ ### Usage
100
104
 
101
105
  ```ruby
102
106
  # Create Project
103
107
  project = crowdin.add_project(name: your_project_name, sourceLanguageId: your_language_id)
104
108
 
105
109
  # Get list of Projects
106
- projects = client.list_projects
107
-
108
- # Get specified project
109
- project = client.get_project(your_project_id)
110
+ projects = crowdin.list_projects
110
111
 
111
112
  # Get list of Projects with offset and limit
112
- projects = client.list_projects(offset: 10, limit: 20)
113
+ projects = crowdin.list_projects(offset: 10, limit: 20)
114
+
115
+ # Get specified project
116
+ project = crowdin.get_project(your_project_id)
113
117
 
114
118
  # Add Storage
115
- adding_storage_response = crowdin.add_storage(File.open('YourFilename.extension'))
119
+ storage = crowdin.add_storage(File.open('YourFilename.extension', 'r'))
116
120
  # or you can specify only filename
117
- adding_storage_response = crowdin.add_storage('YourFilename.extension')
121
+ storage = crowdin.add_storage('YourFilename.extension')
118
122
 
119
123
  # Download file
120
124
  filename = crowdin.download_file(your_destination, your_file_id, your_project_id)
@@ -122,8 +126,10 @@ filename = crowdin.download_file(your_destination, your_file_id, your_project_id
122
126
  # project_id is optional, as it can be initialized with a Crowdin Client
123
127
 
124
128
  # File revisions
125
- file_revisions = crowdin.list_file_revisions(your_file_id, { limit: 10, project_id: your_project_id })
126
- # project_id is optional, as it can be initialized with a Crowdin Client
129
+ # with initialized project_id in your Client
130
+ file_revisions = crowdin.list_file_revisions(your_file_id, limit: 10)
131
+ # or you can specify your project_id
132
+ file_revisions = crowdin.list_file_revisions(your_file_id, { limit: 10 }, your_project_id)
127
133
  ```
128
134
 
129
135
  ### Command-Line Client
@@ -131,14 +137,15 @@ file_revisions = crowdin.list_file_revisions(your_file_id, { limit: 10, project_
131
137
  The Crowdin Ruby client support crowdin-console, where you can test endpoints easier
132
138
 
133
139
  ```console
134
- bundle exec crowdin-console --enable-logger --api-token API_TOKEN --project-id PROJECT_ID
140
+ $ bundle exec crowdin-console --enable-logger --api-token API_TOKEN --project-id PROJECT_ID
135
141
  ```
136
142
 
137
143
  Or Crowdin Enterprise
138
144
 
139
145
  ```console
140
- bundle exec crowdin-console --enable-logger --enterprise --api-token API_TOKEN --organization-domain YOUR_DOMAIN
146
+ $ bundle exec crowdin-console --enable-logger --enterprise --api-token API_TOKEN --organization-domain YOUR_DOMAIN --project-id PROJECT_ID
141
147
  ```
148
+ Note: you can specify full organization domain by adding .com
142
149
 
143
150
  When execute you'll have IRB console with configured *@crowdin* instance
144
151
 
data/bin/crowdin-console CHANGED
@@ -1,20 +1,23 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'bundler/setup'
4
3
  require 'crowdin-api'
5
4
  require 'optparse'
6
5
 
7
- # You can specify your arguments when execute this script
8
6
  #
9
- # Type bundle exec crowdin-console --help for more available arguments
7
+ # You can specify your options while executing this script
8
+ #
9
+ # Type bundle exec crowdin-console --help for more available options
10
10
  #
11
11
  # Example:
12
12
  #
13
13
  # bundle exec crowdin-console --enable-logger --api-token YOUR_API_TOKEN --project-id YOUR_PROJECT_ID
14
14
  #
15
- # or Enterpise API
15
+ # or Enterpise API:
16
16
  #
17
17
  # bundle exec crowdin-console --enterprise --api-token YOUR_ENTERPRISE_API_TOKEN --organization-domain YOUR_DOMAIN
18
+ #
19
+
20
+ include Crowdin::Errors::ApiErrorsRaiser
18
21
 
19
22
  options = {}
20
23
 
@@ -24,14 +27,14 @@ OptionParser.new do |opts|
24
27
  opts.on('--enterprise', 'Enterprise API') { |v| options[:enterprise] = v }
25
28
  opts.on('--api-token TOKEN', 'API Token') { |v| options[:api_token] = v }
26
29
  opts.on('--organization-domain DOMAIN', 'Organization Domain') { |v| options[:organization_domain] = v }
27
- opts.on('--prohject-id ID', 'Project ID') { |v| options[:project_id] = v }
30
+ opts.on('--project-id ID', 'Project ID') { |v| options[:project_id] = v }
28
31
  opts.on('--enable-logger', 'Enable logger') { |v| options[:enable_logger] = v }
29
32
  end.parse!
30
33
 
31
- options[:api_token] || raise(ArgumentError, '--api-token argument is required')
34
+ options[:api_token] || raise_api_token_is_required_error
32
35
 
33
36
  if options[:enterprise]
34
- options[:organization_domain] || raise(ArgumentError, '--organization-domain option is required for Enterprise mode')
37
+ options[:organization_domain] || raise_organization_domain_is_required_error
35
38
 
36
39
  @crowdin = Crowdin::Client.new do |config|
37
40
  config.api_token = options[:api_token]
data/crowdin-api.gemspec CHANGED
@@ -6,10 +6,10 @@ Gem::Specification.new do |gem|
6
6
  gem.name = 'crowdin-api'
7
7
  gem.version = Crowdin::Client::VERSION
8
8
  gem.authors = ['Crowdin']
9
- gem.email = ['support@crowdin.net']
10
- gem.homepage = 'https://github.com/crowdin/crowdin-api/'
11
- gem.summary = 'Client library to manage translations on Crowdin'
12
- gem.description = 'Ruby Client for the Crowdin API. Documentation - https://support.crowdin.com/api/v2/.'
9
+ gem.email = ['support@crowdin.com']
10
+ gem.homepage = 'https://github.com/crowdin/crowdin-api-client-ruby'
11
+ gem.summary = 'Ruby Client for the Crowdin API'
12
+ gem.description = 'The Crowdin Ruby Client is used to interact with the Crowdin API from Ruby'
13
13
  gem.license = 'MIT'
14
14
 
15
15
  gem.files = `git ls-files`.split("\n")
@@ -18,10 +18,13 @@ Gem::Specification.new do |gem|
18
18
  gem.bindir = 'bin'
19
19
  gem.executables << 'crowdin-console'
20
20
 
21
+ gem.required_ruby_version = '>= 2.4'
22
+
21
23
  gem.add_runtime_dependency 'open-uri', '>= 0.1.0', '< 0.2.0'
22
24
  gem.add_runtime_dependency 'rest-client', '>= 2.0.0', '< 2.1.0'
23
25
 
24
26
  gem.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.32'
27
+ gem.add_development_dependency 'codecov', '~> 0.6.0'
25
28
  gem.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
26
29
  gem.add_development_dependency 'rspec', '~> 3.10'
27
30
  gem.add_development_dependency 'rubocop', '~> 1.23'
@@ -41,7 +41,7 @@ module Crowdin
41
41
  end
42
42
 
43
43
  def get_language(language_id = nil)
44
- language_id || raise(ArgumentError, ':language_id is required')
44
+ language_id || raise_parameter_is_required_error(:language_id)
45
45
 
46
46
  request = Web::Request.new(
47
47
  self,
@@ -53,7 +53,7 @@ module Crowdin
53
53
  end
54
54
 
55
55
  def delete_custom_language(language_id = nil)
56
- language_id || raise(ArgumentError, ':language_id is required')
56
+ language_id || raise_parameter_is_required_error(:language_id)
57
57
 
58
58
  request = Web::Request.new(
59
59
  self,
@@ -65,7 +65,7 @@ module Crowdin
65
65
  end
66
66
 
67
67
  def edit_custom_language(language_id = nil)
68
- language_id || raise(ArgumentError, ':language_id is required')
68
+ language_id || raise_parameter_is_required_error(:language_id)
69
69
 
70
70
  request = Web::Request.new(
71
71
  self,
@@ -26,7 +26,7 @@ module Crowdin
26
26
  end
27
27
 
28
28
  def get_project(project_id = nil)
29
- project_id || raise(ArgumentError, ':project_id is required')
29
+ project_id || raise_parameter_is_required_error(:project_id)
30
30
 
31
31
  request = Web::Request.new(
32
32
  self,
@@ -38,7 +38,7 @@ module Crowdin
38
38
  end
39
39
 
40
40
  def delete_project(project_id = nil)
41
- project_id || raise(ArgumentError, ':project_id is required')
41
+ project_id || raise_parameter_is_required_error(:project_id)
42
42
 
43
43
  request = Web::Request.new(
44
44
  self,
@@ -50,7 +50,7 @@ module Crowdin
50
50
  end
51
51
 
52
52
  def edit_project(project_id = nil, query = {})
53
- project_id || raise(ArgumentError, ':project_id is required')
53
+ project_id || raise_parameter_is_required_error(:project_id)
54
54
 
55
55
  request = Web::Request.new(
56
56
  self,
@@ -62,9 +62,11 @@ module Crowdin
62
62
  request.perform
63
63
  end
64
64
 
65
- # For Enterprise API only
65
+ # For Enterprise mode only
66
66
 
67
67
  def list_groups(query = {})
68
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
69
+
68
70
  request = Web::Request.new(
69
71
  self,
70
72
  :get,
@@ -76,6 +78,8 @@ module Crowdin
76
78
  end
77
79
 
78
80
  def add_group(query = {})
81
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
82
+
79
83
  request = Web::Request.new(
80
84
  self,
81
85
  :post,
@@ -87,7 +91,8 @@ module Crowdin
87
91
  end
88
92
 
89
93
  def get_group(group_id = nil)
90
- group_id || raise(ArgumentError, ':group_id is required')
94
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
95
+ group_id || raise_parameter_is_required_error(:group_id)
91
96
 
92
97
  request = Web::Request.new(
93
98
  self,
@@ -99,7 +104,8 @@ module Crowdin
99
104
  end
100
105
 
101
106
  def delete_group(group_id = nil)
102
- group_id || raise(ArgumentError, ':group_id is required')
107
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
108
+ group_id || raise_parameter_is_required_error(:group_id)
103
109
 
104
110
  request = Web::Request.new(
105
111
  self,
@@ -111,7 +117,8 @@ module Crowdin
111
117
  end
112
118
 
113
119
  def edit_group(group_id = nil, query = {})
114
- group_id || raise(ArgumentError, ':group_id is required')
120
+ config.enterprise_mode? || raise_only_for_enterprise_mode_error
121
+ group_id || raise_parameter_is_required_error(:group_id)
115
122
 
116
123
  request = Web::Request.new(
117
124
  self,