attachmentsme / ruby-box Goto Github PK
View Code? Open in Web Editor NEWRuby SDK for Box API v2.0
License: MIT License
Ruby SDK for Box API v2.0
License: MIT License
I'm trying to the install the ruby-box gem on Windows 7x64, but it's throwing this error:
ERROR: While executing gem... (Encoding::UndefinedConversionError)
"\x81" to UTF-8 in conversion from Windows-1252 to UTF-8.
Can somebody please show me how to get pass this? Thanks in advance.
I've got some code that looks like:
folder = client.folder_by_id(folder_id)
folder.upload_file(file_name, data)
And I'm getting an exception like Errno::ENAMETOOLONG: File name too long
. It appears to be passing the data
variable as the file name when creating a new file.
I've looked through the source for the upload_file
method, and it looks okay, but I've also verified that file_name
is just foo.csv
so something's going awry.
Any ideas? Is the upload_file
method available for use, or old dead code?
The README.md file is getting a bit hectic, with all the features that have been added to ruby-box recently. We should swing back around and edit this sucker.
Anyone else running into issues w/ gzipped responses? Testing this out locally with Ruby 2.0.0p247 and is abending on refresh_token call (via oauth2 gem). c/f oauth-xx/oauth2#159
However, seems this should be handled further up (Net::HTTP, Faraday).
> 2.0.0-p247 :016 > client.root_folder
OAuth2::Error: <??
?@E?e?.D?ҝV*??c`????_??3Z??M-Z?????"yY??po?#6qՠ?b?L???}?H-\?r?hz%
??!????9S?L?r?Jz?}?|Q-i??zH???1?5h?ЊE?DF?3?yP??as?,? 51ѕq???pB#)??BD???b6L
??r??????aa??
from /Users/marknadig/.rvm/gems/ruby-2.0.0-p247@kona/gems/oauth2-0.9.3/lib/oauth2/client.rb:137:in `get_token'
from /Users/marknadig/.rvm/gems/ruby-2.0.0-p247@kona/gems/oauth2-0.9.3/lib/oauth2/access_token.rb:86:in `refresh!'
from /Users/marknadig/.rvm/gems/ruby-2.0.0-p247@kona/gems/ruby-box-1.13.0/lib/ruby-box/session.rb:38:in `refresh_token'
from /Users/marknadig/.rvm/gems/ruby-2.0.0-p247@kona/gems/ruby-box-1.13.0/lib/ruby-box/session.rb:81:in `request'
Similar issue here w/ oauth gem after updating to Ruby 2
http://www.extendi.it/blog/2013/12/02/6-oauth-gem-and-ruby-2-0-0
I've integrated this gem into my Rails 3 app and am experiencing a significant delay when pulling files/folders. Here's a specific example.
I'm populating a select box with a nested folder structure from Box. There are a total of 6 folders in my Box account - 3 top/root level and the other 3 are subfolders (see structure below). The ajax request which populates this select box takes 25-30 second to complete! Do you have any thoughts or suggestions? The performance issue isn't isolated just to this method. It's anytime I fetch and iterate over files or folders.
/
/Folder 1
/Folder 1/Nested folder 1-1
/Folder 1/Nested folder 1-2
/Folder 2
/Folder 3
/Folder 3/Nested folder 3-1
Here's the recursive method I'm using.
def folders_from_box(parent_folder_path = '/', recursive = true)
folders = []
if parent_folder_object = client.folder(parent_folder_path)
folder_objects = parent_folder_object.folders
if folder_objects.length > 0
parent_folder_path += "/" unless parent_folder_path[-1] == "/"
folder_objects.each do |folder_object|
folder_path = parent_folder_path + folder_object.name
folders << { id: folder_object.id, path: folder_path }
folders += folders_from_box(folder_path) if recursive
end
end
end
return folders
end
After getting tokens, just as shown in Readme, when attempting any call (e.g. folders = client.root_folder.folders ) I get a Bad request for any API call:
`RubyBox::RequestError (
<title>400 Bad Request</title>code used (with the constants/variables set of course):
session = RubyBox::Session.new({
client_id: BOX_CLIENT_ID,
client_secret: BOX_CLIENT_SECRET,
access_token: token
})
client = RubyBox::Client.new(session)
folders = client.root_folder.folders
A copy method for the file class would be very useful. As of now you have to pull the files locally and re-upload working when working entirely inside ruby-box.
excuse my ignorance as I'm new to Ruby and box but when I attempt to install this gem I get an error. What is the problem? thanks.
C:>gem install ruby-box
Fetching: httpauth-0.2.0.gem (100%)
Successfully installed httpauth-0.2.0
Fetching: multi_xml-0.5.3.gem (100%)
Successfully installed multi_xml-0.5.3
Fetching: oauth2-0.9.1.gem (100%)
Successfully installed oauth2-0.9.1
Fetching: ruby-box-1.2.0.gem (100%)
ERROR: While executing gem ... (Errno::EINVAL)
Invalid argument - C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/ruby-box-1.2.0/spec/fixtures/i☺ e?↨f§↓.jpg
Hi all, does this gem support groups and collaborations functionalities ?
Thanks a lot
We should write a spec using webmock for the direct-link logic that @doliveirakn recently added.
I haven't experienced this with Box yet, but with Dropbox, I have experienced hangs in requests that fail to get responses. The dropbox gem also uses Net::HTTP which does not have open_timeout, ssl_timeout, or continue_timeout's set by default. I want to avoid the same issue with Box by setting appropriate timeouts on the Net::HTTP object (which has to be done after it is created, no global config is available to my knowledge from reading the ruby code)
Preferably, RubyBox::Session would allow me to pass through these various timeouts which would then be set on the http object in RubyBox::Session.request
session = RubyBox::Session.new(
:client_id => ENV['BOX_CLIENT_ID'],
:client_secret => ENV['BOX_CLIENT_SECRET'],
:access_token => ENV['BOX_ACCESS_TOKEN']
)
client = RubyBox::Client.new(session)
file = client.upload_file_by_folder_id(valid_local_file_path, 0)
client.file_by_id(file.id).delete
# NoMethodError: undefined method `[]=' for nil:NilClass
# .rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/ruby-box-1.15.0/lib/ruby-box/session.rb:120:in `handle_errors'
I didn't see support for tasks, so I thought I'd take a crack at it.
Sorry to post this here but I was unable to find any API or rdoc for this gem. Thank you.
Matt
It would be helpful to indicate in the docs that, when you're using the refresh token, you should construct the session with the original access token.
e.g.
require 'ruby-box'
session = RubyBox::Session.new({
client_id: 'your-client-id',
client_secret: 'your-client-secret'
})
session.refresh_token('your-refresh-token')
will not work while the following will
require 'ruby-box'
session = RubyBox::Session.new({
client_id: 'your-client-id',
client_secret: 'your-client-secret',
access_token: 'original-access-token'
})
session.refresh_token('your-refresh-token')
When a 401 is received and a successful refresh is executed an exception is still raised by handle_errors
How do I access the thumbnail end-point with this gem?
The readme.md only explains briefly how to authenticate a box.com user to access files from his account
It would be helpful to show how to use one account for the application to store uploaded files into.
You should be able to create comments on files.
You should be able to create a discussion on a folder.
Hello there!
I would like to know how to log on without the "redirect_uri" and get the token. It's for a command line application.
Thanks for all.
When uploading a file, if it fails because the account is full, a 507 response is returned. However all I can see is RubyBox::ServerError. I don't know if it was some other 5xx error or not. It would be good if the entire response was included in the exception so that consumers of the gem can inspect the response for things the gem hasn't done.
So recently my integration's update description stop working. now when I try to update the description I get a "RubyBox::ItemNameInUse: Item with the same name already exists" I will take a look and see if I can give you a hand looking for this bug.
I am currently using RubyBox 1.4.0 but seem to be running into compatibility issues with Ruby 1.8.7, specifically around an Enumerator call on line 109 of item.rb.
Do any of the earlier versions of RubyBox work as - is with 1.8.7?
If not, any suggestions for a patch so I can successfully backport this gem for 1.8.7?
Thanks,
Wes
The 'folder' method in the client should return the root folder if:
I was playing with the API yesterday and was wishing that it worked like this.
I'm trying to work through how a user would detect that a requested failed initially due to an expired token and a successful refresh took place, providing a new access_token and refresh_token that the client may want to save. Any thoughts?
My current approach is to subclass session and override refresh_token to save off new tokens after calling super. I didn't know if there was a better pattern for some how passing this in the config; e.g. a proc or...
When used in a multiprocess application, there can be a race condition where two processes try to create the same folder. The second one can fail the folder.create_subfolder() call with RubyBox::ItemNameInUse.
The fix for this is to catch this exception and try to open the folder instead of creating it.
Otherwise this can lead to confusing behavior:
> item.id
> "12345"
> item.try(:id)
> nil
> item.respond_to?(:id)
> false
See https://robots.thoughtbot.com/always-define-respond-to-missing-when-overriding
Corrective PR: #118
Using upload_file_by_folder_id with the default overwrite=true fails when an existing file is present in the Box upload folder.
ruby-box (1.14.0)
irb(main):011:0* client.upload_file_by_folder_id('<My\Dir', '123456')
RubyBox::RequestError: Method Not Allowed
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/ruby-box-1.14.0/lib/ruby-box/session.rb:128:in handle_errors' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/ruby-box-1.14.0/lib/ruby-box/session.rb:87:in
request'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/ruby-box-1.14.0/lib/ruby-box/session.rb:48:in get' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/ruby-box-1.14.0/lib/ruby-box/item.rb:68:in
reload_meta'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/ruby-box-1.14.0/lib/ruby-box/item.rb:85:in method_missing' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/ruby-box-1.14.0/lib/ruby-box/file.rb:54:in
update_content'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/ruby-box-1.14.0/lib/ruby-box/folder.rb:23:in upload_file' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/ruby-box-1.14.0/lib/ruby-box/client.rb:140:in
block in upload_file_to_folder'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/ruby-box-1.14.0/lib/ruby-box/client.rb:139:in open' from C:/Ruby200/lib/ruby/gems/2.0.0/gems/ruby-box-1.14.0/lib/ruby-box/client.rb:139:in
upload_file_to_folder'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/ruby-box-1.14.0/lib/ruby-box/client.rb:106:in upload_file_by_folder_id' from (irb):11 from C:/Ruby200/bin/irb:12:in
Hello,
I get a "Cannot delete - folder not empty error".
I want to know if there is a way to force delete a folder for convenience. I've checked the README.md, it didn't even have information on deleting a folder. Code sample would be appreciated.
Does the API preclude us from being able to copy one folder to another? Just curious if this can be added.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.