From 8ff813bc7c73805b9ffc4e295c50004194a4ac4e Mon Sep 17 00:00:00 2001 From: Adrien Giboire Date: Wed, 17 Dec 2014 18:29:45 +0100 Subject: [PATCH 1/5] feature: creation of folder upload email --- lib/ruby-box/client.rb | 4 ++-- lib/ruby-box/folder.rb | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/ruby-box/client.rb b/lib/ruby-box/client.rb index 22a66e8..f3ad17f 100644 --- a/lib/ruby-box/client.rb +++ b/lib/ruby-box/client.rb @@ -76,7 +76,7 @@ def create_folder(path) folder = root_folder folder_names = split_path(path) folder_names.each do |folder_name| - new_folder = folder.folders(folder_name).first + new_folder = folder.folders(folder_name).first if !new_folder begin new_folder = folder.create_subfolder(folder_name) @@ -158,6 +158,6 @@ def fmt_events_args(stream_position, stream_type, limit) limit = limit.kind_of?(Fixnum) ? limit : 100 "stream_position=#{stream_position}&stream_type=#{stream_type}&limit=#{limit}" end - + end end diff --git a/lib/ruby-box/folder.rb b/lib/ruby-box/folder.rb index 66908e6..f39a5f0 100644 --- a/lib/ruby-box/folder.rb +++ b/lib/ruby-box/folder.rb @@ -22,7 +22,7 @@ def upload_file(filename, data, overwrite=true) begin resp = file.upload_content(data) #write a new file. If there is a conflict, update the conflicted file. rescue RubyBox::ItemNameInUse => e - + # if overwrite flag is false, simply raise exception. raise e unless overwrite @@ -76,6 +76,26 @@ def copy_to(destination, name=nil) RubyBox::Folder.new(@session, post(folder_method(:copy), parent)) end + def create_folder_upload_email(opts = {}) + opts = { + access: 'open' + }.merge(opts) if opts + + url = "#{RubyBox::API_URL}/#{resource_name}/#{id}" + uri = URI.parse(url) + + request = Net::HTTP::Put.new(uri.path, { + 'Content-Type' => 'application/jso' + }) + + request.body = JSON.dump({ + folder_upload_email: opts + }) + + resp = @session.request(uri, request) + RubyBox::Folder.new(@session, resp) + end + private def post(extra_url, body) uri = URI.parse("#{RubyBox::API_URL}/#{extra_url}") From 238160fcbc2516145d258ce65e94ff09f0dcb645 Mon Sep 17 00:00:00 2001 From: Adrien Giboire Date: Wed, 17 Dec 2014 18:53:36 +0100 Subject: [PATCH 2/5] docs: update readme for create folder upload email --- README.markdown | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/README.markdown b/README.markdown index a432952..5c88a9a 100644 --- a/README.markdown +++ b/README.markdown @@ -3,7 +3,7 @@ ruby-box Build Status: [![Build Status](https://travis-ci.org/attachmentsme/ruby-box.png)](https://travis-ci.org/attachmentsme/ruby-box) -Mainted by: [Attachments.me](http://attachments.me) +Maintained by: [Adrien Giboire](http://adriengiboire.com) RubyBox provides a simple, chainable, feature-rich client for [Box's 2.0 API](http://developers.box.com/docs/). @@ -15,7 +15,7 @@ RubyBox uses Box's OAuth2 Implementaton, Here are the steps involved in authoriz __1)__ Get the authorization url. ```ruby -require 'ruby-box' +require 'ruby-box-updated' session = RubyBox::Session.new({ client_id: 'your-client-id', @@ -48,7 +48,7 @@ save_me_somehow(@token.refresh_token) __3)__ Create a client using a session initialized with the _access\_token_. ```ruby -require 'ruby-box' +require 'ruby-box-updated' session = RubyBox::Session.new({ client_id: 'your-client-id', @@ -156,6 +156,13 @@ folder = client.folder('image_folder').create_shared_link # lookups by id are mo p folder.shared_link['url'] # https://www.box.com/s/d6de3224958c1755412 ``` +* Creating an email to upload files in a folder. + +```ruby +folder = client.folder('documents_folder').create_folder_upload_email # lookups by id are more efficient +p folder.folder_upload_email.email # upload.adrien_.8kge3wck1h@u.box.com +``` + Files ----- @@ -319,7 +326,7 @@ An array of Ruby:Box users in an enterprise (Supports Filtering, Limit and Offse users = client.users ``` -* Remeber the API filters "name" and "login" by the start of the string. ie: to get "sean+awesome@gmail.com" an approriate filter term would be "sean" +* Remember the API filters "name" and "login" by the start of the string. ie: to get "sean+awesome@gmail.com" an approriate filter term would be "sean" ```ruby users = client.users("sean" , 10 , 1) @@ -334,7 +341,7 @@ Contributing to ruby-box ======================== RubyBox does not yet support all of Box's API Version 2.0 functionality, be liberal with your contributions. - + * Rename account.example to account.yml and fill in your Box credentials * Type bundle install * Type rake.. tests should pass From e3371db0b538f2ed4eea4317933edda228249a85 Mon Sep 17 00:00:00 2001 From: Adrien Giboire Date: Wed, 17 Dec 2014 18:54:20 +0100 Subject: [PATCH 3/5] docs: update gemspec --- ruby-box.gemspec | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ruby-box.gemspec b/ruby-box.gemspec index 91cd522..9e42c24 100644 --- a/ruby-box.gemspec +++ b/ruby-box.gemspec @@ -5,15 +5,15 @@ # stub: ruby-box 1.15.0 ruby lib Gem::Specification.new do |s| - s.name = "ruby-box" - s.version = "1.15.0" + s.name = "ruby-box-updated" + s.version = "1.16.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.require_paths = ["lib"] - s.authors = ["Attachments.me"] - s.date = "2014-10-16" + s.authors = ["Attachments.me", "Adrien Giboire"] + s.date = "2014-12-17" s.description = "ruby gem for box.com 2.0 api" - s.email = "ben@attachments.me" + s.email = "adrien.giboire@gmail.com" s.extra_rdoc_files = [ "LICENSE.txt", "README.markdown" @@ -60,7 +60,7 @@ Gem::Specification.new do |s| "spec/spec_helper.rb", "spec/users_spec.rb" ] - s.homepage = "http://github.com/attachmentsme/ruby-box" + s.homepage = "http://github.com/adriengiboire/ruby-box" s.licenses = ["MIT"] s.rubygems_version = "2.2.2" s.summary = "ruby gem for box.com 2.0 api" From 1738edccd056517e4ece115e3177ee53b7905b72 Mon Sep 17 00:00:00 2001 From: Adrien Giboire Date: Wed, 17 Dec 2014 18:54:58 +0100 Subject: [PATCH 4/5] docs: fix readme for creating a shared folder link --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 5c88a9a..b37dcbc 100644 --- a/README.markdown +++ b/README.markdown @@ -153,7 +153,7 @@ discussion.comments.each {|comment| p comment.message} ```ruby folder = client.folder('image_folder').create_shared_link # lookups by id are more efficient -p folder.shared_link['url'] # https://www.box.com/s/d6de3224958c1755412 +p folder.shared_link.url # https://www.box.com/s/d6de3224958c1755412 ``` * Creating an email to upload files in a folder. From cffd44197ec148ccb1439b62030fc87bc63a38ed Mon Sep 17 00:00:00 2001 From: Adrien Giboire Date: Wed, 17 Dec 2014 19:29:52 +0100 Subject: [PATCH 5/5] revert gem name --- ruby-box.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby-box.gemspec b/ruby-box.gemspec index 9e42c24..b3a4ee1 100644 --- a/ruby-box.gemspec +++ b/ruby-box.gemspec @@ -5,7 +5,7 @@ # stub: ruby-box 1.15.0 ruby lib Gem::Specification.new do |s| - s.name = "ruby-box-updated" + s.name = "ruby-box" s.version = "1.16.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=