dropbox-sdk-v2 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/lib/dropbox/client.rb +107 -12
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a2322ad19040f1f574b4417ce7ca0134849ebe7
4
- data.tar.gz: 636f09861b9ea96ab8b423da8b3daa257fd159b2
3
+ metadata.gz: 3012cc4be1ed874d4eb5584f39564e7812d93803
4
+ data.tar.gz: 7d0d205741968270914b5e4a719fa18dc7488edc
5
5
  SHA512:
6
- metadata.gz: fc3d5b2ba162d750c1c6cbb462f788d8326b3092637d168754cef442223fdeff6743e582ddf5253a027425a3d7fe17536748a75ca3cfb1567515cb7c7c9b0d5b
7
- data.tar.gz: 2daad67a615c21ed801e5638ef164b806eb9c4fc597d6e6df1277c1ba1f8b77fe7bd31ae28a2028da54f186286dd9125ecb8242bccec915310128b5400a1c571
6
+ metadata.gz: d21f8305e1a3b66d2d81219201df04bcecee3355067d92f83204b936371431cec2c718ec4db124048e4b39d6e79dff248212445785575440e014d5374cbb412d
7
+ data.tar.gz: 52723a3ae802a78155e8af7db3f37c940f70d6a356fbe2e648f357ad95684172e99b34a1271ab77b052d1d4be1da3a2cb9473cabed156fa3d1264e764dc7491e
data/README.md CHANGED
@@ -27,6 +27,8 @@ gem 'dropbox-sdk-v2'
27
27
 
28
28
  ## Usage
29
29
 
30
+ Also see the [full method documentation](http://www.rubydoc.info/gems/dropbox-sdk-v2/Dropbox/Client).
31
+
30
32
  Set up a client:
31
33
  ```ruby
32
34
  require 'dropbox'
@@ -3,7 +3,11 @@ require 'json'
3
3
  require 'time'
4
4
 
5
5
  module Dropbox
6
+ # Client contains all the methods that map to the Dropbox API endpoints.
6
7
  class Client
8
+ # Initialize a new client.
9
+ #
10
+ # @param [String] access_token
7
11
  def initialize(access_token)
8
12
  unless access_token =~ /^[a-z0-9_-]{64}$/i
9
13
  raise ClientError.invalid_access_token
@@ -12,95 +16,173 @@ module Dropbox
12
16
  @access_token = access_token
13
17
  end
14
18
 
15
- def copy(from, to)
16
- resp = request('/files/copy', from_path: from, to_path: to)
19
+ # Copy a file or folder to a different location in the user's Dropbox.
20
+ #
21
+ # @param [String] from_path
22
+ # @param [String] to_path
23
+ # @return [Dropbox::Metadata]
24
+ def copy(from_path, to_path)
25
+ resp = request('/files/copy', from_path: from_path, to_path: to_path)
17
26
  parse_tagged_response(resp)
18
27
  end
19
28
 
29
+ # Create a folder at a given path.
30
+ #
31
+ # @param [String] path
32
+ # @return [Dropbox::FolderMetadata]
20
33
  def create_folder(path)
21
34
  resp = request('/files/create_folder', path: path)
22
35
  parse_tagged_response(resp, 'folder')
23
36
  end
24
37
 
38
+ # Delete the file or folder at a given path.
39
+ #
40
+ # @param [String] path
41
+ # @return [Dropbox::Metadata]
25
42
  def delete(path)
26
43
  resp = request('/files/delete', path: path)
27
44
  parse_tagged_response(resp)
28
45
  end
29
46
 
47
+ # Download a file from a user's Dropbox.
48
+ #
49
+ # @param [String] path
50
+ # @return [Dropbox::FileMetadata] metadata
51
+ # @return [HTTP::Response::Body] body
30
52
  def download(path)
31
53
  resp, body = content_request('/files/download', path: path)
32
54
  return parse_tagged_response(resp, 'file'), body
33
55
  end
34
56
 
35
- def get_account(id)
36
- resp = request('/users/get_account', account_id: id)
57
+ # Get information about a user's account.
58
+ #
59
+ # @param [String] account_id
60
+ # @return [Dropbox::BasicAccount]
61
+ def get_account(account_id)
62
+ resp = request('/users/get_account', account_id: account_id)
37
63
  parse_tagged_response(resp, 'basic_account')
38
64
  end
39
65
 
40
- # Takes an array of account IDs and returns an array of BasicAccounts
41
- def get_account_batch(ids)
66
+ # Get information about multiple user accounts.
67
+ #
68
+ # @param [Array<String>] account_ids
69
+ # @return [Array<Dropbox::BasicAccount>]
70
+ def get_account_batch(account_ids)
42
71
  resp = request('/users/get_account_batch', account_ids: ids)
43
72
  resp.map { |a| parse_tagged_response(a, 'basic_account') }
44
73
  end
45
74
 
75
+ # Get information about the current user's account.
76
+ #
77
+ # @return [Dropbox::FullAccount]
46
78
  def get_current_account
47
79
  resp = request('/users/get_current_account')
48
80
  parse_tagged_response(resp, 'full_account')
49
81
  end
50
82
 
83
+ # Get the metadata for a file or folder.
84
+ #
85
+ # @param [String] path
86
+ # @return [Dropbox::Metadata]
51
87
  def get_metadata(path)
52
88
  resp = request('/files/get_metadata', path: path)
53
89
  parse_tagged_response(resp)
54
90
  end
55
91
 
92
+ # Get a preview for a file.
93
+ #
94
+ # @param [String] path
95
+ # @return [Dropbox::FileMetadata] metadata
96
+ # @return [HTTP::Response::Body] body
56
97
  def get_preview(path)
57
98
  resp, body = content_request('/files/get_preview', path: path)
58
99
  return parse_tagged_response(resp, 'file'), body
59
100
  end
60
101
 
102
+ # Get the space usage information for the current user's account.
103
+ #
104
+ # @return [Dropbox::SpaceUsage]
61
105
  def get_space_usage
62
106
  resp = request('/users/get_space_usage')
63
107
  SpaceUsage.new(resp)
64
108
  end
65
109
 
110
+ # Get a temporary link to stream content of a file.
111
+ #
112
+ # @param [String] path
113
+ # @return [Dropbox::FileMetadata] metadata
114
+ # @return [String] link
66
115
  def get_temporary_link(path)
67
116
  resp = request('/files/get_temporary_link', path: path)
68
117
  return parse_tagged_response(resp['metadata'], 'file'), resp['link']
69
118
  end
70
119
 
120
+ # Get a thumbnail for an image.
121
+ #
122
+ # @param [String] path
123
+ # @param [String] format
124
+ # @param [String] size
125
+ # @return [Dropbox::FileMetadata] metadata
126
+ # @return [HTTP::Response::Body] body
71
127
  def get_thumbnail(path, format='jpeg', size='w64h64')
72
128
  resp, body = content_request('/files/get_thumbnail', path: path, format: format, size: size)
73
129
  return parse_tagged_response(resp, 'file'), body
74
130
  end
75
131
 
132
+ # Get the contents of a folder.
133
+ #
134
+ # @param [String] path
135
+ # @return [Array<Dropbox::Metadata]
76
136
  def list_folder(path)
77
137
  resp = request('/files/list_folder', path: path)
78
138
  resp['entries'].map { |e| parse_tagged_response(e) }
79
139
  end
80
140
 
141
+ # Get the revisions of a file.
142
+ #
143
+ # @param [String] path
144
+ # @return [Array<Dropbox::FileMetadata>] entries
145
+ # @return [Boolean] is_deleted
81
146
  def list_revisions(path)
82
147
  resp = request('/files/list_revisions', path: path)
83
148
  entries = resp['entries'].map { |e| parse_tagged_response(e, 'file') }
84
149
  return entries, resp['is_deleted']
85
150
  end
86
151
 
87
- def move(from, to)
152
+ # Move a file or folder to a different location in the user's Dropbox.
153
+ #
154
+ # @param [String] from_path
155
+ # @param [String] to_path
156
+ # @return [Dropbox::Metadata]
157
+ def move(from_path, to_path)
88
158
  resp = request('/files/move', from_path: from, to_path: to)
89
159
  parse_tagged_response(resp)
90
160
  end
91
161
 
162
+ # Restore a file to a specific revision.
163
+ #
164
+ # @param [String] path
165
+ # @param [String] rev
166
+ # @return [Dropbox::FileMetadata]
92
167
  def restore(path, rev)
93
168
  resp = request('/files/restore', path: path, rev: rev)
94
169
  parse_tagged_response(resp, 'file')
95
170
  end
96
171
 
97
- # Revokes the current access token and returns it
172
+ # Disable the access token used to authenticate the call.
173
+ #
174
+ # @return [void]
98
175
  def revoke_token
99
176
  r = HTTP.auth('Bearer ' + @access_token).post(API + '/auth/token/revoke')
100
177
  raise APIError.new(r) if r.code != 200
101
- @access_token
102
178
  end
103
179
 
180
+ # Save a specified URL into a file in user's Dropbox.
181
+ #
182
+ # @param [String] path
183
+ # @param [String] url
184
+ # @return [String] the job id, if the processing is asynchronous.
185
+ # @return [Dropbox::FileMetadata] if the processing is synchronous.
104
186
  def save_url(path, url)
105
187
  resp = request('/files/save_url', path: path, url: url)
106
188
  case resp['.tag']
@@ -113,13 +195,26 @@ module Dropbox
113
195
  end
114
196
  end
115
197
 
116
- def search(query, path='', max=100)
198
+ # Search for files and folders.
199
+ #
200
+ # @param [String] query
201
+ # @param [String] path
202
+ # @param [Integer] max_results
203
+ # @return [Array<Dropbox::Metadata>] matches
204
+ def search(query, path='', max_results=100)
117
205
  resp = request('/files/search', path: path, query: query, max_results: max)
118
206
  resp['matches'].map { |m| parse_tagged_response(m['metadata']) }
119
207
  end
120
208
 
121
- # Body can be a String or an Enumerable
122
- # Mode can be 'add', 'overwrite', or 'update'
209
+ # Create a new file.
210
+ #
211
+ # @param [String] path
212
+ # @param [String, Enumerable] body
213
+ # @param [String] mode
214
+ # @param [Boolean] autorename
215
+ # @param [String, Time] client_modified
216
+ # @param [Boolean] mute
217
+ # @return [Dropbox::FileMetadata]
123
218
  def upload(path, body, mode='add', autorename=false, client_modified=nil, mute=false)
124
219
  client_modified = client_modified.iso8601 if client_modified.is_a?(Time)
125
220
  resp = upload_request('/files/upload', body, path: path, mode: mode,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropbox-sdk-v2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Waits