crowdin-api 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- 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 +107 -267
- 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 -125
- 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 +125 -22
- data/lib/crowdin-api/errors.rb +0 -23
- data/lib/crowdin-api/methods.rb +0 -427
- data/lib/crowdin-api/version.rb +0 -5
data/README.md
CHANGED
@@ -1,329 +1,169 @@
|
|
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/)
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
Add this line to your application's Gemfile:
|
14
|
-
|
15
|
-
```
|
16
|
-
gem 'crowdin-api'
|
17
|
-
```
|
18
|
-
|
19
|
-
And then execute:
|
20
|
-
```
|
21
|
-
$ bundle
|
22
|
-
```
|
23
|
-
|
24
|
-
Or install it yourself as:
|
25
|
-
```
|
26
|
-
$ gem install crowdin-api
|
27
|
-
```
|
28
|
-
|
29
|
-
## Usage
|
30
|
-
|
31
|
-
Start by creating a connection to Crowdin with your credentials:
|
32
|
-
|
33
|
-
Please note that almost all API calls require the `Project Identifier` and `Project API Key`.
|
34
|
-
|
35
|
-
```ruby
|
36
|
-
require 'crowdin-api'
|
37
|
-
require 'logger'
|
38
|
-
|
39
|
-
crowdin = Crowdin::API.new(api_key: API_KEY, project_id: PROJECT_ID)
|
40
|
-
crowdin.log = Logger.new $stderr
|
41
|
-
```
|
42
|
-
|
43
|
-
As well there are several API methods (`get_projects`, `create_project`) that require `User API Key` instead of regular `Project API Key`.
|
44
|
-
|
45
|
-
```ruby
|
46
|
-
crowdin = Crowdin::API.new(account_key: ACCOUNT_KEY)
|
47
|
-
```
|
13
|
+
### Status
|
48
14
|
|
49
|
-
|
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)
|
50
18
|
|
51
|
-
|
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)
|
52
22
|
|
53
|
-
|
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)
|
54
25
|
|
55
|
-
|
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)
|
56
35
|
|
57
|
-
|
58
|
-
Every file is hash:
|
59
|
-
* `:dest` - file name with path in Crowdin project (required)
|
60
|
-
* `:source` - file that should be added (required)
|
61
|
-
* `:title` - string that defines title for uploaded file (optional)
|
62
|
-
* `:export_pattern` - string that defines name of resulted file (optional)
|
63
|
-
|
64
|
-
Optional params:
|
65
|
-
* `:branch` - a branch name (optional)
|
66
|
-
|
67
|
-
**NOTE!** 20 files max are allowed to upload per one time file transfer.
|
68
|
-
|
69
|
-
```ruby
|
70
|
-
crowdin.add_file(
|
71
|
-
files = [
|
72
|
-
{ dest: '/directory/array.xml', source: 'array.xml', export_pattern: '/values-%two_letters_code%/%original_file_name%' },
|
73
|
-
{ dest: 'strings.xml', source: 'strings.xml', title: 'Texts in Application' }
|
74
|
-
], type: 'android')
|
75
|
-
```
|
76
|
-
|
77
|
-
### Update File
|
78
|
-
|
79
|
-
Upload fresh version of your localization file.
|
80
|
-
|
81
|
-
Documentation <https://crowdin.com/page/api/update-file>
|
82
|
-
|
83
|
-
First parameter is array of files that should be updated in Crowdin project.
|
84
|
-
Every file is hash:
|
85
|
-
* `:dest` - file name with path in Crowdin project (required)
|
86
|
-
* `:source` - uploaded file (required)
|
87
|
-
* `:title` - title for uploaded file (optional)
|
88
|
-
* `:export_pattern` - string that defines name of resulted file (optional)
|
89
|
-
|
90
|
-
Optional params:
|
91
|
-
* `:branch` - a branch name (optional)
|
92
|
-
|
93
|
-
**NOTE!** 20 files max are allowed to upload per one time file transfer.
|
36
|
+
## Installation
|
94
37
|
|
95
|
-
|
96
|
-
crowdin.update_file(
|
97
|
-
files = [
|
98
|
-
{ :dest => '/directory/array.xml', :source => 'array.xml', :export_pattern => '/values-%two_letters_code%/%original_file_name%'},
|
99
|
-
{ :dest => 'strings.xml', :source => 'strings.xml' }
|
100
|
-
])
|
38
|
+
Add this line to your application's Gemfile:
|
101
39
|
|
40
|
+
```gemfile
|
41
|
+
gem 'crowdin-api', '~> 1.0.0'
|
102
42
|
```
|
103
43
|
|
104
|
-
|
105
|
-
|
106
|
-
Remove file from Crowdin project.
|
107
|
-
|
108
|
-
Documentation <https://crowdin.com/page/api/delete-file>
|
44
|
+
And then execute:
|
109
45
|
|
110
|
-
```
|
111
|
-
|
46
|
+
```console
|
47
|
+
bundle install
|
112
48
|
```
|
113
49
|
|
114
|
-
|
115
|
-
|
116
|
-
Create a new directory in Crowdin project.
|
117
|
-
|
118
|
-
First parameter `name` - full directory path that should be created (e.g. /MainPage/AboutUs) (required)
|
119
|
-
|
120
|
-
Optional params:
|
121
|
-
* `:is_branch` - create new branch. Valid values - `'0'`, `'1'`. Only when create root directory.
|
122
|
-
* `:branch` - a branch name.
|
123
|
-
|
124
|
-
Documentation: <https://crowdin.com/page/api/add-directory>
|
50
|
+
Or install it yourself as:
|
125
51
|
|
126
|
-
```
|
127
|
-
crowdin
|
52
|
+
```console
|
53
|
+
gem install crowdin-api
|
128
54
|
```
|
129
55
|
|
130
|
-
|
131
|
-
|
132
|
-
```ruby
|
133
|
-
crowdin.add_directory('master', is_branch: '1')
|
134
|
-
```
|
56
|
+
---
|
135
57
|
|
136
|
-
|
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.
|
137
59
|
|
138
|
-
|
60
|
+
:exclamation: Migration from version *0.6.0* to *1.x.x* requires changes in your code.
|
139
61
|
|
140
|
-
|
141
|
-
* `:branch` - a branch name (optional)
|
62
|
+
---
|
142
63
|
|
143
|
-
|
64
|
+
## Quick start
|
144
65
|
|
66
|
+
### Initialization
|
145
67
|
```ruby
|
146
|
-
crowdin
|
147
|
-
```
|
148
|
-
|
149
|
-
### Change Directory
|
150
|
-
|
151
|
-
Rename or change directory attributes.
|
152
|
-
|
153
|
-
Documentation: <https://crowdin.com/page/api/change-directory>
|
154
|
-
|
155
|
-
First parameter `name` - full directory path that should be modified (e.g. /MainPage/AboutUs) (required)
|
156
|
-
|
157
|
-
Optional params:
|
158
|
-
* `:new_name` - new directory name
|
159
|
-
* `:title` - new directory title to be displayed in Crowdin UI
|
160
|
-
* `:export_pattern` - new direcrory export pattern. Is used to create directory name and path in resulted translations bundle.
|
161
|
-
* `:branch` - a branch name.
|
68
|
+
require 'crowdin-api'
|
162
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
|
163
79
|
|
164
|
-
|
80
|
+
# Also you can specify project_id to handle it in methods
|
165
81
|
|
166
|
-
|
167
|
-
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
|
168
89
|
```
|
169
90
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
Documentation: <https://crowdin.com/page/api/upload-translation>
|
175
|
-
|
176
|
-
First parameter is array of translated files that should be added to Crowdin project.
|
177
|
-
Every file is hash:
|
178
|
-
* `:dest` - file names in Crowdin (required)
|
179
|
-
* `:source` - uploaded translation (required)
|
180
|
-
|
181
|
-
Second parameter is target language.
|
182
|
-
With a single call it's possible to upload translations for several files but only into one of the languages.
|
183
|
-
Check [complete list of Crowdin language codes](https://crowdin.com/page/api/language-codes) that can be used.
|
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*.
|
184
94
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
* `:auto_approve_imported` - mark uploaded translations as approved (default: false)
|
189
|
-
* `: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*.
|
190
98
|
|
191
|
-
|
99
|
+
### How to call methods
|
192
100
|
|
193
101
|
```ruby
|
194
|
-
|
195
|
-
|
196
|
-
{ :dest => 'strings.xml', :source => 'strings_uk.xml' },
|
197
|
-
{ :dest => 'array.xml', :source => 'array_uk.xml' }
|
198
|
-
],
|
199
|
-
language = 'uk',
|
200
|
-
params = {:import_duplicates => true}
|
201
|
-
)
|
202
|
-
```
|
203
|
-
|
204
|
-
### Download Translations
|
102
|
+
# Create Project
|
103
|
+
project = crowdin.add_project(name: your_project_name, sourceLanguageId: your_language_id)
|
205
104
|
|
206
|
-
|
105
|
+
# Get list of Projects
|
106
|
+
projects = client.list_projects
|
207
107
|
|
208
|
-
|
108
|
+
# Get specified project
|
109
|
+
project = client.get_project(your_project_id)
|
209
110
|
|
210
|
-
|
111
|
+
# Get list of Projects with offset and limit
|
112
|
+
projects = client.list_projects(offset: 10, limit: 20)
|
211
113
|
|
212
|
-
|
213
|
-
|
214
|
-
|
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')
|
215
118
|
|
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
|
216
123
|
|
217
|
-
|
218
|
-
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
|
219
127
|
```
|
220
128
|
|
221
|
-
###
|
222
|
-
|
223
|
-
Track overall translation and proofreading progress of each target language.
|
129
|
+
### Command-Line Client
|
224
130
|
|
225
|
-
|
131
|
+
The Crowdin Ruby client support crowdin-console, where you can test endpoints easier
|
226
132
|
|
227
|
-
```
|
228
|
-
crowdin
|
133
|
+
```console
|
134
|
+
bundle exec crowdin-console --enable-logger --api-token API_TOKEN --project-id PROJECT_ID
|
229
135
|
```
|
230
136
|
|
231
|
-
|
232
|
-
|
233
|
-
Shows project details and meta information (last translations date, currently uploaded files, target languages etc..).
|
234
|
-
|
235
|
-
Documentation: <https://crowdin.com/page/api/info>
|
137
|
+
Or Crowdin Enterprise
|
236
138
|
|
237
|
-
```
|
238
|
-
crowdin
|
139
|
+
```console
|
140
|
+
bundle exec crowdin-console --enable-logger --enterprise --api-token API_TOKEN --organization-domain YOUR_DOMAIN
|
239
141
|
```
|
240
142
|
|
241
|
-
|
242
|
-
|
243
|
-
Build ZIP archive with the latest translations.
|
244
|
-
|
245
|
-
**Note!** This method can be invoked only once per 30 minutes (there is no such restriction for organization plans).
|
246
|
-
|
247
|
-
Also API call will be ignored if there were no changes in the project since previous export.
|
248
|
-
You can see whether ZIP archive with latest translations was actually build by status attribute (`built` or `skipped`) returned in response.
|
249
|
-
|
250
|
-
Optional params:
|
251
|
-
* `:branch` - a branch name (default: nil)
|
252
|
-
|
253
|
-
Documentation: <https://crowdin.com/page/api/export>
|
143
|
+
When execute you'll have IRB console with configured *@crowdin* instance
|
254
144
|
|
255
|
-
```ruby
|
256
|
-
crowdin.export_translations
|
257
145
|
```
|
258
|
-
|
259
|
-
### Account Projects
|
260
|
-
|
261
|
-
Get Crowdin Project details.
|
262
|
-
|
263
|
-
**Important:** This API method requires `Account API Key`. This key can not be found on your profile pages.
|
264
|
-
|
265
|
-
Documentation: <https://crowdin.com/page/api/get-projects>
|
266
|
-
|
267
|
-
```ruby
|
268
|
-
crowdin = Crowdin::API.new(account_key: ACCOUNT_KEY)
|
269
|
-
crowdin.get_projects(login = 'YourCrowdinAccount')
|
146
|
+
> @crowdin.list_projects
|
270
147
|
```
|
271
148
|
|
272
|
-
|
273
|
-
|
274
|
-
Create Crowdin project.
|
275
|
-
|
276
|
-
**Important:** This API method requires `Account API Key`. This key can not be found on your profile pages.
|
277
|
-
|
278
|
-
Documentation: <https://crowdin.com/page/api/create-project>
|
279
|
-
|
280
|
-
### Edit Project
|
281
|
-
|
282
|
-
Documentation: <https://crowdin.com/page/api/edit-project>
|
283
|
-
|
284
|
-
### Delete Project
|
149
|
+
## Seeking Assistance
|
285
150
|
|
286
|
-
|
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.
|
287
152
|
|
288
|
-
|
289
|
-
|
290
|
-
Documentation: <https://crowdin.com/page/api/download-glossary>
|
291
|
-
|
292
|
-
### Upload Glossary
|
293
|
-
|
294
|
-
Documentation: <https://crowdin.com/page/api/upload-glossary>
|
295
|
-
|
296
|
-
### Download TM
|
297
|
-
|
298
|
-
Documentation: <https://crowdin.com/page/api/download-tm>
|
299
|
-
|
300
|
-
### Upload TM
|
301
|
-
|
302
|
-
Documentation: <https://crowdin.com/page/api/upload-tm>
|
303
|
-
|
304
|
-
### Supported Languages
|
305
|
-
|
306
|
-
Documentation: <https://crowdin.com/page/api/supported-languages>
|
307
|
-
|
308
|
-
## Supported Rubies
|
309
|
-
|
310
|
-
Tested with the following Ruby versions:
|
311
|
-
|
312
|
-
- MRI 2.2.1
|
313
|
-
- 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.
|
314
154
|
|
315
155
|
## Contributing
|
316
156
|
|
317
|
-
|
318
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
319
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
320
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
321
|
-
5. Create new Pull Request
|
322
|
-
|
323
|
-
## License and Author
|
157
|
+
If you want to contribute please read the [Contributing](/CONTRIBUTING.md) guidelines.
|
324
158
|
|
325
|
-
|
159
|
+
## License
|
326
160
|
|
327
|
-
|
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.
|
328
165
|
|
329
|
-
|
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
|