uploadcare-ruby 1.0.6 → 1.1.0

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: 7202dfd94679cd8f39df975484a50a6b1b8f7474
4
- data.tar.gz: f53742f0245eae1002a6351afab310bcbdb3175d
3
+ metadata.gz: a64d207f7ef4f89a13f68834cea937420cc9f3a8
4
+ data.tar.gz: 4dfa8a074d60bc1a37651fb5c3f138799fe38154
5
5
  SHA512:
6
- metadata.gz: 8f66ab85489edc1e08c87b63fb294cdff5dd382df5c5c80e531504dad1b7edaf8c16969448bbf721d9bf17f7af9175e3466cc7062feb2850af6f43b49903446c
7
- data.tar.gz: c7ada37e8c0d23a9ffafe7dc9ce16f758e3ecafe092b0b099777e24f75c32ceccc13083464514edf1462898dddcc28ec920f427fa30079bb00e0a5324255300e
6
+ metadata.gz: b23740f26de3e0eeffdb832e431f0a4f739c089afb23f6e9d60a880e1ea2cb497e8288684c8abf96ee4a3daeaaeaea571723e18970fe979dbb1fea77dde4c07f
7
+ data.tar.gz: 4552d01fa016da894a2ed61e02f4ead93723b65faa76014ba61ef8af673fa20a61203831efe89e1aa552dfc3cdd39c3abe83622ea9ef93ce6f70e274a261f70f
@@ -1,5 +1,12 @@
1
1
  #Changelog
2
2
 
3
+ ### 1.1.0, 21.03.2017
4
+
5
+ - Deprecated `Uploadcare::Api::File#copy` in favor of `#internal_copy` and `#external_copy`.
6
+ - Added to new methods to Uploadcare::Api::File, #internal_copy and #external_copy.
7
+ - Added support of [secure authorization](https://uploadcare.com/documentation/rest/#request) for REST API. It is now used by default (can be overriden in config)
8
+ - Fixed middleware names that could break other gems ([#13](https://github.com/uploadcare/uploadcare-ruby/issues/13}).
9
+
3
10
  ### 1.0.6, 30.01.2017
4
11
 
5
12
  - Fixed incorrect dependencies
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Uploadcare, LLC
3
+ Copyright (c) 2017 Uploadcare, LLC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,42 +1,42 @@
1
1
  [![Build Status](https://secure.travis-ci.org/uploadcare/uploadcare-ruby.png?branch=master)](http://travis-ci.org/uploadcare/uploadcare-ruby)
2
2
 
3
- A ruby wrapper for [Uploadcare.com](https://uploadcare.com) service.
4
-
3
+ A [Ruby](https://www.ruby-lang.org/en/) wrapper for [Uploadcare](https://uploadcare.com).
5
4
 
6
5
  ## Installation
7
6
 
8
- Add this line to your application's Gemfile:
7
+ Installing `uploadcare-ruby` is quite simple and takes a couple of steps.
8
+ First of, add the following line to your app's Gemfile:
9
9
 
10
10
  ```ruby
11
11
  gem 'uploadcare-ruby'
12
12
  ```
13
13
 
14
- And then execute:
14
+ Once you've added the line, execute this:
15
15
 
16
16
  ```shell
17
17
  $ bundle install
18
18
  ```
19
19
 
20
- Or install it yourself:
20
+ Or that (for manual install):
21
21
 
22
22
  ```shell
23
23
  $ gem install uploadcare-ruby
24
24
  ```
25
25
 
26
- --
26
+ ## Initialization
27
27
 
28
- ## Initalizations
29
- Just create an API object - and you're good to go.
28
+ Init is simply done through creating an API object.
30
29
 
31
30
  ```ruby
32
31
  require 'uploadcare'
33
32
 
34
- @api = Uploadcare::Api.new #with default settings
33
+ @api = Uploadcare::Api.new # default settings are used
35
34
 
36
- @api = Uploadcare::Api.new(settings)
35
+ @api = Uploadcare::Api.new(settings) # using user-defined settings
37
36
  ```
38
37
 
39
- ### Default settings
38
+ Here's how the default settings look like:
39
+
40
40
  ``` ruby
41
41
  {
42
42
  public_key: 'demopublickey', # you need to override this
@@ -46,51 +46,42 @@ require 'uploadcare'
46
46
  static_url_base: 'https://ucarecdn.com',
47
47
  api_version: '0.3',
48
48
  cache_files: true,
49
+ auth_scheme: :secure
49
50
  }
50
51
  ```
51
52
 
52
- [Upload API](https://uploadcare.com/documentation/upload/) requires public key and [REST API](https://uploadcare.com/documentation/rest/) requires both public and private keys for authentication.
53
-
54
- You can find and manage your project's API keys on project's overview page.
55
- Open [dashboard](https://uploadcare.com/dashboard/), click on the project's name and find "Keys" section.
56
-
57
- If you haven't found what you were looking for in these docs, try looking in our [Knowledge Base](http://kb.uploadcare.com/).
58
-
59
- --
60
-
61
- ## Raw API
62
- Raw API is a simple interface that allows you to make custom requests to Uploadcare REST API.
63
- Just in case you want some low-level control over your app.
64
-
65
- ```ruby
66
- # any request
67
- @api.request :get, "/files/", {page: 2}
68
-
69
- # you also have the shortcuts for methods
70
- @api.get '/files', {page: 2}
71
-
72
- @api.post ...
53
+ You're free to use both `demopublickey` and `demoprivatekey`
54
+ for initial testing purposes. We wipe out files loaded to our
55
+ demo account periodically. For a better experience,
56
+ consider creating an Uploadcare account. Check out
57
+ [this](http://kb.uploadcare.com/article/234-uc-project-and-account)
58
+ article to get up an running in minutes.
73
59
 
74
- @api.put ...
60
+ Please note, in order to use [Upload API](https://uploadcare.com/documentation/upload/)
61
+ you will only need the public key alone. However, using
62
+ [REST API](https://uploadcare.com/documentation/rest/) requires you to
63
+ use both public and private keys for authentication.
64
+ While “private key” is a common way to name a key from an
65
+ authentication key pair, the actual thing for our `auth-param` is `secret_key`.
75
66
 
76
- @api.delete ...
67
+ ## Usage
77
68
 
78
- ```
79
- All raw API methods return parsed JSON response or raise an error (which you should handle yourself).
69
+ This section contains practical usage examples. Please note,
70
+ everything that follows gets way more clear once you've looked
71
+ through our docs [intro](https://uploadcare.com/documentation/).
80
72
 
81
- --
73
+ ### Basic usage: uploading a single file, manipulations
82
74
 
83
- ## Basic usage
84
- Using Uploadcare is pretty easy (which is the essence of the service itself).
75
+ Using Uploadcare is simple, and here are the basics of handling files.
85
76
 
86
- Create the API object:
77
+ First of, create the API object:
87
78
 
88
79
  ```ruby
89
80
  @api = Uploadcare::Api.new(CONFIG)
90
81
 
91
82
  ```
92
83
 
93
- Upload file
84
+ And yeah, now you can upload a file:
94
85
 
95
86
  ```ruby
96
87
  @file_to_upload = File.open("your-file.png")
@@ -99,62 +90,56 @@ Upload file
99
90
  # => #<Uploadcare::Api::File ...
100
91
  ```
101
92
 
102
- Use file
93
+ Then, let's check out UUID and URL of the
94
+ file you've just uploaded:
103
95
 
104
96
  ```ruby
105
- # file uuid (you probably want to store it somewhere)
97
+ # file uuid (you'd probably want to store those somewhere)
106
98
  @uc_file.uuid
107
- # => "c969be02-9925-4a7e-aa6d-b0730368791c"
99
+ # => "dc99200d-9bd6-4b43-bfa9-aa7bfaefca40"
108
100
 
109
- # url for the file - just paste in your template and you good to go.
101
+ # url for the file, can be used with your website or app right away
110
102
  @uc_file.cdn_url
111
- # => "https://ucarecdn.com/c969be02-9925-4a7e-aa6d-b0730368791c/"
103
+ # => "https://ucarecdn.com/dc99200d-9bd6-4b43-bfa9-aa7bfaefca40/"
112
104
  ```
113
105
 
114
- Store or delete file
106
+ Your might then want to store or delete the uploaded file.
107
+ Storing files could be crucial if you aren't using the
108
+ “Automatic file storing” option for your Uploadcare project.
109
+ If not stored manually or automatically, files get deleted
110
+ within a 24-hour period.
115
111
 
116
112
  ```ruby
117
- # store file (if you dont use autostore option)
113
+ # that's how you store a file
118
114
  @uc_file.store
119
115
  # => #<Uploadcare::Api::File ...
120
116
 
121
- # and delete file
117
+ # and that works for deleting it
122
118
  @uc_file.delete
123
119
  # => #<Uploadcare::Api::File ...
124
120
  ```
125
- ## Uploading
126
- You can upload either File object (array of files will also cut it) or custom URL.
127
121
 
128
- ### Uploading from URL
129
- Just throw your URL into API - and you're good to go.
122
+ ### Uploading a file from URL
123
+
124
+ Now, this one is also quick. Just pass your URL into our API
125
+ and you're good to go.
130
126
 
131
127
  ```ruby
132
- # smart upload
128
+ # the smart upload
133
129
  @file = @api.upload "http://your.awesome/avatar.jpg"
134
130
  # => #<Uploadcare::Api::File ...
135
131
 
136
- # explicitly upload from URL
132
+ # use this one if you want to explicitly upload from URL
137
133
  @file = @api.upload_from_url "http://your.awesome/avatar.jpg"
138
134
  # => #<Uploadcare::Api::File ...
139
135
  ```
140
- Keep in mind that invalid URL will raise an `ArgumentError`.
141
-
142
- ### Uploading a single file
143
- Like with URL - just start throwing your file into API
144
-
145
- ```ruby
136
+ Keep in mind that providing invalid URL
137
+ will raise `ArgumentError`.
146
138
 
147
- file = File.open("path/to/your/file.png")
148
-
149
- @uc_file = @api.upload file
150
- # => #<Uploadcare::Api::File ...
151
-
152
- ```
153
- And that's it.
139
+ ### Uploading multiple files
154
140
 
155
- ### Uploading an array of files
156
- Uploading of an array is just as easy as uploading a single file.
157
- Note, that every object in array must be an instance of `File`.
141
+ Uploading multiple files is as simple as passing an array
142
+ of `File` instances into our API.
158
143
 
159
144
  ```ruby
160
145
  file1 = File.open("path/to/your/file.png")
@@ -162,22 +147,30 @@ file2 = File.open("path/to/your/another-file.png")
162
147
  files = [file1, file2]
163
148
 
164
149
  @uc_files = @api.upload files
165
- # => [#<Uploadcare::Api::File uuid="24626d2f-3f23-4464-b190-37115ce7742a">,
166
- # #<Uploadcare::Api::File uuid="7bb9efa4-05c0-4f36-b0ef-11a4221867f6">]
150
+ # => [#<Uploadcare::Api::File uuid="dc99200d-9bd6-4b43-bfa9-aa7bfaefca40">,
151
+ # #<Uploadcare::Api::File uuid="96cdc400-adc3-435b-9c94-04cd87633fbb">]
167
152
  ```
168
- It is returning you an array of Uploadcare files.
153
+
154
+ In case of multiple input, the respective output would also be an array.
155
+ You can iterate through the array to address to single files.
156
+ You might also want to request more info about a file using `load_data`.
169
157
 
170
158
  ```ruby
171
159
  @uc_files[0]
172
- # => #<Uploadcare::Api::File uuid="24626d2f-3f23-4464-b190-37115ce7742a">
160
+ # => #<Uploadcare::Api::File uuid="dc99200d-9bd6-4b43-bfa9-aa7bfaefca40">
173
161
 
174
- @uc_files[0].load_data
175
- # => #<Uploadcare::Api::File uuid="7bb9efa4-05c0-4f36-b0ef-11a4221867f6", original_file_url="https://ucarecdn.com/7bb9efa4-05c0-4f36-b0ef-11a4221867f6/view.png", image_info={"width"=>800, "geo_location"=>nil, "datetime_original"=>nil, "height"=>600}, ....>
162
+ @uc_files[1].load_data
163
+ # => #<Uploadcare::Api::File uuid="96cdc400-adc3-435b-9c94-04cd87633fbb", original_file_url="https://ucarecdn.com/96cdc400-adc3-435b-9c94-04cd87633fbb/samuelzeller118195.jpg", image_info={"width"=>4896, "geo_location"=>nil, "datetime_original"=>nil, "height"=>3264}, ....>
176
164
  ```
177
165
 
178
- ## File
179
- `File` - is the primary object for Uploadcare API. Basically it's an avatar for file stored for you ).
180
- So all the operations you do - you do it with the file object.
166
+ ### `File` object
167
+
168
+ Now that we've already outlined using arrays of `File` instances
169
+ to upload multiple files, let's fix on the `File` itself.
170
+ It's the the primary object for Uploadcare API.
171
+ Basically, it's an avatar for a file you uploaded.
172
+ And all the further operations are performed using this avatar,
173
+ the `File` object.
181
174
 
182
175
  ```ruby
183
176
  @file_to_upload = File.open("your-file.png")
@@ -186,28 +179,32 @@ So all the operations you do - you do it with the file object.
186
179
  # => #<Uploadcare::Api::File ...
187
180
 
188
181
  @uc_file.uuid
189
- # => "c969be02-9925-4a7e-aa6d-b0730368791c"
182
+ # => "dc99200d-9bd6-4b43-bfa9-aa7bfaefca40"
190
183
 
191
184
  @uc_file.cdn_url
192
- # => "https://ucarecdn.com/c969be02-9925-4a7e-aa6d-b0730368791c/"
185
+ # => "https://ucarecdn.com/dc99200d-9bd6-4b43-bfa9-aa7bfaefca40/"
193
186
  ```
194
187
 
195
- There is one issue with files - all data associated with it accesible with separate HTTP request only.
196
- So if don't *specificaly* need image data (like file name, geolocation data etc.) - you could just use :uuid and :cdn_url methods for file output:
188
+ Please note, all the data associated with files is only accessible
189
+ through separate HTTP requests only. So if you don't specifically
190
+ need file data (filenames, image dimensions, etc.), you'll be just
191
+ fine with using `:uuid` and `:cdn_url` methods for file output:
197
192
 
198
193
  ```erb
199
194
  <img src="#{@file.cdn_url}"/>
200
195
  ```
201
196
 
202
- And that's it. Saves precious loading time.
203
-
204
- If you do however need image data - you could do it manualy:
197
+ Great, we've just lowered a precious loading time.
198
+ However, if you do need the data, you can always request
199
+ it manually:
205
200
 
206
201
  ```ruby
207
202
  @uc_file.load_data
208
203
  ```
209
204
 
210
- Then your file object will respond to any method, described in API documentation (it basicaly an OpenStruct, so you know what to do):
205
+ That way your file object will respond to any method described
206
+ in [API docs](https://uploadcare.com/documentation/rest/#file).
207
+ Basically, that's an an OpenStruct, so you know what to do:
211
208
 
212
209
  ```ruby
213
210
  @uc_file.original_filename
@@ -217,80 +214,253 @@ Then your file object will respond to any method, described in API documentation
217
214
  # => {"width"=>397, "geo_location"=>nil, "datetime_original"=>nil, "height"=>81}
218
215
  ```
219
216
 
220
- You could read more: https://uploadcare.com/documentation/rest/#file
217
+ ### `File` object from UUID or CDN URL
221
218
 
222
- ### Generating files from stored info
223
- At this point you probably store your files UUIDs or CDN urls in some kind of storage.
224
- Then you can create file object by passing them into API:
219
+ `File` objects are needed to manipulate files on our CDN.
220
+ The usual case would be you as a client storing file UUIDs
221
+ or CDN URLs somewhere on your side, e.g. in a database.
222
+ This is how you can use those to create `File` objects:
225
223
 
226
224
  ```ruby
227
- # file by UUID
228
- @file = @api.file "c969be02-9925-4a7e-aa6d-b0730368791c"
229
- # => #<Uploadcare::Api::File uuid="7bb9efa4-05c0-4f36-b0ef-11a4221867f6"
225
+ # file object from UUID
226
+ @file = @api.file "dc99200d-9bd6-4b43-bfa9-aa7bfaefca40"
227
+ # => #<Uploadcare::Api::File uuid="dc99200d-9bd6-4b43-bfa9-aa7bfaefca40"
230
228
 
231
- # file by CDN url
232
- @file = @api.file "https://ucarecdn.com/a8775cf7-0c2c-44fa-b071-4dd48637ecac/"
233
- # => #<Uploadcare::Api::File uuid="7bb9efa4-05c0-4f36-b0ef-11a4221867f6"
229
+ # file object from CDN URL
230
+ @file = @api.file "https://ucarecdn.com/dc99200d-9bd6-4b43-bfa9-aa7bfaefca40/"
231
+ # => #<Uploadcare::Api::File uuid="dc99200d-9bd6-4b43-bfa9-aa7bfaefca40"
234
232
 
235
- # not that generated files aren't loaded by initializing, you need to load it.
233
+ # note, files you generate won't be loaded on init,
234
+ # you'll need to load those manually
236
235
  @file.is_loaded?
237
236
  # => false
238
237
  ```
239
238
 
240
239
  ### Operations
241
- Uploadcare gives you some awesome CDN operations for croping, resizing, rotation, format convertation etc. You could read more at https://uploadcare.com/documentation/cdn/ .
242
- Version 1.0.0 of the gem has no specific methods for this kind of operations, we expect to add support for it later in 1.1 releases.
243
- For the moment all your file objects can store operations passed by cdn url:
240
+
241
+ Another way to mainpulate files on CDN is through operations.
242
+ This is particularly useful for images.
243
+ We've got on-the-fly crop, resize, rotation, format conversions, and
244
+ [more](https://uploadcare.com/documentation/cdn/).
245
+ Image operations are there to help you build responsive designs,
246
+ generate thumbnails and galleries, change formats, etc.
247
+ Currently, this gem has no specific methods for image operations,
248
+ we're planning to implement those in further versions.
249
+ However, we do support applying image operations through
250
+ adding them to CDN URLs. That's an Uploadcare CDN-native
251
+ way described in our [docs](https://uploadcare.com/documentation/cdn/).
244
252
 
245
253
  ```ruby
246
- @file = @api.file "https://ucarecdn.com/a8775cf7-0c2c-44fa-b071-4dd48637ecac/-/crop/150x150/center/-/format/png/"
247
- # => #<Uploadcare::Api::File uuid="a8775cf7-0c2c-44fa-b071-4dd48637ecac"
254
+ @file = @api.file "https://ucarecdn.com/dc99200d-9bd6-4b43-bfa9-aa7bfaefca40/-/crop/150x150/center/-/format/png/"
255
+ # => #<Uploadcare::Api::File uuid="dc99200d-9bd6-4b43-bfa9-aa7bfaefca40"
248
256
 
249
257
  @file.operations
250
258
  # => ["crop/150x150/center", "format/png"]
251
259
 
252
- # note that by default :cdn_url method will return url without any operations:
260
+ # note that by default :cdn_url method returns URLs with no operations:
253
261
  @file.cdn_url
254
- # => "https://ucarecdn.com/a8775cf7-0c2c-44fa-b071-4dd48637ecac/""
262
+ # => "https://ucarecdn.com/dc99200d-9bd6-4b43-bfa9-aa7bfaefca40/""
255
263
 
256
- # you can pass true to :cdn_url methods to get url with included operations:
264
+ # you can pass "true" into the :cdn_url method to get URL including operations:
257
265
  @file.cdn_url(true)
258
266
  # => "https://ucarecdn.com/a8775cf7-0c2c-44fa-b071-4dd48637ecac/-/crop/150x150/center/-/format/png/"
259
267
 
260
- # or call specific methods for url with or without them:
268
+ # there also are specific methods to either dump or include image operations
269
+ # in the output URL:
261
270
  @file.cdn_url_with_operations
262
271
  @file.cdn_url_without_operations
263
272
  ```
264
273
 
265
- Until operations wrapper is released the best way for you to manage operation is simply add them to URL as a string:
274
+ While there's no operation wrapper, the best way of handling operations
275
+ is through adding them to URLs as strings:
266
276
 
267
277
  ```ruby
268
278
  <img src="#{file.cdn_url}-/crop/#{width}x#{height}/center/"/>
269
279
  # or something like that
270
280
  ```
271
281
 
272
- ## File list and pagination
273
- File list is a paginated collection of files for you project. You could read more at https://uploadcare.com/documentation/rest/#pagination.
274
- In our gem file list is a single page containing 20 (by default, value may change) files and some methods for navigating through pages.
282
+ ### Copying files
283
+
284
+ You can also create file copies using our API.
285
+ There are multiple ways of creating those.
286
+ Also, copying is important for image files because
287
+ it allows you to “apply” all the CDN operations
288
+ specified in the source URL to a separate static image.
289
+
290
+ First of all, a copy of your file can be put in the Uploadcare storage.
291
+ This is called “internal copy”, and here's how it works:
275
292
 
276
293
  ```ruby
277
- @list = @api.file_list 1 #page number, 1 by default
294
+ @uc_file.internal_copy
295
+
296
+ # =>
297
+ {
298
+ "type"=>"file",
299
+ "result"=> {
300
+ "uuid"=>"a191a3df-2c43-4939-9590-784aa371ad6d",
301
+ "original_file_url"=>"https://ucarecdn.com/a191a3df-2c43-4939-9590-784aa371ad6d/19xldj.jpg",
302
+ "image_info"=>nil,
303
+ "datetime_stored"=>nil,
304
+ "mime_type"=>"application/octet-stream",
305
+ "is_ready"=>true,
306
+ "url"=>"https://api.uploadcare.com/files/a191a3df-2c43-4939-9590-784aa371ad6d/",
307
+ "original_filename"=>"19xldj.jpg",
308
+ "datetime_uploaded"=>"2017-02-10T14:14:18.690581Z",
309
+ "size"=>0,
310
+ "is_image"=>nil,
311
+ "datetime_removed"=>nil,
312
+ "source"=>"/4ea293d5-153f-422f-a24e-350237109606/"
313
+ }
314
+ }
315
+ ```
316
+
317
+ Once the procedure is complete, a copy would be a separate file
318
+ with its own UUID and attributes.
319
+
320
+ `#internal_copy` can optionally be used with the options hash argument.
321
+ The available options are:
322
+
323
+ - *store*
324
+
325
+ By default a copy is created without “storing”.
326
+ Which means it will be deleted within a 24-hour period.
327
+ You can make your output copy permanent by passing the
328
+ `store: true` option to the `#internal_copy` method.
329
+
330
+ Example:
331
+
332
+ ```ruby
333
+ @uc_file.internal_copy(store: true)
334
+ ```
335
+
336
+ - *strip_operations*
337
+
338
+ If your file is an image and you applied some operations to it,
339
+ then by default the same set of operations is also applied to a copy.
340
+ You can override this by passing `strip_operations: true` to the
341
+ `#internal_copy` method.
342
+
343
+ Example:
344
+
345
+ ```ruby
346
+ file = @api.file "https://ucarecdn.com/24626d2f-3f23-4464-b190-37115ce7742a/-/resize/50x50/"
347
+ file.internal_copy
348
+ # => This will trigger POST /files/ with {"source": "https://ucarecdn.com/24626d2f-3f23-4464-b190-37115ce7742a/-/resize/50x50/"} in the body
349
+ file.internal_copy(strip_operations: true)
350
+ # => This will trigger POST /files/ with {"source": "https://ucarecdn.com/24626d2f-3f23-4464-b190-37115ce7742a/"} in the body
351
+ ```
352
+
353
+ Another option is copying your file to a custom storage.
354
+ We call it “external copy” and here's the usage example:
355
+
356
+ ```ruby
357
+ @uc_file.external_copy('my_custom_storage_name')
358
+
359
+ # =>
360
+ {
361
+ "type"=>"url",
362
+ "result"=>"s3://my_bucket_name/c969be02-9925-4a7e-aa6d-b0730368791c/view.png"
363
+ }
364
+ ```
365
+
366
+ First argument of the `#external_copy` method is a name of
367
+ a custom destination storage for your file.
368
+
369
+ There's also an optional second argument — options hash. The available options are:
370
+
371
+ - *make_public*
372
+
373
+ Make a copy available via public links. Can be either `true` or `false`.
374
+
375
+ - *pattern*
376
+
377
+ Name pattern for a copy. If the parameter is omitted, custom storage pattern is used.
378
+
379
+ - *strip_operations*
380
+
381
+ Same as for `#internal_copy`
382
+
383
+ You might want to learn more about
384
+ [storage options](https://uploadcare.com/documentation/storages/) or
385
+ [copying files](https://uploadcare.com/documentation/rest/#files-post)
386
+ with Uploadcare.
387
+
388
+ ### `Group` object
389
+
390
+ Groups are structures intended to organize sets of separate files.
391
+ Each group is assigned UUID.
392
+ Note, group UUIDs include a `~#{files_count}` part at the end.
393
+ That's a requirement of our API.
394
+
395
+ ```ruby
396
+ # group can be created from an array of Uploadcare files
397
+ @files_ary = [@file, @file2]
398
+ @files = @api.upload @files_ary
399
+ @group = @api.create_group @files
400
+ # => #<Uploadcare::Api::Group uuid="0d192d66-c7a6-4465-b2cd-46716c5e3df3~2", files_count=2 ...
401
+
402
+ # another way to from a group is via an array of strings holding UUIDs
403
+ @uuids_ary = ["c969be02-9925-4a7e-aa6d-b0730368791c", "c969be02-9925-4a7e-aa6d-b0730368791c"]
404
+ @group = @api.create_group @uuids_ary
405
+ # => #<Uploadcare::Api::Group uuid="0d192d66-c7a6-4465-b2cd-46716c5e3df3~2", files_count=2 ...
406
+
407
+ # also, you can create a group object via group UUID
408
+ @group_uloaded = @api.group "#{uuid}"
409
+ ```
410
+
411
+ As with files, groups created via UUIDs are not loaded by default.
412
+ You need to load the data manually, as it requires a separate
413
+ HTTP GET request. New groups created with the `:create_group` method
414
+ are loaded by default.
415
+
416
+ ```ruby
417
+ @group = @api.group "#{uuid}"
418
+
419
+ @group.is_loaded?
420
+ # => false
421
+
422
+ @group.load_data
423
+ # => #<Uploadcare::Api::Group uuid="0d192d66-c7a6-4465-b2cd-46716c5e3df3~2", files_count=2 ...
424
+
425
+ # once a group is loaded, you can use any methods described in our API docs
426
+ # the files within a loaded group are loaded by default
427
+ @group.files
428
+ # => [#<Uploadcare::Api::File uuid="24626d2f-3f23-4464-b190-37115ce7742a" ...>,
429
+ # ... #{files_count} of them ...
430
+ # #<Uploadcare::Api::File uuid="7bb9efa4-05c0-4f36-b0ef-11a4221867f6" ...>]
431
+ ```
432
+
433
+ Check out our docs to learn more about
434
+ [groups](https://uploadcare.com/documentation/rest/#group).
435
+
436
+ ### File lists and pagination
437
+
438
+ File list is a paginated collection of files. Such lists are created
439
+ to better represent the contents of your project.
440
+ For this gem, a file list would be a single page containing
441
+ 20 files (you can override the number).
442
+ There also are methods for navigating through pages.
443
+ You can find more info about pagination
444
+ [here](https://uploadcare.com/documentation/rest/#pagination).
445
+
446
+ ```ruby
447
+ @list = @api.file_list 1 # page number, 1 is the default
278
448
  # => #<Uploadcare::Api::FileList ....
279
449
 
280
450
 
281
- # method :resulst will return you an array of files
451
+ # method :results returns an array of files
282
452
  @list.results
283
453
  # => [#<Uploadcare::Api::File uuid="24626d2f-3f23-4464-b190-37115ce7742a" ...>,
284
454
  # ... 20 of them ...
285
455
  # #<Uploadcare::Api::File uuid="7bb9efa4-05c0-4f36-b0ef-11a4221867f6" ...>]
286
456
 
287
457
 
288
- # note that every file is already loaded
458
+ # note, every file is already loaded
289
459
  @list.results[1].is_loaded?
290
460
  # => true
291
461
 
292
462
 
293
- # there is also shortcuts for you
463
+ # we've also added some shortcuts
294
464
  @list.to_a
295
465
  # => [#<Uploadcare::Api::File uuid="24626d2f-3f23-4464-b190-37115ce7742a" ...>,
296
466
  # ... 20 of them ...
@@ -300,7 +470,7 @@ In our gem file list is a single page containing 20 (by default, value may chang
300
470
  # => #<Uploadcare::Api::File ....
301
471
  ```
302
472
 
303
- And don't forget that you can navigate throught pages:
473
+ Here's how we handle navigating through pages:
304
474
 
305
475
  ```ruby
306
476
  @list = @api.files_list 3
@@ -314,9 +484,8 @@ And don't forget that you can navigate throught pages:
314
484
  @list.go_to 5
315
485
  # => #<Uploadcare::Api::FileList page=5 ....
316
486
 
317
-
318
-
319
- # there is also methods described in API docs avaliable for you:
487
+ # of course, you can go with any of the methods
488
+ # described in our API docs
320
489
  # total pages
321
490
  @list.pages
322
491
  # => 16
@@ -329,16 +498,16 @@ And don't forget that you can navigate throught pages:
329
498
  @list.per_page
330
499
  # => 20
331
500
 
332
- # total files in project
501
+ # total files in a project
333
502
  @list.total
334
503
  # => 308
335
504
  ```
336
505
 
337
- ## Project
338
- Project provides basic information about the connecting project.
339
- Project object is basicly openstruct so every method described in
340
- [API docs](https://uploadcare.com/documentation/rest/#project)
341
- accessible to you:
506
+ ### `Project` object
507
+
508
+ `Project` provides basic info about the connected Uploadcare project.
509
+ That object is also an OpenStruct, so every methods out of
510
+ [these](https://uploadcare.com/documentation/rest/#project) will work.
342
511
 
343
512
  ```ruby
344
513
  project = @api.project
@@ -349,56 +518,42 @@ project.name
349
518
 
350
519
  p.collaborators
351
520
  # => []
352
- # more often it should look like
521
+ # while that one was empty, it usually goes like this:
353
522
  # [{"email": collaborator@gmail.com, "name": "Collaborator"}, {"email": collaborator@gmail.com, "name": "Collaborator"}]
354
523
  ```
355
524
 
525
+ ### Raw API
356
526
 
357
- ## Groups of files
358
- Groups of files - https://uploadcare.com/documentation/rest/#group.
359
- Stores files as group by the single UUID.
360
- Note that UUID has a `~#{files_count}` part at the end and it is required by API to work properly.
527
+ Raw API is a simple interface allowing you to make
528
+ custom requests to Uploadcare REST API.
529
+ It's mainly used when you want a low-level control
530
+ over your app.
361
531
 
362
532
  ```ruby
363
- # group can be created eather by array of Uploadcare Files:
364
- @files_ary = [@file, @file2]
365
- @files = @api.upload @files_ary
366
- @group = @api.create_group @files
367
- # => #<Uploadcare::Api::Group uuid="0d192d66-c7a6-4465-b2cd-46716c5e3df3~2", files_count=2 ...
533
+ # here's how you make any requests
534
+ @api.request :get, "/files/", {page: 2}
368
535
 
369
- # or by array of strings containing UUIDs
370
- @uuids_ary = ["c969be02-9925-4a7e-aa6d-b0730368791c", "c969be02-9925-4a7e-aa6d-b0730368791c"]
371
- @group = @api.create_group @uuids_ary
372
- # => #<Uploadcare::Api::Group uuid="0d192d66-c7a6-4465-b2cd-46716c5e3df3~2", files_count=2 ...
536
+ # and there also are shortcuts for methods
537
+ @api.get '/files', {page: 2}
373
538
 
374
- # you can also create group object just by passing group UUID
375
- @group_uloaded = @api.group "#{uuid}"
376
- ```
539
+ @api.post ...
377
540
 
378
- As with files, group created by passing just the UUID is not loaded by default - you need to load data manually, as it requires separate HTTP GET request.
379
- New groups created by :create_group method is loaded by default.
541
+ @api.put ...
380
542
 
381
- ```ruby
382
- @group = @api.group "#{uuid}"
543
+ @api.delete ...
383
544
 
384
- @group.is_loaded?
385
- # => false
545
+ ```
386
546
 
387
- @group.load_data
388
- # => #<Uploadcare::Api::Group uuid="0d192d66-c7a6-4465-b2cd-46716c5e3df3~2", files_count=2 ...
547
+ All of the raw API methods return a parsed JSON response
548
+ or raise an error (handling those is done on your side in the case).
389
549
 
390
- # loaded group has methods described by API docs and more importantly an array of files
391
- # this files are loaded by default.
392
- @group.files
393
- # => [#<Uploadcare::Api::File uuid="24626d2f-3f23-4464-b190-37115ce7742a" ...>,
394
- # ... #{files_count} of them ...
395
- # #<Uploadcare::Api::File uuid="7bb9efa4-05c0-4f36-b0ef-11a4221867f6" ...>]
396
- ```
550
+ ### Error handling
397
551
 
398
- ## Errors handling
399
- From version 1.0.2 we have a custom exceptions which will raise when Uploadcare service return something with 4xx or 5xx HTTP status.
552
+ Starting from the version 1.0.2, we've got have custom exceptions
553
+ that will be raised in case the Uploadcare service returns
554
+ something with 4xx or 5xx HTTP status.
400
555
 
401
- List of custom errors:
556
+ Check out the list of custom errors:
402
557
 
403
558
  ```ruby
404
559
  400 => Uploadcare::Error::RequestError::BadRequest,
@@ -415,7 +570,8 @@ List of custom errors:
415
570
  504 => Uploadcare::Error::ServerError::GatewayTimeout
416
571
  ```
417
572
 
418
- so now you could escape particular error (in that case 404: Not Found error):
573
+ That's how you handle a particular error
574
+ (in this case, a “404: Not Found” error):
419
575
 
420
576
  ```ruby
421
577
  begin
@@ -425,7 +581,7 @@ rescue Uploadcare::Error::RequestError::NotFound => e
425
581
  end
426
582
  ```
427
583
 
428
- ... any request error (covers all 4xx status codes):
584
+ Handling any request error (covers all 4xx status codes):
429
585
 
430
586
  ```ruby
431
587
  begin
@@ -435,7 +591,7 @@ rescue Uploadcare::Error::RequestError => e
435
591
  end
436
592
  ```
437
593
 
438
- ...and actually any Uploadcare service errors:
594
+ Handling any Uploadcare service error:
439
595
 
440
596
  ```ruby
441
597
  begin
@@ -445,19 +601,37 @@ rescue Uploadcare::Error => e
445
601
  end
446
602
  ```
447
603
 
448
- Please note what almost all actions depends on Uploadcare servers and it will be wise of you to expect that servers will return error code (at least some times).
604
+ Since many of the above listed things depend on Uploadcare servers,
605
+ errors might occasionally occur. Be prepared to handle those.
449
606
 
450
607
  ## Testing
451
608
 
452
- Run `bundle exec rspec`.
609
+ For testing purposes, run `bundle exec rspec`.
453
610
 
454
- To run tests with your own keys, make a `spec/config.yml` file like this:
611
+ Please note, if you're willing to run tests using your own keys,
612
+ make a `spec/config.yml` file containing the following:
455
613
 
456
614
  ```yaml
457
615
  public_key: 'PUBLIC KEY'
458
616
  private_key: 'PRIVATE KEY'
459
617
  ```
460
618
 
461
- ## Contributing
619
+ ## Contributors
620
+
621
+ This is open source so fork, hack, request a pull — get a discount.
622
+
623
+ - [@romanonthego](https://github.com/romanonthego)
624
+ - [@vizvamitra](https://github.com/vizvamitra)
625
+ - [@dmitry-mukhin](https://github.com/dmitry-mukhin)
626
+ - [@zenati](https://github.com/zenati)
627
+ - [@renius](https://github.com/renius)
628
+
629
+ ## Security issues
630
+
631
+ If you think you ran into something in Uploadcare libraries
632
+ which might have security implications, please hit us up at
633
+ [bugbounty@uploadcare.com](mailto:bugbounty@uploadcare.com)
634
+ or Hackerone.
462
635
 
463
- This is open source, fork, hack, request a pull, receive a discount)
636
+ We'll contact you personally in a short time to fix an issue
637
+ through co-op and prior to any public disclosure.