box-api 0.2.0 → 0.2.1
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.
- data/Gemfile.lock +1 -1
- data/README.md +2 -0
- data/box-api.gemspec +1 -1
- data/doc/Box.html +1 -1
- data/doc/Box/Account.html +225 -25
- data/doc/Box/Api.html +374 -8
- data/doc/Box/Api/AccountExceeded.html +1 -1
- data/doc/Box/Api/EmailInvalid.html +1 -1
- data/doc/Box/Api/EmailTaken.html +1 -1
- data/doc/Box/Api/ErrorStatus.html +1 -1
- data/doc/Box/Api/Exception.html +2 -2
- data/doc/Box/Api/Generic.html +1 -1
- data/doc/Box/Api/InvalidFolder.html +1 -1
- data/doc/Box/Api/InvalidInput.html +1 -1
- data/doc/Box/Api/InvalidName.html +1 -1
- data/doc/Box/Api/NameTaken.html +1 -1
- data/doc/Box/Api/NoAccess.html +1 -1
- data/doc/Box/Api/NoParent.html +1 -1
- data/doc/Box/Api/NotAuthorized.html +1 -1
- data/doc/Box/Api/NotShared.html +141 -0
- data/doc/Box/Api/Restricted.html +1 -1
- data/doc/Box/Api/SizeExceeded.html +1 -1
- data/doc/Box/Api/Unknown.html +1 -1
- data/doc/Box/Api/UnknownResponse.html +1 -1
- data/doc/Box/Api/UploadFailed.html +1 -1
- data/doc/Box/Comment.html +1 -1
- data/doc/Box/File.html +24 -6
- data/doc/Box/Folder.html +2 -2
- data/doc/Box/Item.html +275 -1
- data/doc/_index.html +8 -1
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/method_list.html +116 -52
- data/doc/top-level-namespace.html +1 -1
- data/lib/box/account.rb +33 -1
- data/lib/box/api.rb +30 -0
- data/lib/box/api/exceptions.rb +12 -0
- data/lib/box/file.rb +7 -1
- data/lib/box/item.rb +30 -2
- metadata +13 -12
data/lib/box/api.rb
CHANGED
@@ -331,5 +331,35 @@ module Box
|
|
331
331
|
def file_embed(id, options = Hash.new)
|
332
332
|
query_rest('s_create_file_embed', { :action => :create_file_embed, :file_id => id }.merge(options))
|
333
333
|
end
|
334
|
+
|
335
|
+
# Share an item publically, making it accessible via a share link.
|
336
|
+
#
|
337
|
+
# @param [String] target The type of item.
|
338
|
+
# @param [String] target_id The id of the item to share.
|
339
|
+
# @param [Hash] options Extra options related to notifications. Please
|
340
|
+
# read the developer documentation for more details.
|
341
|
+
def share_public(target, target_id, options = Hash.new)
|
342
|
+
query_rest('share_ok', { :action => :public_share, :target => target, :target_id => target_id }.merge(options))
|
343
|
+
end
|
344
|
+
|
345
|
+
# Share an item privately, making it accessible only via email.
|
346
|
+
#
|
347
|
+
# @param [String] target The type of item.
|
348
|
+
# @param [String] target_id The id of the item to share.
|
349
|
+
# @param [Array] emails The email addresses of the individuals to share with.
|
350
|
+
# @param [Hash] options Extra options related to notifications. Please
|
351
|
+
# read the developer documentation for more details.
|
352
|
+
#
|
353
|
+
def share_private(target, target_id, emails, options = Hash.new)
|
354
|
+
query_rest('private_share_ok', { :action => :private_share, :target => target, :target_id => target_id, :emails => emails }.merge(options))
|
355
|
+
end
|
356
|
+
|
357
|
+
# Stop sharing an item publically.
|
358
|
+
#
|
359
|
+
# @param [String] target The type of item.
|
360
|
+
# @param [String] target_id The id of the item to unshare.
|
361
|
+
def unshare_public(target, target_id)
|
362
|
+
query_rest('unshare_ok', :action => :public_unshare, :target => target, :target_id => target_id)
|
363
|
+
end
|
334
364
|
end
|
335
365
|
end
|
data/lib/box/api/exceptions.rb
CHANGED
@@ -29,6 +29,9 @@ module Box
|
|
29
29
|
class AccountExceeded < Exception; end
|
30
30
|
class SizeExceeded < Exception; end
|
31
31
|
|
32
|
+
# Sharing specific responses
|
33
|
+
class NotShared < Exception; end
|
34
|
+
|
32
35
|
# Given a status, returning a cooresponding Exception class.
|
33
36
|
#
|
34
37
|
# @param [String] status The failing status to look for.
|
@@ -52,6 +55,8 @@ module Box
|
|
52
55
|
when "get_auth_token_error", "e_register"
|
53
56
|
Generic
|
54
57
|
# Folder/File specific responses
|
58
|
+
when "wrong_node"
|
59
|
+
InvalidItem
|
55
60
|
when "e_folder_id"
|
56
61
|
InvalidFolder
|
57
62
|
when "no_parent"
|
@@ -74,6 +79,13 @@ module Box
|
|
74
79
|
# Comment specific responses
|
75
80
|
when "get_comments_error", "add_comment_error", "delete_comment_error"
|
76
81
|
Generic
|
82
|
+
# Sharing specific responses
|
83
|
+
when "file_not_shared"
|
84
|
+
NotShared
|
85
|
+
when "wrong input params"
|
86
|
+
InvalidInput
|
87
|
+
when "share_error", "unshare_error", "private_share_error"
|
88
|
+
Generic
|
77
89
|
else
|
78
90
|
Unknown
|
79
91
|
end
|
data/lib/box/file.rb
CHANGED
@@ -67,8 +67,14 @@ module Box
|
|
67
67
|
# when generating the embed code.
|
68
68
|
# @return [String] HTML code to use to embed the file.
|
69
69
|
#
|
70
|
+
# @note This function will share the file if it is not already shared.
|
70
71
|
def embed_code(options = Hash.new)
|
71
|
-
|
72
|
+
begin
|
73
|
+
@api.file_embed(id, options)['file_embed_html']
|
74
|
+
rescue Api::NotShared
|
75
|
+
share_public
|
76
|
+
retry
|
77
|
+
end
|
72
78
|
end
|
73
79
|
|
74
80
|
protected
|
data/lib/box/item.rb
CHANGED
@@ -169,12 +169,40 @@ module Box
|
|
169
169
|
@data.key?(sym.to_s) or super
|
170
170
|
end
|
171
171
|
|
172
|
-
# Consider the item cached. This prevents an additional api
|
173
|
-
#
|
172
|
+
# Consider the item cached. This prevents an additional api when we
|
173
|
+
# know the item is fully fetched.
|
174
174
|
def force_cached_info
|
175
175
|
@cached_info = true
|
176
176
|
end
|
177
177
|
|
178
|
+
# Generates a share link for this item.
|
179
|
+
#
|
180
|
+
# @param [Hash] options Special options related to notification. See
|
181
|
+
# the developer wiki for details instructions.
|
182
|
+
# @return The public name of the item. In order to access this item
|
183
|
+
# on the web, prefix this value with 'http://www.box.net/shared/'.
|
184
|
+
#
|
185
|
+
# TODO: Document the options.
|
186
|
+
def share_public(options = Hash.new)
|
187
|
+
@api.share_public(type, id, options)['public_name']
|
188
|
+
end
|
189
|
+
|
190
|
+
# Shares this item privately with the given email addresses.
|
191
|
+
#
|
192
|
+
# @param [Array] emails The Box users to share this item with.
|
193
|
+
# @param [Hash] options Special options related to notification. See
|
194
|
+
# the developer wiki for details instructions.
|
195
|
+
def share_private(emails, options = Hash.new)
|
196
|
+
@api.share_private(type, id, emails, options)
|
197
|
+
|
198
|
+
true
|
199
|
+
end
|
200
|
+
|
201
|
+
# Unshares this item.
|
202
|
+
def unshare
|
203
|
+
@api.unshare(type, id)
|
204
|
+
end
|
205
|
+
|
178
206
|
protected
|
179
207
|
|
180
208
|
# Fetches this item's info from the api.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: box-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-11-
|
13
|
+
date: 2011-11-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httmultiparty
|
17
|
-
requirement: &
|
17
|
+
requirement: &2153669280 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 0.3.6
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2153669280
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: launchy
|
28
|
-
requirement: &
|
28
|
+
requirement: &2153668860 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2153668860
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rake
|
39
|
-
requirement: &
|
39
|
+
requirement: &2153668360 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2153668360
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rspec
|
50
|
-
requirement: &
|
50
|
+
requirement: &2153667820 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2153667820
|
59
59
|
description: Box-api is a collection of classes that implement functions defined in
|
60
60
|
the Box public API. See http://developer.box.net for more information.
|
61
61
|
email:
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- doc/Box/Api/NoAccess.html
|
88
88
|
- doc/Box/Api/NoParent.html
|
89
89
|
- doc/Box/Api/NotAuthorized.html
|
90
|
+
- doc/Box/Api/NotShared.html
|
90
91
|
- doc/Box/Api/Restricted.html
|
91
92
|
- doc/Box/Api/SizeExceeded.html
|
92
93
|
- doc/Box/Api/Unknown.html
|
@@ -144,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
145
|
version: '0'
|
145
146
|
segments:
|
146
147
|
- 0
|
147
|
-
hash:
|
148
|
+
hash: 2152248300867732637
|
148
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
150
|
none: false
|
150
151
|
requirements:
|
@@ -153,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
154
|
version: '0'
|
154
155
|
segments:
|
155
156
|
- 0
|
156
|
-
hash:
|
157
|
+
hash: 2152248300867732637
|
157
158
|
requirements: []
|
158
159
|
rubyforge_project:
|
159
160
|
rubygems_version: 1.8.10
|