crowdin-api 0.5.0 → 1.1.1
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 +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +139 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +71 -0
- data/Gemfile +5 -0
- data/LICENSE +1 -1
- data/README.md +114 -267
- data/Rakefile +19 -0
- data/bin/crowdin-console +54 -0
- data/bin/setup +6 -0
- data/crowdin-api.gemspec +33 -0
- data/lib/crowdin-api/api-resources/languages.rb +81 -0
- data/lib/crowdin-api/api-resources/projects.rb +134 -0
- data/lib/crowdin-api/api-resources/source_files.rb +303 -0
- data/lib/crowdin-api/api-resources/source_strings.rb +74 -0
- data/lib/crowdin-api/api-resources/storages.rb +102 -0
- data/lib/crowdin-api/api-resources/translation_status.rb +89 -0
- data/lib/crowdin-api/api-resources/translations.rb +162 -0
- data/lib/crowdin-api/api-resources/workflows.rb +59 -0
- data/lib/crowdin-api/client/client.rb +82 -0
- data/lib/crowdin-api/client/configuration.rb +44 -0
- data/lib/crowdin-api/client/version.rb +7 -0
- data/lib/crowdin-api/core/api_errors_raiser.rb +29 -0
- data/lib/crowdin-api/core/errors.rb +7 -0
- data/lib/crowdin-api/core/request.rb +118 -0
- data/lib/crowdin-api.rb +23 -126
- data/spec/core/config-instance_spec.rb +72 -0
- data/spec/crowdin-api_spec.rb +7 -0
- data/spec/spec_helper.rb +9 -0
- metadata +112 -40
- 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,176 @@
|
|
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
|
+
[![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)
|
52
23
|
|
53
|
-
|
24
|
+
## Table of Contents
|
25
|
+
* [Installation](#installation)
|
26
|
+
* [Quick Start](#quick-start)
|
27
|
+
* [Initialization](#initialization)
|
28
|
+
* [How to call methods](#how-to-call-methods)
|
29
|
+
* [Command-Line Client](#command-line-client)
|
30
|
+
* [Seeking Assistance](#seeking-assistance)
|
31
|
+
* [Contributing](#contributing)
|
32
|
+
* [License](#license)
|
54
33
|
|
55
|
-
|
56
|
-
|
57
|
-
First parameter is array of files that should be added to Crowdin project.
|
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.
|
34
|
+
## Installation
|
94
35
|
|
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
|
-
])
|
36
|
+
Add this line to your application's Gemfile:
|
101
37
|
|
38
|
+
```gemfile
|
39
|
+
gem 'crowdin-api', '~> 1.1.0'
|
102
40
|
```
|
103
41
|
|
104
|
-
|
105
|
-
|
106
|
-
Remove file from Crowdin project.
|
107
|
-
|
108
|
-
Documentation <https://crowdin.com/page/api/delete-file>
|
42
|
+
And then execute:
|
109
43
|
|
110
|
-
```
|
111
|
-
|
44
|
+
```console
|
45
|
+
bundle install
|
112
46
|
```
|
113
47
|
|
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>
|
48
|
+
Or install it yourself as:
|
125
49
|
|
126
|
-
```
|
127
|
-
crowdin
|
50
|
+
```console
|
51
|
+
gem install crowdin-api
|
128
52
|
```
|
129
53
|
|
130
|
-
|
131
|
-
|
132
|
-
```ruby
|
133
|
-
crowdin.add_directory('master', is_branch: '1')
|
134
|
-
```
|
54
|
+
---
|
135
55
|
|
136
|
-
|
56
|
+
: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
57
|
|
138
|
-
|
58
|
+
:exclamation: Migration from version *0.6.0* to *1.x.x* requires changes in your code.
|
139
59
|
|
140
|
-
|
141
|
-
* `:branch` - a branch name (optional)
|
60
|
+
---
|
142
61
|
|
143
|
-
|
62
|
+
## Quick start
|
144
63
|
|
64
|
+
### Initialization
|
145
65
|
```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)
|
66
|
+
require 'crowdin-api'
|
156
67
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
* `:branch` - a branch name.
|
68
|
+
# Initialize a new Client instance with config options
|
69
|
+
crowdin = Crowdin::Client.new do |config|
|
70
|
+
config.api_token = 'YourApiToken'
|
71
|
+
end
|
162
72
|
|
73
|
+
# Or you can intialize Enterprise Client instance by specifying your organization_domain in config options
|
74
|
+
crowdin = Crowdin::Client.new do |config|
|
75
|
+
config.api_token = 'YourEnterpriseApiToken'
|
76
|
+
config.organization_domain = 'YourOrganizationDomain'
|
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
|
163
81
|
|
164
|
-
|
82
|
+
# All supported Crowdin Client config options now:
|
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
|
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
|
165
91
|
|
166
|
-
|
167
|
-
crowdin.change_directory('/MainPage/AboutUs', new_name: 'AboutCompany')
|
92
|
+
# Also you can specify proxy by adding it to ENV['http_proxy'] before Client initialization
|
168
93
|
```
|
169
94
|
|
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.
|
95
|
+
To generate a new token in Crowdin, follow these steps:
|
96
|
+
- Go to *Account Settings* > *API* tab, *Personal Access Tokens* section, and click *New Token*.
|
97
|
+
- Specify *Token Name* and click *Create*.
|
184
98
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
* `:auto_approve_imported` - mark uploaded translations as approved (default: false)
|
189
|
-
* `:branch` - a branch name (default: nil)
|
99
|
+
To generate a new token in Crowdin Enterprise, follow these steps:
|
100
|
+
- Go to *Account Settings* > *Access tokens* tab and click *New token*.
|
101
|
+
- Specify *Token Name*, select *Scopes* and *Projects*, click *Create*.
|
190
102
|
|
191
|
-
|
103
|
+
### Usage
|
192
104
|
|
193
105
|
```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
|
106
|
+
# Create Project
|
107
|
+
project = crowdin.add_project(name: your_project_name, sourceLanguageId: your_language_id)
|
205
108
|
|
206
|
-
|
109
|
+
# Get list of Projects
|
110
|
+
projects = crowdin.list_projects
|
207
111
|
|
208
|
-
|
112
|
+
# Get list of Projects with offset and limit
|
113
|
+
projects = crowdin.list_projects(offset: 10, limit: 20)
|
209
114
|
|
210
|
-
|
115
|
+
# Get specified project
|
116
|
+
project = crowdin.get_project(your_project_id)
|
211
117
|
|
212
|
-
|
213
|
-
|
214
|
-
|
118
|
+
# Add Storage
|
119
|
+
storage = crowdin.add_storage(File.open('YourFilename.extension', 'r'))
|
120
|
+
# or you can specify only filename
|
121
|
+
storage = crowdin.add_storage('YourFilename.extension')
|
215
122
|
|
123
|
+
# Download file
|
124
|
+
filename = crowdin.download_file(your_file_id, your_destination, your_project_id)
|
125
|
+
# your_destination - filename or full path to file, default - saving to currect directory with default filename
|
126
|
+
# project_id is optional, as it can be initialized with a Crowdin Client
|
216
127
|
|
217
|
-
|
218
|
-
|
128
|
+
# File revisions
|
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)
|
219
133
|
```
|
220
134
|
|
221
|
-
###
|
222
|
-
|
223
|
-
Track overall translation and proofreading progress of each target language.
|
135
|
+
### Command-Line Client
|
224
136
|
|
225
|
-
|
137
|
+
The Crowdin Ruby client support crowdin-console, where you can test endpoints easier
|
226
138
|
|
227
|
-
```
|
228
|
-
crowdin
|
139
|
+
```console
|
140
|
+
$ bundle exec crowdin-console --enable-logger --api-token API_TOKEN --project-id PROJECT_ID
|
229
141
|
```
|
230
142
|
|
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>
|
143
|
+
Or Crowdin Enterprise
|
236
144
|
|
237
|
-
```
|
238
|
-
crowdin
|
145
|
+
```console
|
146
|
+
$ bundle exec crowdin-console --enable-logger --enterprise --api-token API_TOKEN --organization-domain YOUR_DOMAIN --project-id PROJECT_ID
|
239
147
|
```
|
148
|
+
Note: you can specify full organization domain by adding .com
|
240
149
|
|
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>
|
150
|
+
When execute you'll have IRB console with configured *@crowdin* instance
|
254
151
|
|
255
|
-
```ruby
|
256
|
-
crowdin.export_translations
|
257
152
|
```
|
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')
|
153
|
+
> @crowdin.list_projects
|
270
154
|
```
|
271
155
|
|
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
|
156
|
+
## Seeking Assistance
|
285
157
|
|
286
|
-
|
158
|
+
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
159
|
|
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
|
160
|
+
Need help working with Crowdin Ruby client or have any questions? [Contact](https://crowdin.com/contacts) Customer Success Service.
|
314
161
|
|
315
162
|
## Contributing
|
316
163
|
|
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
|
164
|
+
If you want to contribute please read the [Contributing](/CONTRIBUTING.md) guidelines.
|
324
165
|
|
325
|
-
|
166
|
+
## License
|
326
167
|
|
327
|
-
|
168
|
+
<pre>
|
169
|
+
The Crowdin Ruby Client is licensed under the MIT License.
|
170
|
+
See the LICENSE.md file distributed with this work for additional
|
171
|
+
information regarding copyright ownership.
|
328
172
|
|
329
|
-
|
173
|
+
Except as contained in the LICENSE file, the name(s) of the above copyright
|
174
|
+
holders shall not be used in advertising or otherwise to promote the sale,
|
175
|
+
use or other dealings in this Software without prior written authorization.
|
176
|
+
</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,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::ApiErrorsRaiser
|
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
data/crowdin-api.gemspec
ADDED
@@ -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,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_parameter_is_required_error(:language_id)
|
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_parameter_is_required_error(:language_id)
|
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_parameter_is_required_error(:language_id)
|
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
|