crowdin-api 0.6.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build-and-publish.yml +30 -0
- data/.github/workflows/test-and-lint.yml +31 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +118 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +71 -0
- data/Gemfile +5 -0
- data/LICENSE +1 -1
- data/README.md +104 -282
- data/Rakefile +19 -0
- data/bin/crowdin-console +51 -0
- data/bin/setup +6 -0
- data/crowdin-api.gemspec +30 -0
- data/lib/crowdin-api/api-resources/languages.rb +81 -0
- data/lib/crowdin-api/api-resources/projects.rb +127 -0
- data/lib/crowdin-api/api-resources/source_files.rb +313 -0
- data/lib/crowdin-api/api-resources/storages.rb +102 -0
- data/lib/crowdin-api/api-resources/translation_status.rb +97 -0
- data/lib/crowdin-api/api-resources/translations.rb +166 -0
- data/lib/crowdin-api/client/client.rb +82 -0
- data/lib/crowdin-api/client/configuration.rb +41 -0
- data/lib/crowdin-api/client/version.rb +7 -0
- data/lib/crowdin-api/core/errors.rb +20 -0
- data/lib/crowdin-api/core/payload.rb +26 -0
- data/lib/crowdin-api/core/request.rb +91 -0
- data/lib/crowdin-api.rb +22 -126
- data/spec/core/config-instance_spec.rb +35 -0
- data/spec/crowdin-api_spec.rb +7 -0
- data/spec/spec_helper.rb +3 -0
- metadata +94 -44
- data/lib/crowdin-api/errors.rb +0 -23
- data/lib/crowdin-api/methods.rb +0 -452
- data/lib/crowdin-api/version.rb +0 -5
data/README.md
CHANGED
@@ -1,25 +1,50 @@
|
|
1
|
-
|
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
|
-
|
3
|
+
# Crowdin Ruby client
|
4
4
|
|
5
|
-
|
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
|
-
|
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
|
-
|
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
|
+
[![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
|
+
|
23
|
+
[![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)
|
25
|
+
|
26
|
+
## Table of Contents
|
27
|
+
* [Installation](#installation)
|
28
|
+
* [Quick Start](#quick-start)
|
29
|
+
* [Initialization](#initialization)
|
30
|
+
* [How to call methods](#how-to-call-methods)
|
31
|
+
* [Command-Line Client](#command-line-client)
|
32
|
+
* [Seeking Assistance](#seeking-assistance)
|
33
|
+
* [Contributing](#contributing)
|
34
|
+
* [License](#license)
|
10
35
|
|
11
36
|
## Installation
|
12
37
|
|
13
38
|
Add this line to your application's Gemfile:
|
14
39
|
|
15
40
|
```gemfile
|
16
|
-
gem 'crowdin-api'
|
41
|
+
gem 'crowdin-api', '~> 1.0.0'
|
17
42
|
```
|
18
43
|
|
19
44
|
And then execute:
|
20
45
|
|
21
46
|
```console
|
22
|
-
bundle
|
47
|
+
bundle install
|
23
48
|
```
|
24
49
|
|
25
50
|
Or install it yourself as:
|
@@ -28,320 +53,117 @@ Or install it yourself as:
|
|
28
53
|
gem install crowdin-api
|
29
54
|
```
|
30
55
|
|
31
|
-
|
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
|
56
|
+
---
|
144
57
|
|
145
|
-
|
58
|
+
: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
59
|
|
147
|
-
|
60
|
+
:exclamation: Migration from version *0.6.0* to *1.x.x* requires changes in your code.
|
148
61
|
|
149
|
-
|
62
|
+
---
|
150
63
|
|
151
|
-
|
64
|
+
## Quick start
|
152
65
|
|
66
|
+
### Initialization
|
153
67
|
```ruby
|
154
|
-
crowdin
|
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:
|
166
|
-
|
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.
|
68
|
+
require 'crowdin-api'
|
171
69
|
|
70
|
+
# Create a new Crowdin Client object.
|
71
|
+
crowdin = Crowdin::Client.new do |config|
|
72
|
+
config.api_token = 'YourApiToken'
|
73
|
+
end
|
74
|
+
# or you can create Enterprise instance by specify your organization_domain
|
75
|
+
crowdin = Crowdin::Client.new do |config|
|
76
|
+
config.api_token = 'YourEnterpriseApiToken'
|
77
|
+
config.organization_domain = 'YourOrganizationDomain'
|
78
|
+
end
|
172
79
|
|
173
|
-
|
80
|
+
# Also you can specify project_id to handle it in methods
|
174
81
|
|
175
|
-
|
176
|
-
crowdin.
|
82
|
+
# All Crowdin Client config options:
|
83
|
+
crowdin = Crowdin::Client.new do |config|
|
84
|
+
config.api_token = 'YourApiToken' # [String] required
|
85
|
+
config.organization_domain = 'YourOrganizationDomain' # [String] optional
|
86
|
+
config.project_id = 'YourProjectId' # [Integer] nil by default
|
87
|
+
config.enable_logger = true # [Boolean] false by default
|
88
|
+
end
|
177
89
|
```
|
178
90
|
|
179
|
-
|
180
|
-
|
181
|
-
|
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:
|
91
|
+
To generate a new token in Crowdin, follow these steps:
|
92
|
+
- Go to *Account Settings* > *API* tab, *Personal Access Tokens* section, and click *New Token*.
|
93
|
+
- Specify *Token Name* and click *Create*.
|
196
94
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
* `:branch` - a branch name (default: nil)
|
95
|
+
To generate a new token in Crowdin Enterprise, follow these steps:
|
96
|
+
- Go to *Account Settings* > *Access tokens* tab and click *New token*.
|
97
|
+
- Specify *Token Name*, select *Scopes* and *Projects*, click *Create*.
|
201
98
|
|
202
|
-
|
99
|
+
### How to call methods
|
203
100
|
|
204
101
|
```ruby
|
205
|
-
|
206
|
-
|
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
|
-
```
|
214
|
-
|
215
|
-
### Download Translations
|
102
|
+
# Create Project
|
103
|
+
project = crowdin.add_project(name: your_project_name, sourceLanguageId: your_language_id)
|
216
104
|
|
217
|
-
|
105
|
+
# Get list of Projects
|
106
|
+
projects = client.list_projects
|
218
107
|
|
219
|
-
|
108
|
+
# Get specified project
|
109
|
+
project = client.get_project(your_project_id)
|
220
110
|
|
221
|
-
|
111
|
+
# Get list of Projects with offset and limit
|
112
|
+
projects = client.list_projects(offset: 10, limit: 20)
|
222
113
|
|
223
|
-
|
114
|
+
# Add Storage
|
115
|
+
adding_storage_response = crowdin.add_storage(File.open('YourFilename.extension'))
|
116
|
+
# or you can specify only filename
|
117
|
+
adding_storage_response = crowdin.add_storage('YourFilename.extension')
|
224
118
|
|
225
|
-
|
226
|
-
|
119
|
+
# Download file
|
120
|
+
filename = crowdin.download_file(your_destination, your_file_id, your_project_id)
|
121
|
+
# your_destination - filename or full path to file
|
122
|
+
# project_id is optional, as it can be initialized with a Crowdin Client
|
227
123
|
|
228
|
-
|
229
|
-
crowdin.
|
124
|
+
# 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
|
230
127
|
```
|
231
128
|
|
232
|
-
###
|
233
|
-
|
234
|
-
Track overall translation and proofreading progress of each target language.
|
129
|
+
### Command-Line Client
|
235
130
|
|
236
|
-
|
131
|
+
The Crowdin Ruby client support crowdin-console, where you can test endpoints easier
|
237
132
|
|
238
|
-
```
|
239
|
-
crowdin
|
133
|
+
```console
|
134
|
+
bundle exec crowdin-console --enable-logger --api-token API_TOKEN --project-id PROJECT_ID
|
240
135
|
```
|
241
136
|
|
242
|
-
|
243
|
-
|
244
|
-
Shows project details and meta information (last translations date, currently uploaded files, target languages etc..).
|
245
|
-
|
246
|
-
Documentation: <https://support.crowdin.com/api/info/>
|
137
|
+
Or Crowdin Enterprise
|
247
138
|
|
248
|
-
```
|
249
|
-
crowdin
|
139
|
+
```console
|
140
|
+
bundle exec crowdin-console --enable-logger --enterprise --api-token API_TOKEN --organization-domain YOUR_DOMAIN
|
250
141
|
```
|
251
142
|
|
252
|
-
|
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).
|
143
|
+
When execute you'll have IRB console with configured *@crowdin* instance
|
263
144
|
|
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.
|
266
|
-
|
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
145
|
```
|
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')
|
146
|
+
> @crowdin.list_projects
|
288
147
|
```
|
289
148
|
|
290
|
-
|
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
|
149
|
+
## Seeking Assistance
|
299
150
|
|
300
|
-
|
151
|
+
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.
|
301
152
|
|
302
|
-
|
303
|
-
|
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
|
153
|
+
Need help working with Crowdin Ruby client or have any questions? [Contact](https://crowdin.com/contacts) Customer Success Service.
|
332
154
|
|
333
155
|
## Contributing
|
334
156
|
|
335
|
-
|
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
|
157
|
+
If you want to contribute please read the [Contributing](/CONTRIBUTING.md) guidelines.
|
342
158
|
|
343
|
-
|
159
|
+
## License
|
344
160
|
|
345
|
-
|
161
|
+
<pre>
|
162
|
+
The Crowdin Ruby Client is licensed under the MIT License.
|
163
|
+
See the LICENSE.md file distributed with this work for additional
|
164
|
+
information regarding copyright ownership.
|
346
165
|
|
347
|
-
|
166
|
+
Except as contained in the LICENSE file, the name(s) of the above copyright
|
167
|
+
holders shall not be used in advertising or otherwise to promote the sale,
|
168
|
+
use or other dealings in this Software without prior written authorization.
|
169
|
+
</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
|
data/bin/crowdin-console
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'crowdin-api'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
# You can specify your arguments when execute this script
|
8
|
+
#
|
9
|
+
# Type bundle exec crowdin-console --help for more available arguments
|
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
|
+
options = {}
|
20
|
+
|
21
|
+
OptionParser.new do |opts|
|
22
|
+
opts.banner = 'Usage: ./bin/crowdin-console --enable-logger --api-token YOUR_API_TOKEN ..'
|
23
|
+
|
24
|
+
opts.on('--enterprise', 'Enterprise API') { |v| options[:enterprise] = v }
|
25
|
+
opts.on('--api-token TOKEN', 'API Token') { |v| options[:api_token] = v }
|
26
|
+
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 }
|
28
|
+
opts.on('--enable-logger', 'Enable logger') { |v| options[:enable_logger] = v }
|
29
|
+
end.parse!
|
30
|
+
|
31
|
+
options[:api_token] || raise(ArgumentError, '--api-token argument is required')
|
32
|
+
|
33
|
+
if options[:enterprise]
|
34
|
+
options[:organization_domain] || raise(ArgumentError, '--organization-domain option is required for Enterprise mode')
|
35
|
+
|
36
|
+
@crowdin = Crowdin::Client.new do |config|
|
37
|
+
config.api_token = options[:api_token]
|
38
|
+
config.organization_domain = options[:organization_domain]
|
39
|
+
config.enable_logger = options[:enable_logger] || false
|
40
|
+
config.project_id = options[:project_id] || nil
|
41
|
+
end
|
42
|
+
else
|
43
|
+
@crowdin = Crowdin::Client.new do |config|
|
44
|
+
config.api_token = options[:api_token]
|
45
|
+
config.enable_logger = options[:enable_logger] || false
|
46
|
+
config.project_id = options[:project_id] || nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
require 'irb'
|
51
|
+
IRB.start
|
data/bin/setup
ADDED
data/crowdin-api.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
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.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/.'
|
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.add_runtime_dependency 'open-uri', '>= 0.1.0', '< 0.2.0'
|
22
|
+
gem.add_runtime_dependency 'rest-client', '>= 2.0.0', '< 2.1.0'
|
23
|
+
|
24
|
+
gem.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.32'
|
25
|
+
gem.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
|
26
|
+
gem.add_development_dependency 'rspec', '~> 3.10'
|
27
|
+
gem.add_development_dependency 'rubocop', '~> 1.23'
|
28
|
+
gem.add_development_dependency 'sinatra', '~> 2.1'
|
29
|
+
gem.add_development_dependency 'webmock', '~> 3.14'
|
30
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Crowdin
|
4
|
+
module ApiResources
|
5
|
+
module Languages
|
6
|
+
def list_languages(query = {})
|
7
|
+
request = Web::Request.new(
|
8
|
+
self,
|
9
|
+
:get,
|
10
|
+
'/languages',
|
11
|
+
query
|
12
|
+
)
|
13
|
+
|
14
|
+
request.perform
|
15
|
+
end
|
16
|
+
|
17
|
+
# Add custom language.
|
18
|
+
#
|
19
|
+
# === Parameters
|
20
|
+
#
|
21
|
+
# * +:name+ [String] - Language name
|
22
|
+
# * +:code+ [String] - Custom language code
|
23
|
+
# * +:localeCode+ [String] - Custom language locale code
|
24
|
+
# * +:textDirection+ [String ltr/rtl] - Text direction in custom language
|
25
|
+
# * +:pluralCategoryNames+ [String] - Array with category names
|
26
|
+
# * +:threeLettersCode+ [String] - Custom language 3 letters code. Format: ISO 6393 code
|
27
|
+
#
|
28
|
+
# === Example
|
29
|
+
#
|
30
|
+
# crowdin.add_custom_language(name: 'your_name', code: 'your_code' ..)
|
31
|
+
#
|
32
|
+
def add_custom_language(query = {})
|
33
|
+
request = Web::Request.new(
|
34
|
+
self,
|
35
|
+
:post,
|
36
|
+
'/languages',
|
37
|
+
query
|
38
|
+
)
|
39
|
+
|
40
|
+
request.perform
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_language(language_id = nil)
|
44
|
+
language_id || raise(ArgumentError, ':language_id is required')
|
45
|
+
|
46
|
+
request = Web::Request.new(
|
47
|
+
self,
|
48
|
+
:get,
|
49
|
+
"/languages/#{language_id}"
|
50
|
+
)
|
51
|
+
|
52
|
+
request.perform
|
53
|
+
end
|
54
|
+
|
55
|
+
def delete_custom_language(language_id = nil)
|
56
|
+
language_id || raise(ArgumentError, ':language_id is required')
|
57
|
+
|
58
|
+
request = Web::Request.new(
|
59
|
+
self,
|
60
|
+
:delete,
|
61
|
+
"/languages/#{language_id}"
|
62
|
+
)
|
63
|
+
|
64
|
+
request.perform
|
65
|
+
end
|
66
|
+
|
67
|
+
def edit_custom_language(language_id = nil)
|
68
|
+
language_id || raise(ArgumentError, ':language_id is required')
|
69
|
+
|
70
|
+
request = Web::Request.new(
|
71
|
+
self,
|
72
|
+
:patch,
|
73
|
+
"/languages/#{language_id}",
|
74
|
+
query
|
75
|
+
)
|
76
|
+
|
77
|
+
request.perform
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|