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.
- checksums.yaml +4 -4
- 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 +146 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +71 -0
- data/Gemfile +5 -0
- data/LICENSE +1 -1
- data/README.md +120 -280
- 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/dictionaries.rb +34 -0
- data/lib/crowdin-api/api-resources/distributions.rb +99 -0
- data/lib/crowdin-api/api-resources/glossaries.rb +217 -0
- data/lib/crowdin-api/api-resources/labels.rb +117 -0
- data/lib/crowdin-api/api-resources/languages.rb +82 -0
- data/lib/crowdin-api/api-resources/machine_translation_engines.rb +74 -0
- data/lib/crowdin-api/api-resources/projects.rb +148 -0
- data/lib/crowdin-api/api-resources/reports.rb +138 -0
- data/lib/crowdin-api/api-resources/screenshots.rb +186 -0
- data/lib/crowdin-api/api-resources/source_files.rb +304 -0
- data/lib/crowdin-api/api-resources/source_strings.rb +74 -0
- data/lib/crowdin-api/api-resources/storages.rb +106 -0
- data/lib/crowdin-api/api-resources/string_comments.rb +73 -0
- data/lib/crowdin-api/api-resources/string_translations.rb +220 -0
- data/lib/crowdin-api/api-resources/tasks.rb +113 -0
- data/lib/crowdin-api/api-resources/teams.rb +144 -0
- data/lib/crowdin-api/api-resources/translation_memory.rb +145 -0
- data/lib/crowdin-api/api-resources/translation_status.rb +89 -0
- data/lib/crowdin-api/api-resources/translations.rb +161 -0
- data/lib/crowdin-api/api-resources/users.rb +129 -0
- data/lib/crowdin-api/api-resources/vendors.rb +21 -0
- data/lib/crowdin-api/api-resources/webhooks.rb +73 -0
- data/lib/crowdin-api/api-resources/workflows.rb +62 -0
- data/lib/crowdin-api/client/client.rb +95 -0
- data/lib/crowdin-api/client/configuration.rb +48 -0
- data/lib/crowdin-api/client/version.rb +7 -0
- data/lib/crowdin-api/core/errors.rb +8 -0
- data/lib/crowdin-api/core/errors_raisers.rb +39 -0
- data/lib/crowdin-api/core/request.rb +118 -0
- data/lib/crowdin-api/core/utils.rb +10 -0
- data/lib/crowdin-api.rb +39 -126
- data/spec/client/client-instance_spec.rb +14 -0
- data/spec/client/configuration-instance_spec.rb +72 -0
- data/spec/spec_helper.rb +9 -0
- metadata +130 -47
- 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,52 @@
|
|
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
|
+
[![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
|
-
|
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
|
-
|
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
|
-
|
62
|
+
:exclamation: Migration from version *0.6.0* to *1.x.x* requires changes in your code.
|
148
63
|
|
149
|
-
|
64
|
+
---
|
150
65
|
|
151
|
-
|
66
|
+
## Quick start
|
152
67
|
|
68
|
+
### Initialization
|
153
69
|
```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:
|
70
|
+
require 'crowdin-api'
|
166
71
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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:
|
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
|
-
|
198
|
-
|
199
|
-
|
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
|
-
|
108
|
+
### Usage
|
203
109
|
|
204
110
|
```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
|
-
```
|
111
|
+
# Create Project
|
112
|
+
project = crowdin.add_project(name: your_project_name, sourceLanguageId: your_language_id)
|
214
113
|
|
215
|
-
|
114
|
+
# Get list of Projects
|
115
|
+
projects = crowdin.list_projects
|
216
116
|
|
217
|
-
|
117
|
+
# Get list of Projects with offset and limit
|
118
|
+
projects = crowdin.list_projects(offset: 10, limit: 20)
|
218
119
|
|
219
|
-
|
120
|
+
# Get specified project
|
121
|
+
project = crowdin.get_project(your_project_id)
|
220
122
|
|
221
|
-
|
123
|
+
# Edit project
|
124
|
+
project = crowdin.edit_project(project_id, [{op: 'replace',
|
125
|
+
path: '/name',
|
126
|
+
value: 'your_new_project_name'}])
|
222
127
|
|
223
|
-
|
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
|
-
|
226
|
-
|
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
|
-
|
229
|
-
|
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
|
-
###
|
146
|
+
### Command-Line Client
|
233
147
|
|
234
|
-
|
148
|
+
The Crowdin Ruby client support crowdin-console, where you can test endpoints easier
|
235
149
|
|
236
|
-
|
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
|
-
|
243
|
-
|
244
|
-
Shows project details and meta information (last translations date, currently uploaded files, target languages etc..).
|
154
|
+
Or Crowdin Enterprise
|
245
155
|
|
246
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
177
|
+
## License
|
344
178
|
|
345
|
-
|
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
|
-
|
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
|
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::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
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,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
|