dropbox-api 0.4.0 → 0.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG +8 -0
- data/Gemfile +2 -8
- data/LICENSE +201 -22
- data/README.markdown +47 -12
- data/dropbox-api.gemspec +17 -7
- data/lib/dropbox-api/client/files.rb +40 -3
- data/lib/dropbox-api/client.rb +8 -4
- data/lib/dropbox-api/connection/requests.rb +31 -9
- data/lib/dropbox-api/objects/dir.rb +9 -0
- data/lib/dropbox-api/objects/file.rb +5 -10
- data/lib/dropbox-api/objects/fileops.rb +5 -0
- data/lib/dropbox-api/tasks.rb +2 -2
- data/lib/dropbox-api/util/error.rb +4 -0
- data/lib/dropbox-api/version.rb +1 -1
- data/spec/lib/dropbox-api/client_spec.rb +60 -2
- data/spec/lib/dropbox-api/connection_spec.rb +54 -17
- data/spec/lib/dropbox-api/dir_spec.rb +36 -21
- data/spec/lib/dropbox-api/file_spec.rb +6 -6
- data/spec/lib/dropbox-api/oauth_spec.rb +1 -1
- metadata +82 -26
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: '08fbed3e2d04b975a565dac78c8e2d6fe130fcba5a37a3910a08df084870f945'
|
|
4
|
+
data.tar.gz: b33ac10dc712af96339d455287b084a5ca848455fb80091940b002fe1183327c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bdb0c3bc9b91009d4a556370ff23155deea83a8c9b84dc03c882f112bd611a0090d7643fb752bdee5205bb885aeda541fc51fd3ddd3bb3286028ab64d97f5a21
|
|
7
|
+
data.tar.gz: 75f7415ce3f893cf92d676c246eaafe1919f94b5340ffd8a17b67c53708901801859ea8ce79adc2c5c171b4767487b16858e292480931442aa91dcaa9eac6fa4
|
data/CHANGELOG
ADDED
data/Gemfile
CHANGED
data/LICENSE
CHANGED
|
@@ -1,22 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2020 Zendesk
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/README.markdown
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Dropbox::API - Dropbox Ruby API client
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
-
A Ruby client for the
|
|
4
|
+
A Ruby client for the Dropbox REST API.
|
|
5
5
|
|
|
6
6
|
Goal:
|
|
7
7
|
|
|
8
|
-
To deliver a more Rubyesque experience when using the
|
|
8
|
+
To deliver a more Rubyesque experience when using the Dropbox API.
|
|
9
9
|
|
|
10
10
|
Current state:
|
|
11
11
|
|
|
@@ -14,11 +14,11 @@ First release, whole API covered.
|
|
|
14
14
|
Important!!!
|
|
15
15
|
------------
|
|
16
16
|
|
|
17
|
-
From version 0.2.0, Dropbox::API::File#delete and Dropbox::API::Dir#delete *are gone*!!
|
|
17
|
+
From version 0.2.0, `Dropbox::API::File#delete` and `Dropbox::API::Dir#delete` *are gone*!!
|
|
18
18
|
|
|
19
19
|
The reason is that it's based on Hashie::Mash and was screwing Hash#delete.
|
|
20
20
|
|
|
21
|
-
It is replaced with Dropbox::API::File#destroy and Dropbox::API::Dir#destroy
|
|
21
|
+
It is replaced with `Dropbox::API::File#destroy` and `Dropbox::API::Dir#destroy`.
|
|
22
22
|
|
|
23
23
|
Installation
|
|
24
24
|
------------
|
|
@@ -43,9 +43,10 @@ In order to use this client, you need to have an app created on https://www.drop
|
|
|
43
43
|
Once you have it, put this configuration somewhere in your code, before you start working with the client.
|
|
44
44
|
|
|
45
45
|
```ruby
|
|
46
|
-
Dropbox::API::Config.app_key =
|
|
46
|
+
Dropbox::API::Config.app_key = YOUR_APP_KEY
|
|
47
47
|
Dropbox::API::Config.app_secret = YOUR_APP_SECRET
|
|
48
|
-
Dropbox::API::Config.mode = "sandbox" # if you have a single-directory app
|
|
48
|
+
Dropbox::API::Config.mode = "sandbox" # if you have a single-directory app
|
|
49
|
+
# Dropbox::API::Config.mode = "dropbox" # if your app has access to the whole dropbox
|
|
49
50
|
```
|
|
50
51
|
|
|
51
52
|
Dropbox::API::Client
|
|
@@ -54,6 +55,9 @@ Dropbox::API::Client
|
|
|
54
55
|
The client is the base for all communication with the API and wraps around almost all calls
|
|
55
56
|
available in the API.
|
|
56
57
|
|
|
58
|
+
Web-based Authorization
|
|
59
|
+
-----------------------
|
|
60
|
+
|
|
57
61
|
In order to create a Dropbox::API::Client object, you need to have the configuration set up for OAuth.
|
|
58
62
|
Second thing you need is to have the user authorize your app using OAuth. Here's a short intro
|
|
59
63
|
on how to do this:
|
|
@@ -66,9 +70,11 @@ session[:token] = request_token.token
|
|
|
66
70
|
session[:token_secret] = request_token.secret
|
|
67
71
|
request_token.authorize_url(:oauth_callback => 'http://yoursite.com/callback')
|
|
68
72
|
# Here the user goes to Dropbox, authorizes the app and is redirected
|
|
73
|
+
# This would be typically run in a Rails controller
|
|
69
74
|
hash = { oauth_token: session[:token], oauth_token_secret: session[:token_secret]}
|
|
70
75
|
request_token = OAuth::RequestToken.from_hash(consumer, hash)
|
|
71
|
-
|
|
76
|
+
oauth_verifier = params[:oauth_verifier]
|
|
77
|
+
result = request_token.get_access_token(:oauth_verifier => oauth_verifier)
|
|
72
78
|
```
|
|
73
79
|
|
|
74
80
|
Now that you have the oauth token and secret, you can create a new instance of the Dropbox::API::Client, like this:
|
|
@@ -85,19 +91,20 @@ Dropbox::API supplies you with a helper rake which will authorize a single clien
|
|
|
85
91
|
In order to have this rake available, put this on your Rakefile:
|
|
86
92
|
|
|
87
93
|
```ruby
|
|
94
|
+
require "dropbox-api"
|
|
88
95
|
require "dropbox-api/tasks"
|
|
89
96
|
Dropbox::API::Tasks.install
|
|
90
97
|
```
|
|
91
98
|
|
|
92
99
|
You will notice that you have a new rake task - dropbox:authorize
|
|
93
100
|
|
|
94
|
-
When you call this Rake task, it will ask you to provide the
|
|
101
|
+
When you call this Rake task, it will ask you to provide the app key and app secret. Afterwards it will present you with an authorize url on Dropbox.
|
|
95
102
|
|
|
96
103
|
Simply go to that url, authorize the app, then press enter in the console.
|
|
97
104
|
|
|
98
105
|
The rake task will output valid ruby code which you can use to create a client.
|
|
99
106
|
|
|
100
|
-
What differs this from the
|
|
107
|
+
What differs this from the Dropbox Ruby SDK?
|
|
101
108
|
--------------------------------------------
|
|
102
109
|
|
|
103
110
|
A few things:
|
|
@@ -166,6 +173,16 @@ When provided a path, returns a single file or directory
|
|
|
166
173
|
client.find 'file.txt' # => #<Dropbox::API::File>
|
|
167
174
|
```
|
|
168
175
|
|
|
176
|
+
### Dropbox::API::Client#destroy
|
|
177
|
+
|
|
178
|
+
Removes the file specified by path
|
|
179
|
+
|
|
180
|
+
Returns a Dropbox::API::File object of the deleted file
|
|
181
|
+
|
|
182
|
+
```ruby
|
|
183
|
+
client.destroy 'file.txt' # => #<Dropbox::API::File>
|
|
184
|
+
```
|
|
185
|
+
|
|
169
186
|
### Dropbox::API::Client#ls
|
|
170
187
|
|
|
171
188
|
When provided a path, returns a list of files or directories within that path
|
|
@@ -198,6 +215,14 @@ Stores a file with a provided body under a provided name and returns a Dropbox::
|
|
|
198
215
|
client.upload 'file.txt', 'file body' # => #<Dropbox::API::File>
|
|
199
216
|
```
|
|
200
217
|
|
|
218
|
+
### Dropbox::API::Client#chunked_upload
|
|
219
|
+
|
|
220
|
+
Stores a file from a File object under a provided name and returns a Dropbox::API::File object. It should be used for larger files.
|
|
221
|
+
|
|
222
|
+
```ruby
|
|
223
|
+
client.chunked_upload 'file.txt', File.open('file.txt') # => #<Dropbox::API::File>
|
|
224
|
+
```
|
|
225
|
+
|
|
201
226
|
### Dropbox::API::Client#download
|
|
202
227
|
|
|
203
228
|
Downloads a file with a provided name and returns it's content
|
|
@@ -240,6 +265,15 @@ delta.cursor # => 'abc123'
|
|
|
240
265
|
delta.entries # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
|
|
241
266
|
```
|
|
242
267
|
|
|
268
|
+
Optionally, you can set additional parameters, e.g. **path_prefix**. You can find all available parameters in the [Dropbox API documentation](https://www.dropbox.com/developers/core/docs#delta).
|
|
269
|
+
|
|
270
|
+
```ruby
|
|
271
|
+
delta = client.delta 'abc123', path_prefix: '/Path/To/My/Folder'
|
|
272
|
+
delta.cursor # => 'abc123'
|
|
273
|
+
delta.entries # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
|
|
243
277
|
Dropbox::API::File and Dropbox::API::Dir methods
|
|
244
278
|
----------------------------
|
|
245
279
|
|
|
@@ -329,7 +363,8 @@ In order to run tests, you need to have an application created and authorized. P
|
|
|
329
363
|
|
|
330
364
|
Check out spec/connection.sample.yml for an example.
|
|
331
365
|
|
|
332
|
-
Copyright
|
|
333
|
-
|
|
366
|
+
## Copyright and license
|
|
367
|
+
|
|
368
|
+
Copyright 2020 Zendesk
|
|
334
369
|
|
|
335
|
-
|
|
370
|
+
Licensed under the [Apache License, Version 2.0](LICENSE)
|
data/dropbox-api.gemspec
CHANGED
|
@@ -5,17 +5,27 @@ require "dropbox-api/version"
|
|
|
5
5
|
Gem::Specification.new do |s|
|
|
6
6
|
s.name = "dropbox-api"
|
|
7
7
|
s.version = Dropbox::API::VERSION
|
|
8
|
-
s.authors = ["
|
|
9
|
-
s.email = ["
|
|
8
|
+
s.authors = ["Zendesk"]
|
|
9
|
+
s.email = ["opensource@zendesk.com"]
|
|
10
10
|
s.homepage = "http://github.com/futuresimple/dropbox-api"
|
|
11
|
-
s.summary = "A Ruby client for the
|
|
12
|
-
s.description = "To deliver a more Rubyesque experience when using the
|
|
11
|
+
s.summary = "A Ruby client for the Dropbox REST API."
|
|
12
|
+
s.description = "To deliver a more Rubyesque experience when using the Dropbox API."
|
|
13
|
+
s.license = 'Apache License Version 2.0'
|
|
13
14
|
|
|
14
15
|
s.rubyforge_project = "dropbox-api"
|
|
15
16
|
|
|
16
|
-
s.add_dependency 'multi_json'
|
|
17
|
-
s.add_dependency 'oauth'
|
|
18
|
-
s.add_dependency 'hashie'
|
|
17
|
+
s.add_dependency 'multi_json', '~> 1.10'
|
|
18
|
+
s.add_dependency 'oauth', '~> 0.4.7'
|
|
19
|
+
s.add_dependency 'hashie', '~> 3.4.0'
|
|
20
|
+
|
|
21
|
+
s.add_development_dependency 'rspec','2.14.1'
|
|
22
|
+
s.add_development_dependency 'rake', '10.1.0'
|
|
23
|
+
s.add_development_dependency 'simplecov', '~> 0.8.2'
|
|
24
|
+
s.add_development_dependency 'yajl-ruby', '~> 1.2.0'
|
|
25
|
+
|
|
26
|
+
if RUBY_VERSION < "1.9"
|
|
27
|
+
s.add_development_dependency 'ruby-debug19'
|
|
28
|
+
end
|
|
19
29
|
|
|
20
30
|
s.files = `git ls-files`.split("\n")
|
|
21
31
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
@@ -24,10 +24,47 @@ module Dropbox
|
|
|
24
24
|
Dropbox::API::File.init(response, self)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
def chunked_upload(path, file, options = {})
|
|
28
|
+
root = options.delete(:root) || Dropbox::API::Config.mode
|
|
29
|
+
path = Dropbox::API::Util.escape(path)
|
|
30
|
+
upload_url = '/chunked_upload'
|
|
31
|
+
commit_url = ['', "commit_chunked_upload", root, path].compact.join('/')
|
|
32
|
+
|
|
33
|
+
total_file_size = ::File.size(file)
|
|
34
|
+
chunk_size = options[:chunk_size] || 4*1024*1024 # default 4 MB chunk size
|
|
35
|
+
offset = options[:offset] || 0
|
|
36
|
+
upload_id = options[:upload_id]
|
|
37
|
+
|
|
38
|
+
while offset < total_file_size
|
|
39
|
+
data = file.read(chunk_size)
|
|
40
|
+
|
|
41
|
+
query = Dropbox::API::Util.query(options.merge(:offset => offset))
|
|
42
|
+
response = connection.put(:content, "#{upload_url}?#{query}", data, {
|
|
43
|
+
'Content-Type' => "application/octet-stream",
|
|
44
|
+
"Content-Length" => data.length.to_s
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
upload = Dropbox::API::Object.init(response, self)
|
|
48
|
+
options[:upload_id] ||= upload[:upload_id]
|
|
49
|
+
offset += upload[:offset].to_i - offset if upload[:offset] && upload[:offset].to_i > offset
|
|
50
|
+
yield offset, upload if block_given?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
query = Dropbox::API::Util.query({:upload_id => options[:upload_id]})
|
|
55
|
+
|
|
56
|
+
response = connection.post(:content, "#{commit_url}?#{query}", "", {
|
|
57
|
+
'Content-Type' => "application/octet-stream",
|
|
58
|
+
"Content-Length" => "0"
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
Dropbox::API::File.init(response, self)
|
|
62
|
+
end
|
|
63
|
+
|
|
27
64
|
def copy_from_copy_ref(copy_ref, to, options = {})
|
|
28
|
-
raw.copy({
|
|
29
|
-
:from_copy_ref => copy_ref,
|
|
30
|
-
:to_path => to
|
|
65
|
+
raw.copy({
|
|
66
|
+
:from_copy_ref => copy_ref,
|
|
67
|
+
:to_path => to
|
|
31
68
|
}.merge(options))
|
|
32
69
|
end
|
|
33
70
|
|
data/lib/dropbox-api/client.rb
CHANGED
|
@@ -18,8 +18,7 @@ module Dropbox
|
|
|
18
18
|
include Dropbox::API::Client::Files
|
|
19
19
|
|
|
20
20
|
def find(filename)
|
|
21
|
-
data = self.raw.metadata(:path => filename)
|
|
22
|
-
data.delete('contents')
|
|
21
|
+
data = self.raw.metadata(:path => filename, :list => false)
|
|
23
22
|
Dropbox::API::Object.convert(data, self)
|
|
24
23
|
end
|
|
25
24
|
|
|
@@ -38,16 +37,21 @@ module Dropbox
|
|
|
38
37
|
Dropbox::API::Dir.init(response, self)
|
|
39
38
|
end
|
|
40
39
|
|
|
40
|
+
def destroy(path, options = {})
|
|
41
|
+
response = raw.delete({ :path => path }.merge(options))
|
|
42
|
+
Dropbox::API::Object.convert(response, self)
|
|
43
|
+
end
|
|
44
|
+
|
|
41
45
|
def search(term, options = {})
|
|
42
46
|
options[:path] ||= ''
|
|
43
47
|
results = raw.search({ :query => term }.merge(options))
|
|
44
48
|
Dropbox::API::Object.convert(results, self)
|
|
45
49
|
end
|
|
46
50
|
|
|
47
|
-
def delta(cursor=nil)
|
|
51
|
+
def delta(cursor=nil, options={})
|
|
48
52
|
entries = []
|
|
49
53
|
has_more = true
|
|
50
|
-
params = cursor ?
|
|
54
|
+
params = cursor ? options.merge(:cursor => cursor) : options
|
|
51
55
|
while has_more
|
|
52
56
|
response = raw.delta(params)
|
|
53
57
|
params[:cursor] = response['cursor']
|
|
@@ -10,26 +10,48 @@ module Dropbox
|
|
|
10
10
|
raise Dropbox::API::Error::ConnectionFailed if !response
|
|
11
11
|
status = response.code.to_i
|
|
12
12
|
case status
|
|
13
|
+
when 400
|
|
14
|
+
parsed = MultiJson.decode(response.body)
|
|
15
|
+
raise Dropbox::API::Error::BadInput.new("400 - Bad input parameter - #{parsed['error']}")
|
|
13
16
|
when 401
|
|
14
|
-
raise Dropbox::API::Error::Unauthorized
|
|
17
|
+
raise Dropbox::API::Error::Unauthorized.new("401 - Bad or expired token")
|
|
15
18
|
when 403
|
|
16
19
|
parsed = MultiJson.decode(response.body)
|
|
17
|
-
raise Dropbox::API::Error::Forbidden.new(
|
|
20
|
+
raise Dropbox::API::Error::Forbidden.new('403 - Bad OAuth request')
|
|
18
21
|
when 404
|
|
19
|
-
raise Dropbox::API::Error::NotFound
|
|
20
|
-
when
|
|
22
|
+
raise Dropbox::API::Error::NotFound.new("404 - Not found")
|
|
23
|
+
when 405
|
|
24
|
+
parsed = MultiJson.decode(response.body)
|
|
25
|
+
raise Dropbox::API::Error::WrongMethod.new("405 - Request method not expected - #{parsed['error']}")
|
|
26
|
+
when 406
|
|
21
27
|
parsed = MultiJson.decode(response.body)
|
|
22
|
-
raise Dropbox::API::Error.new(parsed[
|
|
28
|
+
raise Dropbox::API::Error.new("#{status} - #{parsed['error']}")
|
|
29
|
+
when 429
|
|
30
|
+
raise Dropbox::API::Error::RateLimit.new('429 - Rate Limiting in affect')
|
|
23
31
|
when 300..399
|
|
24
|
-
raise Dropbox::API::Error::Redirect
|
|
25
|
-
when
|
|
26
|
-
|
|
32
|
+
raise Dropbox::API::Error::Redirect.new("#{status} - Redirect Error")
|
|
33
|
+
when 503
|
|
34
|
+
handle_503 response
|
|
35
|
+
when 507
|
|
36
|
+
raise Dropbox::API::Error::StorageQuota.new("507 - Dropbox storage quota exceeded.")
|
|
37
|
+
when 500..502, 504..506, 508..599
|
|
38
|
+
parsed = MultiJson.decode(response.body)
|
|
39
|
+
raise Dropbox::API::Error.new("#{status} - Server error. Check http://status.dropbox.com/")
|
|
27
40
|
else
|
|
28
41
|
options[:raw] ? response.body : MultiJson.decode(response.body)
|
|
29
42
|
end
|
|
30
43
|
end
|
|
31
44
|
|
|
32
|
-
|
|
45
|
+
def handle_503(response)
|
|
46
|
+
if response.is_a? Net::HTTPServiceUnavailable
|
|
47
|
+
raise Dropbox::API::Error.new("503 - #{response.message}")
|
|
48
|
+
else
|
|
49
|
+
parsed = MultiJson.decode(response.body)
|
|
50
|
+
header_parse = MultiJson.decode(response.headers)
|
|
51
|
+
error_message = "#{parsed["error"]}. Retry after: #{header_parse['Retry-After']}"
|
|
52
|
+
raise Dropbox::API::Error.new("503 - #{error_message}")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
33
55
|
|
|
34
56
|
def get_raw(endpoint, path, data = {}, headers = {})
|
|
35
57
|
query = Dropbox::API::Util.query(data)
|
|
@@ -14,6 +14,15 @@ module Dropbox
|
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
def direct_url(options = {})
|
|
18
|
+
response = client.raw.shares({ :path => self.path, :short_url => false }.merge(options))
|
|
19
|
+
Dropbox::API::Object.init(response, client)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def hash
|
|
23
|
+
self[:hash]
|
|
24
|
+
end
|
|
25
|
+
|
|
17
26
|
end
|
|
18
27
|
|
|
19
28
|
end
|
|
@@ -15,16 +15,6 @@ module Dropbox
|
|
|
15
15
|
self.update response
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def share_url(options = {})
|
|
19
|
-
response = client.raw.shares({ :path => self.path }.merge(options))
|
|
20
|
-
Dropbox::API::Object.init(response, client)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def direct_url(options = {})
|
|
24
|
-
response = client.raw.media({ :path => self.path }.merge(options))
|
|
25
|
-
Dropbox::API::Object.init(response, client)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
18
|
def thumbnail(options = {})
|
|
29
19
|
client.raw.thumbnails({ :path => self.path }.merge(options))
|
|
30
20
|
end
|
|
@@ -38,6 +28,11 @@ module Dropbox
|
|
|
38
28
|
client.download(self.path)
|
|
39
29
|
end
|
|
40
30
|
|
|
31
|
+
def direct_url(options = {})
|
|
32
|
+
response = client.raw.media({ :path => self.path }.merge(options))
|
|
33
|
+
Dropbox::API::Object.init(response, client)
|
|
34
|
+
end
|
|
35
|
+
|
|
41
36
|
end
|
|
42
37
|
|
|
43
38
|
end
|
data/lib/dropbox-api/tasks.rb
CHANGED
|
@@ -12,9 +12,9 @@ module Dropbox
|
|
|
12
12
|
task :authorize do
|
|
13
13
|
require "dropbox-api"
|
|
14
14
|
require "cgi"
|
|
15
|
-
print "Enter
|
|
15
|
+
print "Enter dropbox app key: "
|
|
16
16
|
consumer_key = $stdin.gets.chomp
|
|
17
|
-
print "Enter
|
|
17
|
+
print "Enter dropbox app secret: "
|
|
18
18
|
consumer_secret = $stdin.gets.chomp
|
|
19
19
|
|
|
20
20
|
Dropbox::API::Config.app_key = consumer_key
|
|
@@ -3,12 +3,16 @@ module Dropbox
|
|
|
3
3
|
|
|
4
4
|
class Error < StandardError
|
|
5
5
|
|
|
6
|
+
class BadInput < Error; end
|
|
6
7
|
class ConnectionFailed < Error; end
|
|
7
8
|
class Config < Error; end
|
|
8
9
|
class Unauthorized < Error; end
|
|
9
10
|
class Forbidden < Error; end
|
|
10
11
|
class NotFound < Error; end
|
|
11
12
|
class Redirect < Error; end
|
|
13
|
+
class WrongMethod < Error; end
|
|
14
|
+
class RateLimit < Error; end
|
|
15
|
+
class StorageQuota < Error; end
|
|
12
16
|
|
|
13
17
|
end
|
|
14
18
|
|
data/lib/dropbox-api/version.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require "spec_helper"
|
|
3
|
+
require "tempfile"
|
|
3
4
|
|
|
4
5
|
describe Dropbox::API::Client do
|
|
5
6
|
|
|
@@ -114,6 +115,41 @@ describe Dropbox::API::Client do
|
|
|
114
115
|
end
|
|
115
116
|
end
|
|
116
117
|
|
|
118
|
+
describe "#chunked_upload" do
|
|
119
|
+
|
|
120
|
+
before do
|
|
121
|
+
@size = 5*1024*1024 # 5MB, to test the 4MB chunk size
|
|
122
|
+
@file = File.open("/tmp/dropbox-api-test", "w") {|f| f.write "a"*@size}
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "puts a 5MB file in dropbox" do
|
|
126
|
+
filename = "#{Dropbox::Spec.test_dir}/test-#{Dropbox::Spec.namespace}.txt"
|
|
127
|
+
response = @client.chunked_upload filename, File.open("/tmp/dropbox-api-test")
|
|
128
|
+
response.path.should == filename
|
|
129
|
+
response.bytes.should == @size
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
after do
|
|
133
|
+
FileUtils.rm "/tmp/dropbox-api-test"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
describe "#destroy" do
|
|
139
|
+
|
|
140
|
+
before do
|
|
141
|
+
@client = Dropbox::Spec.instance
|
|
142
|
+
@filename = "#{Dropbox::Spec.test_dir}/spec-test-#{Time.now.to_i}.txt"
|
|
143
|
+
@file = @client.upload @filename, "spec file"
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it "destroys the file properly" do
|
|
147
|
+
file = @client.destroy(@filename)
|
|
148
|
+
file.is_deleted.should == true
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
end
|
|
152
|
+
|
|
117
153
|
describe "#search" do
|
|
118
154
|
|
|
119
155
|
let(:term) { "searchable-test-#{Dropbox::Spec.namespace}" }
|
|
@@ -143,10 +179,10 @@ describe Dropbox::API::Client do
|
|
|
143
179
|
it "copies a file from a copy_ref" do
|
|
144
180
|
filename = "test/searchable-test-#{Dropbox::Spec.namespace}.txt"
|
|
145
181
|
@client.upload filename, "Some file"
|
|
146
|
-
response = @client.search "searchable-test-#{Dropbox::Spec.namespace}", :path => 'test'
|
|
182
|
+
response = @client.search "searchable-test-#{Dropbox::Spec.namespace}", :path => 'test'
|
|
147
183
|
ref = response.first.copy_ref['copy_ref']
|
|
148
184
|
@client.copy_from_copy_ref ref, "#{filename}.copied"
|
|
149
|
-
response = @client.search "searchable-test-#{Dropbox::Spec.namespace}.txt.copied", :path => 'test'
|
|
185
|
+
response = @client.search "searchable-test-#{Dropbox::Spec.namespace}.txt.copied", :path => 'test'
|
|
150
186
|
response.size.should == 1
|
|
151
187
|
response.first.class.should == Dropbox::API::File
|
|
152
188
|
end
|
|
@@ -196,6 +232,28 @@ describe Dropbox::API::Client do
|
|
|
196
232
|
files.first.path.should == delete_filename
|
|
197
233
|
files.last.path.should == filename
|
|
198
234
|
end
|
|
235
|
+
|
|
236
|
+
context "with extra params" do
|
|
237
|
+
|
|
238
|
+
let(:response) do
|
|
239
|
+
{
|
|
240
|
+
'cursor' => nil,
|
|
241
|
+
'has_more' => false,
|
|
242
|
+
'entries' => []
|
|
243
|
+
}
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
let(:params) do
|
|
247
|
+
{ :path_prefix => 'my_path' }
|
|
248
|
+
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
it "passes them to raw delta" do
|
|
252
|
+
@client.raw.should_receive(:delta).with(params).and_return(response)
|
|
253
|
+
@client.delta nil, params
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
end
|
|
199
257
|
end
|
|
200
258
|
|
|
201
259
|
end
|
|
@@ -10,62 +10,99 @@ describe Dropbox::API::Connection do
|
|
|
10
10
|
describe "#request" do
|
|
11
11
|
|
|
12
12
|
it "returns a parsed response when the response is a 200" do
|
|
13
|
-
response =
|
|
13
|
+
response = double :code => 200, :body => '{ "a":1}'
|
|
14
14
|
response = @connection.request { response }
|
|
15
15
|
response.should be_an_instance_of(Hash)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it "raises a Dropbox::API::Error::Unauthorized when the response is a 401" do
|
|
19
|
-
response =
|
|
19
|
+
response = double :code => 401, :body => '{ "a":1}'
|
|
20
20
|
lambda do
|
|
21
21
|
@connection.request { response }
|
|
22
|
-
end.should raise_error(Dropbox::API::Error::Unauthorized)
|
|
22
|
+
end.should raise_error(Dropbox::API::Error::Unauthorized, '401 - Bad or expired token')
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it "raises a Dropbox::API::Error::Forbidden when the response is a 403" do
|
|
26
|
-
response =
|
|
26
|
+
response = double :code => 403, :body => '{ "a":1}'
|
|
27
27
|
lambda do
|
|
28
28
|
@connection.request { response }
|
|
29
|
-
end.should raise_error(Dropbox::API::Error::Forbidden)
|
|
29
|
+
end.should raise_error(Dropbox::API::Error::Forbidden, '403 - Bad OAuth request')
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
it "raises a Dropbox::API::Error::NotFound when the response is a 404" do
|
|
33
|
-
response =
|
|
33
|
+
response = double :code => 404, :body => '{ "a":1}'
|
|
34
34
|
lambda do
|
|
35
35
|
@connection.request { response }
|
|
36
|
-
end.should raise_error(Dropbox::API::Error::NotFound)
|
|
36
|
+
end.should raise_error(Dropbox::API::Error::NotFound, '404 - Not found')
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "raises a Dropbox::API::Error::WrongMethod when the response is a 405" do
|
|
40
|
+
response = double :code => 405, :body => '{ "error": "The requested method GET is not allowed for the URL /foo/." }'
|
|
41
|
+
lambda do
|
|
42
|
+
@connection.request { response }
|
|
43
|
+
end.should raise_error(Dropbox::API::Error::WrongMethod, '405 - Request method not expected - The requested method GET is not allowed for the URL /foo/.')
|
|
37
44
|
end
|
|
38
45
|
|
|
39
46
|
it "raises a Dropbox::API::Error when the response is a 3xx" do
|
|
40
|
-
response =
|
|
47
|
+
response = double :code => 301, :body => '{ "a":1}'
|
|
41
48
|
lambda do
|
|
42
49
|
@connection.request { response }
|
|
43
|
-
end.should raise_error(Dropbox::API::Error::Redirect)
|
|
50
|
+
end.should raise_error(Dropbox::API::Error::Redirect, '301 - Redirect Error')
|
|
44
51
|
end
|
|
45
52
|
|
|
46
53
|
it "raises a Dropbox::API::Error when the response is a 5xx" do
|
|
47
|
-
response =
|
|
54
|
+
response = double :code => 500, :body => '{ "a":1}'
|
|
48
55
|
lambda do
|
|
49
56
|
@connection.request { response }
|
|
50
|
-
end.should raise_error(Dropbox::API::Error)
|
|
57
|
+
end.should raise_error(Dropbox::API::Error, '500 - Server error. Check http://status.dropbox.com/')
|
|
51
58
|
end
|
|
52
59
|
|
|
53
60
|
it "raises a Dropbox::API::Error when the response is a 400" do
|
|
54
|
-
response =
|
|
61
|
+
response = double :code => 400, :body => '{ "error": "bad request foo" }'
|
|
62
|
+
lambda do
|
|
63
|
+
@connection.request { response }
|
|
64
|
+
end.should raise_error(Dropbox::API::Error::BadInput, '400 - Bad input parameter - bad request foo')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "raises a Dropbox::API::Error when the response is a 406" do
|
|
68
|
+
response = double :code => 406, :body => '{ "error": "bad request bar" }'
|
|
55
69
|
lambda do
|
|
56
70
|
@connection.request { response }
|
|
57
|
-
end.should raise_error(Dropbox::API::Error)
|
|
71
|
+
end.should raise_error(Dropbox::API::Error, '406 - bad request bar')
|
|
58
72
|
end
|
|
59
73
|
|
|
60
74
|
it "raises a Dropbox::API::Error when the response is a 406" do
|
|
61
|
-
response =
|
|
75
|
+
response = double :code => 429, :body => '{ "error": "rate limited" }'
|
|
62
76
|
lambda do
|
|
63
77
|
@connection.request { response }
|
|
64
|
-
end.should raise_error(Dropbox::API::Error)
|
|
78
|
+
end.should raise_error(Dropbox::API::Error::RateLimit, '429 - Rate Limiting in affect')
|
|
65
79
|
end
|
|
66
80
|
|
|
81
|
+
it "raises a Dropbox::API::Error when the response is a 503" do
|
|
82
|
+
response = double :code => 503, :body => '{ "error": "rate limited" }', :headers => '{ "Retry-After": "50" }'
|
|
83
|
+
lambda do
|
|
84
|
+
@connection.request { response }
|
|
85
|
+
end.should raise_error(Dropbox::API::Error, '503 - rate limited. Retry after: 50')
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "raises a Dropbox::API::Error when the response is a 503 Service Unavailable" do
|
|
89
|
+
message = 'we are down'
|
|
90
|
+
response = Net::HTTPServiceUnavailable.new('1.1', 503, message)
|
|
91
|
+
lambda do
|
|
92
|
+
@connection.request { response }
|
|
93
|
+
end.should raise_error(Dropbox::API::Error, "503 - #{message}")
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "raises a Dropbox::API::Error::StorageQuota when the response is a 507" do
|
|
97
|
+
response = double :code => 507, :body => '{ "error": "quote limit" }'
|
|
98
|
+
lambda do
|
|
99
|
+
@connection.request { response }
|
|
100
|
+
end.should raise_error(Dropbox::API::Error, '507 - Dropbox storage quota exceeded.')
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
|
|
67
104
|
it "returns the raw response if :raw => true is provided" do
|
|
68
|
-
response =
|
|
105
|
+
response = double :code => 200, :body => '{ "something": "more" }'
|
|
69
106
|
response = @connection.request(:raw => true) { response }
|
|
70
107
|
response.should == '{ "something": "more" }'
|
|
71
108
|
end
|
|
@@ -83,7 +120,7 @@ describe Dropbox::API::Connection do
|
|
|
83
120
|
describe "errors" do
|
|
84
121
|
|
|
85
122
|
it "recovers error with rescue statement modifier" do
|
|
86
|
-
expect { raise Dropbox::API::Error rescue nil }.to_not raise_error
|
|
123
|
+
expect { raise Dropbox::API::Error rescue nil }.to_not raise_error
|
|
87
124
|
end
|
|
88
125
|
|
|
89
126
|
it "recovers any kind of errors with the generic error" do
|
|
@@ -2,41 +2,56 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe Dropbox::API::Dir do
|
|
4
4
|
|
|
5
|
-
before do
|
|
6
|
-
@client = Dropbox::Spec.instance
|
|
7
|
-
@dirname = "#{Dropbox::Spec.test_dir}/spec-dir-test-#{Time.now.to_i}"
|
|
8
|
-
@dir = @client.mkdir @dirname
|
|
9
|
-
end
|
|
10
|
-
|
|
11
5
|
after do
|
|
12
6
|
# @dir.delete
|
|
13
7
|
end
|
|
14
8
|
|
|
15
|
-
describe "#
|
|
9
|
+
describe "#hash" do
|
|
10
|
+
|
|
11
|
+
let(:hash) { "dasdsaf32da" }
|
|
16
12
|
|
|
17
|
-
it "
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@dir.path.should == new_dirname
|
|
13
|
+
it "returns the hash from Dropbox" do
|
|
14
|
+
dir = Dropbox::API::Dir.new("hash" => hash)
|
|
15
|
+
dir.hash.should == hash
|
|
21
16
|
end
|
|
22
17
|
|
|
23
18
|
end
|
|
24
19
|
|
|
25
|
-
|
|
20
|
+
context "operations" do
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@dir.
|
|
30
|
-
@dir.
|
|
22
|
+
before do
|
|
23
|
+
@client = Dropbox::Spec.instance
|
|
24
|
+
@dirname = "#{Dropbox::Spec.test_dir}/spec-dir-test-#{Time.now.to_i}"
|
|
25
|
+
@dir = @client.mkdir @dirname
|
|
31
26
|
end
|
|
32
27
|
|
|
33
|
-
|
|
28
|
+
describe "#copy" do
|
|
29
|
+
|
|
30
|
+
it "copies the dir properly" do
|
|
31
|
+
new_dirname = @dirname + "-copied"
|
|
32
|
+
@dir.copy new_dirname
|
|
33
|
+
@dir.path.should == new_dirname
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "#move" do
|
|
39
|
+
|
|
40
|
+
it "moves the dir properly" do
|
|
41
|
+
new_dirname = @dirname + "-copied"
|
|
42
|
+
@dir.move new_dirname
|
|
43
|
+
@dir.path.should == new_dirname
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe "#destroy" do
|
|
34
49
|
|
|
35
|
-
|
|
50
|
+
it "destroys the dir properly" do
|
|
51
|
+
@dir.destroy
|
|
52
|
+
@dir.is_deleted.should == true
|
|
53
|
+
end
|
|
36
54
|
|
|
37
|
-
it "destroys the dir properly" do
|
|
38
|
-
@dir.destroy
|
|
39
|
-
@dir.is_deleted.should == true
|
|
40
55
|
end
|
|
41
56
|
|
|
42
57
|
end
|
|
@@ -21,7 +21,7 @@ describe Dropbox::API::File do
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
end
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
describe "#move" do
|
|
26
26
|
|
|
27
27
|
it "moves the file properly" do
|
|
@@ -85,22 +85,22 @@ describe Dropbox::API::File do
|
|
|
85
85
|
|
|
86
86
|
result = @file.share_url
|
|
87
87
|
result.should be_an_instance_of(Dropbox::API::Object)
|
|
88
|
-
result.keys.sort.should == ['expires', 'url']
|
|
88
|
+
result.keys.sort.should == ['expires', 'url', 'visibility']
|
|
89
89
|
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
describe "#copy_ref" do
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
it "returns a copy_ref object" do
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
result = @file.copy_ref
|
|
99
99
|
result.should be_an_instance_of(Dropbox::API::Object)
|
|
100
100
|
result.keys.sort.should == ['copy_ref', 'expires']
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
end
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
describe "#direct_url" do
|
|
@@ -5,7 +5,7 @@ describe Dropbox::API::OAuth do
|
|
|
5
5
|
describe ".consumer" do
|
|
6
6
|
|
|
7
7
|
it "raises an error if config options are not provided" do
|
|
8
|
-
Dropbox::API::Config.stub
|
|
8
|
+
Dropbox::API::Config.stub(:app_key).and_return(nil)
|
|
9
9
|
lambda {
|
|
10
10
|
Dropbox::API::OAuth.consumer :main
|
|
11
11
|
}.should raise_error(Dropbox::API::Error::Config)
|
metadata
CHANGED
|
@@ -1,66 +1,123 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dropbox-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
7
|
+
- Zendesk
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-04-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: multi_json
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- -
|
|
17
|
+
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '1.10'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- -
|
|
24
|
+
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '1.10'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: oauth
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- -
|
|
31
|
+
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
33
|
+
version: 0.4.7
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- -
|
|
38
|
+
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
40
|
+
version: 0.4.7
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: hashie
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- -
|
|
45
|
+
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version:
|
|
47
|
+
version: 3.4.0
|
|
48
48
|
type: :runtime
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- -
|
|
52
|
+
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version:
|
|
55
|
-
|
|
54
|
+
version: 3.4.0
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - '='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 2.14.1
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - '='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 2.14.1
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - '='
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 10.1.0
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - '='
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 10.1.0
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: simplecov
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 0.8.2
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: 0.8.2
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: yajl-ruby
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: 1.2.0
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: 1.2.0
|
|
111
|
+
description: To deliver a more Rubyesque experience when using the Dropbox API.
|
|
56
112
|
email:
|
|
57
|
-
-
|
|
113
|
+
- opensource@zendesk.com
|
|
58
114
|
executables: []
|
|
59
115
|
extensions: []
|
|
60
116
|
extra_rdoc_files: []
|
|
61
117
|
files:
|
|
62
|
-
- .gitignore
|
|
63
|
-
- .rspec
|
|
118
|
+
- ".gitignore"
|
|
119
|
+
- ".rspec"
|
|
120
|
+
- CHANGELOG
|
|
64
121
|
- Gemfile
|
|
65
122
|
- LICENSE
|
|
66
123
|
- README.markdown
|
|
@@ -95,7 +152,8 @@ files:
|
|
|
95
152
|
- spec/support/config.rb
|
|
96
153
|
- spec/support/jpeg.rb
|
|
97
154
|
homepage: http://github.com/futuresimple/dropbox-api
|
|
98
|
-
licenses:
|
|
155
|
+
licenses:
|
|
156
|
+
- Apache License Version 2.0
|
|
99
157
|
metadata: {}
|
|
100
158
|
post_install_message:
|
|
101
159
|
rdoc_options: []
|
|
@@ -103,20 +161,19 @@ require_paths:
|
|
|
103
161
|
- lib
|
|
104
162
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
163
|
requirements:
|
|
106
|
-
- -
|
|
164
|
+
- - ">="
|
|
107
165
|
- !ruby/object:Gem::Version
|
|
108
166
|
version: '0'
|
|
109
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
168
|
requirements:
|
|
111
|
-
- -
|
|
169
|
+
- - ">="
|
|
112
170
|
- !ruby/object:Gem::Version
|
|
113
171
|
version: '0'
|
|
114
172
|
requirements: []
|
|
115
|
-
|
|
116
|
-
rubygems_version: 2.0.5
|
|
173
|
+
rubygems_version: 3.1.2
|
|
117
174
|
signing_key:
|
|
118
175
|
specification_version: 4
|
|
119
|
-
summary: A Ruby client for the
|
|
176
|
+
summary: A Ruby client for the Dropbox REST API.
|
|
120
177
|
test_files:
|
|
121
178
|
- spec/connection.sample.yml
|
|
122
179
|
- spec/fixtures/dropbox.jpg
|
|
@@ -129,4 +186,3 @@ test_files:
|
|
|
129
186
|
- spec/spec_helper.rb
|
|
130
187
|
- spec/support/config.rb
|
|
131
188
|
- spec/support/jpeg.rb
|
|
132
|
-
has_rdoc:
|