ruby-box 1.4.0 → 1.5.0

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODI2ZDdkYWJmMDQ3ZGZiMDQ1ZGI3NDljOTM0ZGY2ZDhiMGM1YWE2Mw==
4
+ Nzk0MzA1ZmJjZTkyODM4ZjQ0YjcxNTM5ZWQ0MTIyYjFjYTRkN2UxMw==
5
5
  data.tar.gz: !binary |-
6
- ODNjY2YyZTA5ODcwMjU3ZjNmODljYjY1MzM5YTcxODYwZjgzNTcyMA==
6
+ MTE2NjQ3MTZmN2M2NGM4ZGU0ZWY1YWVjZTBjMzljZDdhZWFhZWE3MQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MDYxYmQ5ZjAyZjYyNzc4MzczNjEwZTdjMWNhOGI4ZWFkODI0OWJjMzVjNGJk
10
- ODYyMTQ2ZmVlMmUwZDNkMDE5NGY2NTZjOTgyYWQ5MGMzOGFhYTEzMjhhN2Qy
11
- ZDVlY2JkM2E0N2U2NTEzYzA2ZDJkYTZjYjJkODUwYTRjZjI5YmE=
9
+ YTAxYTFiMjI2YjNiNDU3ZGIwMjQzNjkzMDI5MjRkMWMxZmE0MDgyOTBhY2Qz
10
+ ZDgwODQ1Njc2ZGNlNzM1YzcyNWI3ZDExMTVjZmFmMTdlZmI4YTZmZmE0NmJh
11
+ MmEyMGQ3ZmZlYjhkZGYyYjJmNDZhNzZjYzJkZDE2MDVhNjk1OWE=
12
12
  data.tar.gz: !binary |-
13
- OTliM2MyMjk3ZmJmNzIxY2I3MjBmYWJjM2IzNWEwNThmN2I0Nzc2NjcxMmQ1
14
- MDNhNzFmNjk1YjdlMDIzZjkyYTA0ZGNlYTY1MWFiOThmZDAzYzlkM2IxZWQw
15
- OTg5NmRmMTRkNzBkNzMxNjhiMWU4MzEwMzE4ZTMzMGQ5OGU1YTc=
13
+ M2Y3OTAxMjQ5Zjc1NmJjM2Y1MDkyNTQyNmVmMzkwZjQyNzU5YWJkMDdlYjRl
14
+ NmU3ZGMwMDAyOTBkOTAyN2U4NzhhN2EyZGJlNTkyNTI5OGFmOTQ0MzViYWMw
15
+ Yjg2M2RjNzdlYTYyOGFhNGJjYTc5MGU0M2JlN2Y2OTc1YTU0NGQ=
data/README.markdown CHANGED
@@ -31,7 +31,14 @@ p '@token.token' # the access token.
31
31
  p '@token.refresh_token' # token that can be exchanged for a new access_token once the access_token expires.
32
32
 
33
33
  # refreshing token.
34
- @token = session.refresh_token('refresh-token-string')
34
+
35
+ session = RubyBox::Session.new({
36
+ client_id: 'your-client-id',
37
+ client_secret: 'your-client-secret',
38
+ access_token: 'original-access-token'
39
+ })
40
+
41
+ @token = session.refresh_token('your-refresh-token')
35
42
  ```
36
43
 
37
44
  __3)__ Create a client using a session initialized with the _access\_token_.
@@ -86,6 +93,13 @@ discussion = folder.discussions.first
86
93
  discussion.comments.each {|comment| p comment.message}
87
94
  ```
88
95
 
96
+ * Creating a shared link for a folder.
97
+
98
+ ```ruby
99
+ folder = client.folder('image_folder').create_shared_link
100
+ p folder.shared_link['url'] # https://www.box.com/s/d6de3224958c1755412
101
+ ```
102
+
89
103
  Files
90
104
  -----
91
105
 
@@ -126,6 +140,13 @@ comments.each do |comment|
126
140
  end
127
141
  ```
128
142
 
143
+ * Creating a shared link for a file.
144
+
145
+ ```ruby
146
+ file = client.file('/image_folder/an-image.jpg').create_shared_link
147
+ p file.shared_link['url'] # https://www.box.com/s/d6de3224958c1755412
148
+ ```
149
+
129
150
  Search
130
151
  ------
131
152
 
@@ -152,8 +173,6 @@ eresp.events.each do |ev|
152
173
  end
153
174
  ```
154
175
 
155
-
156
-
157
176
  Contributors
158
177
  ============
159
178
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.0
1
+ 1.5.0
@@ -14,4 +14,5 @@ module RubyBox
14
14
  class RequestError < RubyBoxError; end
15
15
  class ServerError < StandardError; end
16
16
  class ItemNameInUse < RubyBoxError; end
17
+ class UnshareableResource < StandardError; end
17
18
  end
@@ -51,6 +51,15 @@ module RubyBox
51
51
  collaboration.create
52
52
  end
53
53
 
54
+ def create_subfolder(name)
55
+ url = "#{RubyBox::API_URL}/#{resource_name}"
56
+ uri = URI.parse(url)
57
+ request = Net::HTTP::Post.new( uri.request_uri )
58
+ request.body = JSON.dump({ "name" => name, "parent" => {"id" => id} })
59
+ resp = @session.request(uri, request)
60
+ RubyBox::Folder.new(@session, resp)
61
+ end
62
+
54
63
  private
55
64
 
56
65
  def resource_name
data/lib/ruby-box/item.rb CHANGED
@@ -82,6 +82,34 @@ module RubyBox
82
82
  end
83
83
  end
84
84
 
85
+ # see http://developers.box.com/docs/#folders-create-a-shared-link-for-a-folder
86
+ # for a list of valid options.
87
+ def create_shared_link(opts={})
88
+ raise UnshareableResource unless ['folder', 'file'].include?(type)
89
+
90
+ opts = {
91
+ access: 'open'
92
+ }.merge(opts) if opts
93
+
94
+ url = "#{RubyBox::API_URL}/#{resource_name}/#{id}"
95
+ uri = URI.parse(url)
96
+
97
+ request = Net::HTTP::Put.new(uri.path, {
98
+ "Content-Type" => 'application/json'
99
+ })
100
+
101
+ request.body = JSON.dump({
102
+ shared_link: opts
103
+ })
104
+
105
+ @raw_item = @session.request(uri, request)
106
+ self
107
+ end
108
+
109
+ def disable_shared_link(opts={})
110
+ create_shared_link(nil)
111
+ end
112
+
85
113
  protected
86
114
 
87
115
  def self.factory(session, entry)
data/ruby-box.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ruby-box"
8
- s.version = "1.4.0"
8
+ s.version = "1.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Attachments.me"]
12
- s.date = "2013-06-21"
12
+ s.date = "2013-07-01"
13
13
  s.description = "ruby gem for box.com 2.0 api"
14
14
  s.email = "ben@attachments.me"
15
15
  s.extra_rdoc_files = [
@@ -198,5 +198,34 @@ describe RubyBox, :skip => true do
198
198
  folder.delete if folder
199
199
  end
200
200
  end
201
+
202
+ describe '#shared_link' do
203
+ it 'should allow a share link to be created for a folder' do
204
+ folder = @client.create_folder('/ruby-box_gem_testing/shared_folder').create_shared_link
205
+
206
+ # share link was successfully created.
207
+ folder.shared_link['url'].should match /https?:\/\/[\S]+/
208
+
209
+ # share link can be disabled.
210
+ folder.disable_shared_link
211
+ folder.shared_link.should == nil
212
+
213
+ folder.delete if folder
214
+ end
215
+
216
+ it 'should allow a share link to be created for a file' do
217
+ utf8_file_name = '遠志教授.jpg'
218
+ file = @client.upload_file('spec/fixtures/' + utf8_file_name, '/ruby-box_gem_testing/cool stuff/').create_shared_link
219
+
220
+ # share link was successfully created.
221
+ file.shared_link['url'].should match /https?:\/\/[\S]+/
222
+
223
+ # share link can be disabled.
224
+ file.disable_shared_link
225
+ file.shared_link.should == nil
226
+
227
+ file.delete
228
+ end
229
+ end
201
230
  end
202
231
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-box
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Attachments.me
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-21 00:00:00.000000000 Z
11
+ date: 2013-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post