crowdin-api 0.6.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build-and-publish.yml +30 -0
  3. data/.github/workflows/test-and-lint.yml +31 -0
  4. data/.gitignore +12 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +5 -0
  7. data/.rubocop_todo.yml +146 -0
  8. data/CODE_OF_CONDUCT.md +128 -0
  9. data/CONTRIBUTING.md +71 -0
  10. data/Gemfile +5 -0
  11. data/LICENSE +1 -1
  12. data/README.md +120 -280
  13. data/Rakefile +19 -0
  14. data/bin/crowdin-console +54 -0
  15. data/bin/setup +6 -0
  16. data/crowdin-api.gemspec +33 -0
  17. data/lib/crowdin-api/api-resources/dictionaries.rb +34 -0
  18. data/lib/crowdin-api/api-resources/distributions.rb +99 -0
  19. data/lib/crowdin-api/api-resources/glossaries.rb +217 -0
  20. data/lib/crowdin-api/api-resources/labels.rb +117 -0
  21. data/lib/crowdin-api/api-resources/languages.rb +82 -0
  22. data/lib/crowdin-api/api-resources/machine_translation_engines.rb +74 -0
  23. data/lib/crowdin-api/api-resources/projects.rb +148 -0
  24. data/lib/crowdin-api/api-resources/reports.rb +138 -0
  25. data/lib/crowdin-api/api-resources/screenshots.rb +186 -0
  26. data/lib/crowdin-api/api-resources/source_files.rb +304 -0
  27. data/lib/crowdin-api/api-resources/source_strings.rb +74 -0
  28. data/lib/crowdin-api/api-resources/storages.rb +106 -0
  29. data/lib/crowdin-api/api-resources/string_comments.rb +73 -0
  30. data/lib/crowdin-api/api-resources/string_translations.rb +220 -0
  31. data/lib/crowdin-api/api-resources/tasks.rb +113 -0
  32. data/lib/crowdin-api/api-resources/teams.rb +144 -0
  33. data/lib/crowdin-api/api-resources/translation_memory.rb +145 -0
  34. data/lib/crowdin-api/api-resources/translation_status.rb +89 -0
  35. data/lib/crowdin-api/api-resources/translations.rb +161 -0
  36. data/lib/crowdin-api/api-resources/users.rb +129 -0
  37. data/lib/crowdin-api/api-resources/vendors.rb +21 -0
  38. data/lib/crowdin-api/api-resources/webhooks.rb +73 -0
  39. data/lib/crowdin-api/api-resources/workflows.rb +62 -0
  40. data/lib/crowdin-api/client/client.rb +95 -0
  41. data/lib/crowdin-api/client/configuration.rb +48 -0
  42. data/lib/crowdin-api/client/version.rb +7 -0
  43. data/lib/crowdin-api/core/errors.rb +8 -0
  44. data/lib/crowdin-api/core/errors_raisers.rb +39 -0
  45. data/lib/crowdin-api/core/request.rb +118 -0
  46. data/lib/crowdin-api/core/utils.rb +10 -0
  47. data/lib/crowdin-api.rb +39 -126
  48. data/spec/client/client-instance_spec.rb +14 -0
  49. data/spec/client/configuration-instance_spec.rb +72 -0
  50. data/spec/spec_helper.rb +9 -0
  51. metadata +130 -47
  52. data/lib/crowdin-api/errors.rb +0 -23
  53. data/lib/crowdin-api/methods.rb +0 -452
  54. data/lib/crowdin-api/version.rb +0 -5
data/README.md CHANGED
@@ -1,25 +1,52 @@
1
- # Crowdin::API
1
+ [<p align='center'><img src='https://support.crowdin.com/assets/logos/crowdin-dark-symbol.png' data-canonical-src='https://support.crowdin.com/assets/logos/crowdin-dark-symbol.png' width='200' height='200' align='center'/></p>](https://crowdin.com)
2
2
 
3
- A Ruby interface to the Crowdin API.
3
+ # Crowdin Ruby client
4
4
 
5
- For more about the Crowdin API see <https://support.crowdin.com/api/api-integration-setup/>.
5
+ The Crowdin Ruby client is a lightweight interface to the Crowdin API v2. It provides common services for making API requests.
6
6
 
7
- To experiment with that code, run `bin/console` for an interactive prompt.
7
+ Crowdin API is a full-featured RESTful API that helps you to integrate localization into your development process. The endpoints that we use allow you to easily make calls to retrieve information and to execute actions needed.
8
8
 
9
- > **WARNING**: This is a development version: It contains the latest changes, but may also have severe known issues, including crashes and data loss situations. In fact, it may not work at all.
9
+ For more about Crowdin API v2 see the documentation:
10
+ - [Crowdin](https://support.crowdin.com/api/v2/)
11
+ - [Crowdin Enterprise](https://support.crowdin.com/enterprise/api/)
12
+
13
+ ## Status
14
+
15
+ [![Gem](https://img.shields.io/gem/v/crowdin-api?logo=ruby&cacheSeconds=1800)](https://rubygems.org/gems/crowdin-api)
16
+ [![Gem](https://img.shields.io/gem/dt/crowdin-api?cacheSeconds=1800)](https://rubygems.org/gems/crowdin-api)
17
+ [![Gem](https://img.shields.io/gem/dtv/crowdin-api?cacheSeconds=1800)](https://rubygems.org/gems/crowdin-api)
18
+
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
+ [![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)
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)
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)
23
+
24
+ ## Table of Contents
25
+ * [Requirements](#requirements)
26
+ * [Installation](#installation)
27
+ * [Quick Start](#quick-start)
28
+ * [Initialization](#initialization)
29
+ * [Usage](#usage)
30
+ * [Command-Line Client](#command-line-client)
31
+ * [Seeking Assistance](#seeking-assistance)
32
+ * [Contributing](#contributing)
33
+ * [License](#license)
34
+
35
+ ## Requirements
36
+ * Ruby >= 2.4
10
37
 
11
38
  ## Installation
12
39
 
13
40
  Add this line to your application's Gemfile:
14
41
 
15
42
  ```gemfile
16
- gem 'crowdin-api'
43
+ gem 'crowdin-api', '~> 1.2.0'
17
44
  ```
18
45
 
19
46
  And then execute:
20
47
 
21
48
  ```console
22
- bundle
49
+ bundle install
23
50
  ```
24
51
 
25
52
  Or install it yourself as:
@@ -28,320 +55,133 @@ Or install it yourself as:
28
55
  gem install crowdin-api
29
56
  ```
30
57
 
31
- ## Usage
32
-
33
- Start by creating a connection to Crowdin with your credentials:
34
-
35
- Please note that almost all API calls require the `Project Identifier` and `Project API Key`.
36
-
37
- ```ruby
38
- require 'crowdin-api'
39
- require 'logger'
40
-
41
- crowdin = Crowdin::API.new(api_key: API_KEY, project_id: PROJECT_ID)
42
- crowdin.log = Logger.new $stderr
43
- ```
44
-
45
- As well there are several API methods (`get_projects`, `create_project`) that require `User API Key` instead of regular `Project API Key`.
46
-
47
- ```ruby
48
- crowdin = Crowdin::API.new(account_key: ACCOUNT_KEY)
49
- ```
50
-
51
- Now you can make requests to the api.
52
-
53
- ### Add File
54
-
55
- Add new file to Crowdin project.
56
-
57
- Documentation: <https://support.crowdin.com/api/add-file/>.
58
-
59
- First parameter is array of files that should be added to Crowdin project.
60
- Every file is hash:
61
-
62
- * `:dest` - file name with path in Crowdin project (required)
63
- * `:source` - file that should be added (required)
64
- * `:title` - string that defines title for uploaded file (optional)
65
- * `:export_pattern` - string that defines name of resulted file (optional)
66
-
67
- Optional params:
68
-
69
- * `:branch` - a branch name (optional)
70
-
71
- **NOTE!** 20 files max are allowed to upload per one time file transfer.
72
-
73
- ```ruby
74
- crowdin.add_file(
75
- files = [
76
- { dest: '/directory/array.xml', source: 'array.xml', export_pattern: '/values-%two_letters_code%/%original_file_name%' },
77
- { dest: 'strings.xml', source: 'strings.xml', title: 'Texts in Application' }
78
- ], type: 'android')
79
- ```
80
-
81
- ### Update File
82
-
83
- Upload fresh version of your localization file.
84
-
85
- Documentation <https://support.crowdin.com/api/update-file/>
86
-
87
- First parameter is array of files that should be updated in Crowdin project.
88
- Every file is hash:
89
-
90
- * `:dest` - file name with path in Crowdin project (required)
91
- * `:source` - uploaded file (required)
92
- * `:title` - title for uploaded file (optional)
93
- * `:export_pattern` - string that defines name of resulted file (optional)
94
-
95
- Optional params:
96
-
97
- * `:branch` - a branch name (optional)
98
-
99
- **NOTE!** 20 files max are allowed to upload per one time file transfer.
100
-
101
- ```ruby
102
- crowdin.update_file(
103
- files = [
104
- { :dest => '/directory/array.xml', :source => 'array.xml', :export_pattern => '/values-%two_letters_code%/%original_file_name%'},
105
- { :dest => 'strings.xml', :source => 'strings.xml' }
106
- ])
107
-
108
- ```
109
-
110
- ### Delete File
111
-
112
- Remove file from Crowdin project.
113
-
114
- Documentation <https://support.crowdin.com/api/delete-file/>
115
-
116
- ```ruby
117
- crowdin.delete_file('strings.xml')
118
- ```
119
-
120
- ### Create Directory
121
-
122
- Create a new directory in Crowdin project.
123
-
124
- First parameter `name` - full directory path that should be created (e.g. /MainPage/AboutUs) (required)
125
-
126
- Optional params:
127
-
128
- * `:is_branch` - create new branch. Valid values - `'0'`, `'1'`. Only when create root directory.
129
- * `:branch` - a branch name.
130
-
131
- Documentation: <https://support.crowdin.com/api/add-directory/>
132
-
133
- ```ruby
134
- crowdin.add_directory('dirname')
135
- ```
136
-
137
- Create a new branch:
138
-
139
- ```ruby
140
- crowdin.add_directory('master', is_branch: '1')
141
- ```
142
-
143
- ### Delete Directory
58
+ ---
144
59
 
145
- Remove directory with nested files from Crowdin project.
60
+ :bookmark_tabs: For versions *0.6.0* and lower see the [branch api/v1](https://github.com/crowdin/crowdin-api-client-ruby/tree/api/v1). Please note that these versions are no longer supported.
146
61
 
147
- Optional params:
62
+ :exclamation: Migration from version *0.6.0* to *1.x.x* requires changes in your code.
148
63
 
149
- * `:branch` - a branch name (optional)
64
+ ---
150
65
 
151
- Documentation: <https://support.crowdin.com/api/delete-directory/>
66
+ ## Quick start
152
67
 
68
+ ### Initialization
153
69
  ```ruby
154
- crowdin.delete_directory('dirname')
155
- ```
156
-
157
- ### Change Directory
158
-
159
- Rename or change directory attributes.
160
-
161
- Documentation: <https://support.crowdin.com/api/change-directory/>
162
-
163
- First parameter `name` - full directory path that should be modified (e.g. /MainPage/AboutUs) (required)
164
-
165
- Optional params:
70
+ require 'crowdin-api'
166
71
 
167
- * `:new_name` - new directory name
168
- * `:title` - new directory title to be displayed in Crowdin UI
169
- * `:export_pattern` - new direcrory export pattern. Is used to create directory name and path in resulted translations bundle.
170
- * `:branch` - a branch name.
72
+ # Initialize a new Client instance with config options
73
+ crowdin = Crowdin::Client.new do |config|
74
+ config.api_token = 'YourApiToken'
75
+ end
171
76
 
77
+ # Or you can intialize Enterprise Client instance by specifying your
78
+ # organization_domain in config options
79
+ crowdin = Crowdin::Client.new do |config|
80
+ config.api_token = 'YourEnterpriseApiToken'
81
+ config.organization_domain = 'YourOrganizationDomain'
82
+ end
83
+ # Note: we use full specified organization domain if that includes '.com'
84
+ # config.organization_domain = your_domain -> https://your_domain.api.crowdin.com
85
+ # config.organization_domain = your_domain.com -> your_domain.com
172
86
 
173
- When renaming directory the path can not be changed (it means `new_name` parameter can not contain path, name only).
87
+ # All supported Crowdin Client config options now:
88
+ crowdin = Crowdin::Client.new do |config|
89
+ config.api_token = 'YourApiToken' # [String] required
90
+ config.organization_domain = 'YourOrganizationDomain' # [String] optional
91
+ config.project_id = 'YourProjectId' # [Integer] nil by default
92
+ config.enable_logger = true # [Boolean] false by default
93
+ end
94
+ # Note: Client will initialize default Logger instance if you have specify
95
+ # enable_logger to true, you can change it by crowdin.logger = YourLogger
174
96
 
175
- ```ruby
176
- crowdin.change_directory('/MainPage/AboutUs', new_name: 'AboutCompany')
97
+ # Also you can specify proxy by adding it to ENV['http_proxy'] before Client initialization
177
98
  ```
178
99
 
179
- ### Upload Translations
180
-
181
- Upload existing translations to your Crowdin project.
182
-
183
- Documentation: <https://support.crowdin.com/api/upload-translation/>
184
-
185
- First parameter is array of translated files that should be added to Crowdin project.
186
- Every file is hash:
187
-
188
- * `:dest` - file names in Crowdin (required)
189
- * `:source` - uploaded translation (required)
190
-
191
- Second parameter is target language.
192
- With a single call it's possible to upload translations for several files but only into one of the languages.
193
- Check [complete list of Crowdin language codes](https://support.crowdin.com/api/language-codes/) that can be used.
194
-
195
- Optional params:
100
+ To generate a new token in Crowdin, follow these steps:
101
+ - Go to *Account Settings* > *API* tab, *Personal Access Tokens* section, and click *New Token*.
102
+ - Specify *Token Name* and click *Create*.
196
103
 
197
- * `:import_duplicates` - defines whether to add translation if there is the same translation previously added (default: false)
198
- * `:import_eq_suggestions` - defines whether to add translation if it is equal to source string at Crowdin (default: false)
199
- * `:auto_approve_imported` - mark uploaded translations as approved (default: false)
200
- * `:branch` - a branch name (default: nil)
104
+ To generate a new token in Crowdin Enterprise, follow these steps:
105
+ - Go to *Account Settings* > *Access tokens* tab and click *New token*.
106
+ - Specify *Token Name*, select *Scopes* and *Projects*, click *Create*.
201
107
 
202
- **NOTE!** 20 files max are allowed to upload per one time file transfer.
108
+ ### Usage
203
109
 
204
110
  ```ruby
205
- crowdin.upload_translation(
206
- files = [
207
- { :dest => 'strings.xml', :source => 'strings_uk.xml' },
208
- { :dest => 'array.xml', :source => 'array_uk.xml' }
209
- ],
210
- language = 'uk',
211
- params = {:import_duplicates => true}
212
- )
213
- ```
111
+ # Create Project
112
+ project = crowdin.add_project(name: your_project_name, sourceLanguageId: your_language_id)
214
113
 
215
- ### Download Translations
114
+ # Get list of Projects
115
+ projects = crowdin.list_projects
216
116
 
217
- Download last exported translation package (one target language or all languages as one zip file).
117
+ # Get list of Projects with offset and limit
118
+ projects = crowdin.list_projects(offset: 10, limit: 20)
218
119
 
219
- Documentation: <https://support.crowdin.com/api/download/>
120
+ # Get specified project
121
+ project = crowdin.get_project(your_project_id)
220
122
 
221
- First parameter is the language of translation you need or download `all` of them at once.
123
+ # Edit project
124
+ project = crowdin.edit_project(project_id, [{op: 'replace',
125
+ path: '/name',
126
+ value: 'your_new_project_name'}])
222
127
 
223
- Optional params:
128
+ # Add Storage
129
+ storage = crowdin.add_storage(File.open('YourFilename.extension', 'r'))
130
+ # or you can specify only absolute path to file
131
+ storage = crowdin.add_storage('YourFilename.extension')
224
132
 
225
- * `:output` - a name of ZIP file with translations
226
- * `:branch` - a branch name (default: nil)
133
+ # Download file
134
+ file = crowdin.download_file(your_file_id, your_destination, your_project_id)
135
+ # your_destination - filename or absolute path to file, optional
136
+ # Without destination option file will be saved to the current directory with a default filename
137
+ # project_id is optional, as it can be initialized with a Crowdin Client
227
138
 
228
- ```ruby
229
- crowdin.download_translation('ru', :output => '/path/to/download/ru_RU.zip')
139
+ # File revisions
140
+ # with initialized project_id in your Client
141
+ file_revisions = crowdin.list_file_revisions(your_file_id, limit: 10)
142
+ # or you can specify your project_id
143
+ file_revisions = crowdin.list_file_revisions(your_file_id, { limit: 10 }, your_project_id)
230
144
  ```
231
145
 
232
- ### Translation Status
146
+ ### Command-Line Client
233
147
 
234
- Track overall translation and proofreading progress of each target language.
148
+ The Crowdin Ruby client support crowdin-console, where you can test endpoints easier
235
149
 
236
- Documentation: <https://support.crowdin.com/api/status/>
237
-
238
- ```ruby
239
- crowdin.translations_status
150
+ ```console
151
+ $ bundle exec crowdin-console --enable-logger --api-token API_TOKEN --project-id PROJECT_ID
240
152
  ```
241
153
 
242
- ### Project Info
243
-
244
- Shows project details and meta information (last translations date, currently uploaded files, target languages etc..).
154
+ Or Crowdin Enterprise
245
155
 
246
- Documentation: <https://support.crowdin.com/api/info/>
247
-
248
- ```ruby
249
- crowdin.project_info
156
+ ```console
157
+ $ bundle exec crowdin-console --enable-logger --enterprise --api-token API_TOKEN --organization-domain DOMAIN --project-id PROJECT_ID
250
158
  ```
159
+ Note: you can specify full organization domain by adding '.com'
251
160
 
252
- ### Export File
253
-
254
- Export a single translated file from Crowdin.
255
-
256
- Documentation: <https://support.crowdin.com/api/export-file/>
257
-
258
- ### Export Translations
259
-
260
- Build ZIP archive with the latest translations.
261
-
262
- **Note!** This method can be invoked only once per 30 minutes (there is no such restriction for organization plans).
263
-
264
- Also API call will be ignored if there were no changes in the project since previous export.
265
- You can see whether ZIP archive with latest translations was actually build by status attribute (`built` or `skipped`) returned in response.
161
+ When execute you'll have IRB console with configured *@crowdin* instance
266
162
 
267
- Optional params:
268
-
269
- * `:branch` - a branch name (default: nil)
270
-
271
- Documentation: <https://support.crowdin.com/api/export/>
272
-
273
- ```ruby
274
- crowdin.export_translations
275
163
  ```
276
-
277
- ### Account Projects
278
-
279
- Get Crowdin Project details.
280
-
281
- **Important:** This API method requires `Account API Key`. This key can not be found on your profile pages.
282
-
283
- Documentation: <https://support.crowdin.com/api/get-projects/>
284
-
285
- ```ruby
286
- crowdin = Crowdin::API.new(account_key: ACCOUNT_KEY)
287
- crowdin.get_projects(login = 'YourCrowdinAccount')
164
+ > @crowdin.list_projects
288
165
  ```
289
166
 
290
- ### Create Project
291
-
292
- Create Crowdin project.
293
-
294
- **Important:** This API method requires `Account API Key`. This key can not be found on your profile pages.
295
-
296
- Documentation: <https://support.crowdin.com/api/create-project/>
297
-
298
- ### Edit Project
299
-
300
- Documentation: <https://support.crowdin.com/api/edit-project/>
167
+ ## Seeking Assistance
301
168
 
302
- ### Delete Project
169
+ If you find any problems or would like to suggest a feature, please read the [How can I contribute](/CONTRIBUTING.md#how-can-i-contribute) section in our contributing guidelines.
303
170
 
304
- Documentation: <https://support.crowdin.com/api/delete-project/>
305
-
306
- ### Download Glossary
307
-
308
- Documentation: <https://support.crowdin.com/api/download-glossary/>
309
-
310
- ### Upload Glossary
311
-
312
- Documentation: <https://support.crowdin.com/api/upload-glossary/>
313
-
314
- ### Download TM
315
-
316
- Documentation: <https://support.crowdin.com/api/download-tm/>
317
-
318
- ### Upload TM
319
-
320
- Documentation: <https://support.crowdin.com/api/upload-tm/>
321
-
322
- ### Supported Languages
323
-
324
- Documentation: <https://support.crowdin.com/api/supported-languages/>
325
-
326
- ## Supported Rubies
327
-
328
- Tested with the following Ruby versions:
329
-
330
- * MRI 2.2.1
331
- * JRuby 9.0.0.0
171
+ Need help working with Crowdin Ruby client or have any questions? [Contact](https://crowdin.com/contacts) Customer Success Service.
332
172
 
333
173
  ## Contributing
334
174
 
335
- 1. Fork it
336
- 2. Create your feature branch (`git checkout -b my-new-feature`)
337
- 3. Commit your changes (`git commit -am 'Added some feature'`)
338
- 4. Push to the branch (`git push origin my-new-feature`)
339
- 5. Create new Pull Request
340
-
341
- ## License and Author
175
+ If you want to contribute please read the [Contributing](/CONTRIBUTING.md) guidelines.
342
176
 
343
- Author: Anton Maminov (anton.maminov@gmail.com)
177
+ ## License
344
178
 
345
- Copyright: 2012-2019 [crowdin.com](https://crowdin.com/)
179
+ <pre>
180
+ The Crowdin Ruby Client is licensed under the MIT License.
181
+ See the LICENSE.md file distributed with this work for additional
182
+ information regarding copyright ownership.
346
183
 
347
- This library is distributed under the MIT license. Please see the LICENSE file.
184
+ Except as contained in the LICENSE file, the name(s) of the above copyright
185
+ holders shall not be used in advertising or otherwise to promote the sale,
186
+ use or other dealings in this Software without prior written authorization.
187
+ </pre>
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core'
5
+
6
+ begin
7
+ require 'rspec/core/rake_task'
8
+ rescue LoadError
9
+ # Ignored
10
+ end
11
+
12
+ if defined?(RSpec)
13
+ desc 'Run specs'
14
+ RSpec::Core::RakeTask.new(:spec) do |spec|
15
+ spec.pattern = FileList['spec/**/*_spec.rb']
16
+ end
17
+
18
+ task default: %i[spec]
19
+ end
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'crowdin-api'
4
+ require 'optparse'
5
+
6
+ #
7
+ # You can specify your options while executing this script
8
+ #
9
+ # Type bundle exec crowdin-console --help for more available options
10
+ #
11
+ # Example:
12
+ #
13
+ # bundle exec crowdin-console --enable-logger --api-token YOUR_API_TOKEN --project-id YOUR_PROJECT_ID
14
+ #
15
+ # or Enterpise API:
16
+ #
17
+ # bundle exec crowdin-console --enterprise --api-token YOUR_ENTERPRISE_API_TOKEN --organization-domain YOUR_DOMAIN
18
+ #
19
+
20
+ include Crowdin::Errors::ClcErrorsRaiser
21
+
22
+ options = {}
23
+
24
+ OptionParser.new do |opts|
25
+ opts.banner = 'Usage: ./bin/crowdin-console --enable-logger --api-token YOUR_API_TOKEN ..'
26
+
27
+ opts.on('--enterprise', 'Enterprise API') { |v| options[:enterprise] = v }
28
+ opts.on('--api-token TOKEN', 'API Token') { |v| options[:api_token] = v }
29
+ opts.on('--organization-domain DOMAIN', 'Organization Domain') { |v| options[:organization_domain] = v }
30
+ opts.on('--project-id ID', 'Project ID') { |v| options[:project_id] = v }
31
+ opts.on('--enable-logger', 'Enable logger') { |v| options[:enable_logger] = v }
32
+ end.parse!
33
+
34
+ options[:api_token] || raise_api_token_is_required_error
35
+
36
+ if options[:enterprise]
37
+ options[:organization_domain] || raise_organization_domain_is_required_error
38
+
39
+ @crowdin = Crowdin::Client.new do |config|
40
+ config.api_token = options[:api_token]
41
+ config.organization_domain = options[:organization_domain]
42
+ config.enable_logger = options[:enable_logger] || false
43
+ config.project_id = options[:project_id] || nil
44
+ end
45
+ else
46
+ @crowdin = Crowdin::Client.new do |config|
47
+ config.api_token = options[:api_token]
48
+ config.enable_logger = options[:enable_logger] || false
49
+ config.project_id = options[:project_id] || nil
50
+ end
51
+ end
52
+
53
+ require 'irb'
54
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/bin/bash
2
+
3
+ set -euo pipefail
4
+ IFS=$'\n\t'
5
+
6
+ bundle install
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('lib/crowdin-api/client/version', __dir__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'crowdin-api'
7
+ gem.version = Crowdin::Client::VERSION
8
+ gem.authors = ['Crowdin']
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
+ gem.license = 'MIT'
14
+
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ gem.require_paths = ['lib']
18
+ gem.bindir = 'bin'
19
+ gem.executables << 'crowdin-console'
20
+
21
+ gem.required_ruby_version = '>= 2.4'
22
+
23
+ gem.add_runtime_dependency 'open-uri', '>= 0.1.0', '< 0.2.0'
24
+ gem.add_runtime_dependency 'rest-client', '>= 2.0.0', '< 2.1.0'
25
+
26
+ gem.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.32'
27
+ gem.add_development_dependency 'codecov', '~> 0.6.0'
28
+ gem.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
29
+ gem.add_development_dependency 'rspec', '~> 3.10'
30
+ gem.add_development_dependency 'rubocop', '~> 1.23'
31
+ gem.add_development_dependency 'sinatra', '~> 2.1'
32
+ gem.add_development_dependency 'webmock', '~> 3.14'
33
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module ApiResources
5
+ module Dictionaries
6
+ def list_dictionaries(query = {}, project_id = config.project_id)
7
+ project_id || raise_project_id_is_required_error
8
+
9
+ request = Web::Request.new(
10
+ self,
11
+ :get,
12
+ "/projects/#{project_id}/dictionaries",
13
+ query
14
+ )
15
+
16
+ request.perform
17
+ end
18
+
19
+ def edit_dictionary(language_id = nil, query = {}, project_id = config.project_id)
20
+ language_id || raise_parameter_is_required_error(:language_id)
21
+ project_id || raise_project_id_is_required_error
22
+
23
+ request = Web::Request.new(
24
+ self,
25
+ :patch,
26
+ "/projects/#{project_id}/dictionaries/#{language_id}",
27
+ query
28
+ )
29
+
30
+ request.perform
31
+ end
32
+ end
33
+ end
34
+ end