crowdin-api 0.3.0 → 0.4.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72070c7f8a25a54dbce0ed12d8c2788428fe0747
4
- data.tar.gz: 97ea30a8860ca975dedef7a55cd71abbb34965da
3
+ metadata.gz: 21b2c419fc865199393792868efd92917fe9350b
4
+ data.tar.gz: 2bbb0c118a6480be3ca45000682e7d3482597e45
5
5
  SHA512:
6
- metadata.gz: 005b02706cda35ba8de5fc38ac0efba1b48e37a3cdf70209e4756ead6b88391e072e23a49f8311c842207add560fb853f6b94310ab923b1c0888b755819dd73d
7
- data.tar.gz: 469129180e883c4665487cbe5abcecabaf0a743bd928f2834451b439c2d67e23cdc18677297b6a42848db120c139e933b684a22dbecb9de6f8c23906b4513df4
6
+ metadata.gz: aba7345cf676b48cf41475198e9a0212e3ce46396bb554e31154d634f7258878de24cb292565edc6effbcc48097d962288e4e9a34aeece9b340206bc8bf3bc41
7
+ data.tar.gz: 3d58d2f449e22e30d098dafe4853a5d1e213215406fd58e6084eef6abff26b50d304a6c065e9eebaec77716d429d1c4c53476f7d0f6d08c55830e8b73a40ce73
data/README.md CHANGED
@@ -4,6 +4,8 @@ A Ruby interface to the Crowdin API.
4
4
 
5
5
  For more about the Crowdin API see <https://crowdin.com/page/api>.
6
6
 
7
+ To experiment with that code, run `bin/console` for an interactive prompt.
8
+
7
9
  > **WARNING**: This is a development version: It contains the latest changes, but may also have severe known issues, including crashes and data loss situations. In fact, it may not work at all.
8
10
 
9
11
  ## Installation
@@ -59,6 +61,9 @@ Every file is hash:
59
61
  * `:title` - string that defines title for uploaded file (optional)
60
62
  * `:export_pattern` - string that defines name of resulted file (optional)
61
63
 
64
+ Optional params:
65
+ * `:branch` - a branch name (optional)
66
+
62
67
  **NOTE!** 20 files max are allowed to upload per one time file transfer.
63
68
 
64
69
  ```ruby
@@ -82,6 +87,9 @@ Every file is hash:
82
87
  * `:title` - title for uploaded file (optional)
83
88
  * `:export_pattern` - string that defines name of resulted file (optional)
84
89
 
90
+ Optional params:
91
+ * `:branch` - a branch name (optional)
92
+
85
93
  **NOTE!** 20 files max are allowed to upload per one time file transfer.
86
94
 
87
95
  ```ruby
@@ -107,16 +115,31 @@ crowdin.delete_file('strings.xml')
107
115
 
108
116
  Create a new directory in Crowdin project.
109
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
+
110
124
  Documentation: <https://crowdin.com/page/api/add-directory>
111
125
 
112
126
  ```ruby
113
127
  crowdin.add_directory('dirname')
114
128
  ```
115
129
 
130
+ Create a new branch:
131
+
132
+ ```ruby
133
+ crowdin.add_directory('master', is_branch: '1')
134
+ ```
135
+
116
136
  ### Delete Directory
117
137
 
118
138
  Remove directory with nested files from Crowdin project.
119
139
 
140
+ Optional params:
141
+ * `:branch` - a branch name (optional)
142
+
120
143
  Documentation: <https://crowdin.com/page/api/delete-directory>
121
144
 
122
145
  ```ruby
@@ -135,6 +158,8 @@ Optional params:
135
158
  * `:new_name` - new directory name
136
159
  * `:title` - new directory title to be displayed in Crowdin UI
137
160
  * `:export_pattern` - new direcrory export pattern. Is used to create directory name and path in resulted translations bundle.
161
+ * `:branch` - a branch name.
162
+
138
163
 
139
164
  When renaming directory the path can not be changed (it means `new_name` parameter can not contain path, name only).
140
165
 
@@ -161,6 +186,7 @@ Optional params:
161
186
  * `:import_duplicates` - defines whether to add translation if there is the same translation previously added (default: false)
162
187
  * `:import_eq_suggestions` - defines whether to add translation if it is equal to source string at Crowdin (default: false)
163
188
  * `:auto_approve_imported` - mark uploaded translations as approved (default: false)
189
+ * `:branch` - a branch name (default: nil)
164
190
 
165
191
  **NOTE!** 20 files max are allowed to upload per one time file transfer.
166
192
 
@@ -183,6 +209,11 @@ Documentation: <https://crowdin.com/page/api/download>
183
209
 
184
210
  First parameter is the language of translation you need or download `all` of them at once.
185
211
 
212
+ Optional params:
213
+ * `:output` - a name of ZIP file with translations
214
+ * `:branch` - a branch name (default: nil)
215
+
216
+
186
217
  ```ruby
187
218
  crowdin.download_translation('ru', :output => '/path/to/download/ru_RU.zip')
188
219
  ```
@@ -216,6 +247,9 @@ Build ZIP archive with the latest translations.
216
247
  Also API call will be ignored if there were no changes in the project since previous export.
217
248
  You can see whether ZIP archive with latest translations was actually build by status attribute (`built` or `skipped`) returned in response.
218
249
 
250
+ Optional params:
251
+ * `:branch` - a branch name (default: nil)
252
+
219
253
  Documentation: <https://crowdin.com/page/api/export>
220
254
 
221
255
  ```ruby
@@ -276,7 +310,7 @@ Documentation: <https://crowdin.com/page/api/supported-languages>
276
310
  Tested with the following Ruby versions:
277
311
 
278
312
  - MRI 2.2.1
279
- - JRuby 9.0.0.0.pre2
313
+ - JRuby 9.0.0.0
280
314
 
281
315
  ## Contributing
282
316
 
@@ -1,4 +1,3 @@
1
- require 'pp'
2
1
  require 'json'
3
2
  require 'rest-client'
4
3
 
@@ -70,6 +69,9 @@ module Crowdin
70
69
  end
71
70
 
72
71
  def request(params, &block)
72
+ # Returns a query hash with non nil values.
73
+ params[:query].reject! { |_, value| value.nil? } if params[:query]
74
+
73
75
  case params[:method]
74
76
  when :post
75
77
  query = @connection.options.merge(params[:query] || {})
@@ -84,7 +86,6 @@ module Crowdin
84
86
  end
85
87
 
86
88
  log.debug("args: #{@response.args}") if log
87
- log.debug("body: #{@response.body}") if log
88
89
 
89
90
  if @response.headers[:content_disposition]
90
91
  filename = params[:output] || @response.headers[:content_disposition][/attachment; filename="(.+?)"/, 1]
@@ -95,6 +96,8 @@ module Crowdin
95
96
  return true
96
97
  else
97
98
  doc = JSON.load(@response.body)
99
+ log.debug("body: #{doc}") if log
100
+
98
101
  if doc.kind_of?(Hash) && doc['success'] == false
99
102
  code = doc['error']['code']
100
103
  message = doc['error']['message']
@@ -18,6 +18,14 @@ module Crowdin
18
18
  # * :title - title in Crowdin UI (optional)
19
19
  # * :export_pattern - Resulted file name (optional)
20
20
  #
21
+ # Optional:
22
+ # * :branch - a branch name.
23
+ # If the branch is not exists Crowdin will be return an error:
24
+ # "error":{
25
+ # "code":8,
26
+ # "message":"File was not found"
27
+ # }
28
+ #
21
29
  # == Request
22
30
  #
23
31
  # POST https://api.crowdin.com/api/project/{project-identifier}/add-file?key={project-key}
@@ -54,6 +62,9 @@ module Crowdin
54
62
  # * :title - title in Crowdin UI (optional)
55
63
  # * :export_pattern - Resulted file name (optional)
56
64
  #
65
+ # Optional:
66
+ # * :branch - a branch name
67
+ #
57
68
  # == Request
58
69
  #
59
70
  # POST https://api.crowdin.com/api/project/{project-identifier}/update-file?key={project-key}
@@ -89,13 +100,16 @@ module Crowdin
89
100
  #
90
101
  # files - Array of files that should be added to Crowdin project.
91
102
  # file is a Hash { :dest, :source }
92
- # * :dest - file name with path in Crowdin project (required)
93
- # * :source - path for uploaded file (required)
103
+ # * :dest - file name with path in Crowdin project (required)
104
+ # * :source - path for uploaded file (required)
105
+ # language - Target language. With a single call it's possible to upload translations for several
106
+ # files but only into one of the languages. (required)
94
107
  #
95
108
  # Optional:
96
109
  # * :import_duplicates (default: false)
97
110
  # * :import_eq_suggestions (default: false)
98
111
  # * :auto_approve_imported (default: false)
112
+ # * :branch - a branch name
99
113
  #
100
114
  # == Request
101
115
  #
@@ -120,6 +134,10 @@ module Crowdin
120
134
  #
121
135
  # Note: If you would like to download the most recent translations you may want to use export API method before downloading.
122
136
  #
137
+ # Optional:
138
+ # * :output - a name of ZIP file with translations
139
+ # * :branch - a branch name
140
+ #
123
141
  # == Request
124
142
  #
125
143
  # GET https://api.crowdin.com/api/project/{project-identifier}/download/{package}.zip?key={project-key}
@@ -128,7 +146,8 @@ module Crowdin
128
146
  request(
129
147
  :method => :get,
130
148
  :path => "/api/project/#{@project_id}/download/#{language}.zip",
131
- :output => params[:output],
149
+ :output => params.delete(:output),
150
+ :query => params,
132
151
  )
133
152
  end
134
153
 
@@ -167,29 +186,53 @@ module Crowdin
167
186
 
168
187
  # Add directory to Crowdin project.
169
188
  #
189
+ # == Parameters
190
+ #
191
+ # name - directory name (with path if nested directory should be created). (required)
192
+ #
193
+ # Optional:
194
+ # * :is_branch - create new branch. Valid values - 0, 1. Only when create root directory.
195
+ # * :branch - a branch name.
196
+ #
170
197
  # == Request
171
198
  #
172
199
  # POST https://api.crowdin.com/api/project/{project-identifier}/add-directory?key={project-key}
173
200
  #
174
- def add_directory(name)
201
+ def add_directory(name, params = {})
202
+ params[:name] = name
203
+
175
204
  request(
176
205
  :method => :post,
177
206
  :path => "/api/project/#{@project_id}/add-directory",
178
- :query => { :name => name },
207
+ :query => params,
179
208
  )
180
209
  end
181
210
 
182
211
  # Delete Crowdin project directory. All nested files and directories will be deleted too.
183
212
  #
213
+ # == Parameters
214
+ #
215
+ # name - Directory path (or just name if the directory is in root) (required)
216
+ # :branch - a branch name (optional)
217
+ #
218
+ # FIXME
219
+ # When you try to remove the branch directory Crowdin will be return an error:
220
+ # "error":{
221
+ # "code":17,
222
+ # "message":"Specified directory was not found"
223
+ # }
224
+ #
184
225
  # == Request
185
226
  #
186
227
  # POST https://api.crowdin.com/api/project/{project-identifier}/delete-directory?key={project-key}
187
228
  #
188
- def delete_directory(name)
229
+ def delete_directory(name, params = {})
230
+ params[:name] = name
231
+
189
232
  request(
190
233
  :method => :post,
191
234
  :path => "/api/project/#{@project_id}/delete-directory",
192
- :query => { :name => name },
235
+ :query => params,
193
236
  )
194
237
  end
195
238
 
@@ -204,6 +247,7 @@ module Crowdin
204
247
  # * :new_name - new directory name (not contain path, name only)
205
248
  # * :title - new directory title to be displayed in Crowdin UI
206
249
  # * :export_pattern - new directory export pattern
250
+ # * :branch - a branch name
207
251
  #
208
252
  # == Request
209
253
  #
@@ -267,14 +311,18 @@ module Crowdin
267
311
  # Please note that this method can be invoked only every 30 minutes.
268
312
  # Also API call will be ignored if there were no any changes in project since last export.
269
313
  #
314
+ # Optional:
315
+ # * :branch - a branch name
316
+ #
270
317
  # == Request
271
318
  #
272
- # POST https://api.crowdin.com/api/project/{project-identifier}/export?key={project-key}
319
+ # GET https://api.crowdin.com/api/project/{project-identifier}/export?key={project-key}
273
320
  #
274
- def export_translations
321
+ def export_translations(params = {})
275
322
  request(
276
- :method => :post,
323
+ :method => :get,
277
324
  :path => "/api/project/#{@project_id}/export",
325
+ :query => params,
278
326
  )
279
327
  end
280
328
 
@@ -1,5 +1,5 @@
1
1
  module Crowdin
2
2
  class API
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0.pre"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crowdin-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Crowdin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-29 00:00:00.000000000 Z
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
41
69
  description: Ruby Client for the Crowdin API
42
70
  email:
43
71
  - support@crowdin.net
@@ -68,12 +96,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
96
  version: '0'
69
97
  required_rubygems_version: !ruby/object:Gem::Requirement
70
98
  requirements:
71
- - - ">="
99
+ - - ">"
72
100
  - !ruby/object:Gem::Version
73
- version: '0'
101
+ version: 1.3.1
74
102
  requirements: []
75
103
  rubyforge_project:
76
- rubygems_version: 2.4.6
104
+ rubygems_version: 2.4.8
77
105
  signing_key:
78
106
  specification_version: 4
79
107
  summary: Client library to manage translations on Crowdin