Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,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)
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby-box/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/ruby-box/comment.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module RubyBox
class Comment < Item

private

def resource_name
Expand All @@ -11,4 +11,4 @@ def has_mini_format?
true
end
end
end
end
2 changes: 1 addition & 1 deletion lib/ruby-box/event_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ def events
def resource_name
'events'
end

end
end
2 changes: 1 addition & 1 deletion lib/ruby-box/exceptions.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module RubyBox
module RubyBox
class RubyBoxError < StandardError
attr_accessor :body, :status

Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-box/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def create_comment(message)
def file_content_url
"#{RubyBox::API_URL}/#{resource_name}/#{id}/content"
end


def resource_name
'files'
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-box/folder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/ruby-box/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ def method_missing(method, *args, &block)
# Support has many and paginated has many relationships.
return many(key) if @@has_many.include?(key)
return paginated(key, args[0] || 100, args[1] || 0, args[2]) if @@has_many_paginated.include?(key)

# update @raw_item hash if this appears to be a setter.
setter = method.to_s.end_with?('=')
key = key[0...-1] if setter
@raw_item[key] = args[0] if setter and update_fields.include?(key)

# we may have a mini version of the object loaded, fix this.
reload_meta if @raw_item[key].nil? and has_mini_format?

Expand Down
10 changes: 7 additions & 3 deletions lib/ruby-box/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ def request(uri, request, raw=false, retries=0)
#http.set_debug_output($stdout)

if @access_token
request.delete('Authorization')
request.add_field('Authorization', "Bearer #{@access_token.token}")
else
request.delete('Authorization')
request.add_field('Authorization', build_auth_header)
end


request.add_field('As-User', "#{@as_user}") if @as_user

if @as_user
request.delete('As-User')
request.add_field('As-User', "#{@as_user}")
end
response = http.request(request)

if response.is_a? Net::HTTPNotFound
Expand Down Expand Up @@ -111,6 +114,7 @@ def handle_errors( response, raw )
body = response.body
begin
parsed_body = JSON.parse(body)
raise if body.empty? || body.nil?
rescue
msg = body.nil? || body.empty? ? "no data returned" : body
parsed_body = { "message" => msg }
Expand Down
6 changes: 3 additions & 3 deletions lib/ruby-box/shared_link.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module RubyBox
class SharedLink < Item

private

def has_mini_format?
false
end
end
end
end
8 changes: 4 additions & 4 deletions lib/ruby-box/user.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module RubyBox
class User < Item

def enterprise
resp = @session.get( "#{RubyBox::API_URL}/users/#{id}?fields=enterprise" )
resp["enterprise"]
end

private

def resource_name
'users'
end

end
end
end
12 changes: 6 additions & 6 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@
client.split_path('foo/bar/').should == ['foo', 'bar']
end
end

describe '#create_folder' do
it 'doesnt call folder.create_folder if the folder exists' do
client = RubyBox::Client.new(@session)
mock_root_folder = mock( Object )
test_folder = mock( Object )
mock_root_folder = double
test_folder = double
mock_root_folder.should_receive(:folders).and_return([test_folder])
mock_root_folder.should_not_receive(:create_subfolder)
client.should_receive(:root_folder).and_return(mock_root_folder)
result = client.create_folder( '/test0')
result.should == test_folder
end

it 'calls folder.create_folder if the folder does not exist' do
client = RubyBox::Client.new(@session)
mock_root_folder = mock( Object )
test_folder = mock( Object )
mock_root_folder = double
test_folder = double
mock_root_folder.should_receive(:folders).and_return([])
mock_root_folder.should_receive(:create_subfolder).and_return(test_folder)
client.should_receive(:root_folder).and_return(mock_root_folder)
Expand Down
4 changes: 2 additions & 2 deletions spec/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
file.name = 'Funky Monkey.jpg'
file.description = 'a new description'
file.name.should == 'Funky Monkey.jpg'
file.description.should == 'a new description'
file.description.should == 'a new description'
end

it 'should not update files raw_item hash for keys not in update_fields' do
Expand Down Expand Up @@ -107,4 +107,4 @@
end
end

end
end
6 changes: 3 additions & 3 deletions spec/folder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
it "compares name in a case insensitive manner" do
items = [
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047867", "sequence_id": "1", "etag": "1", "name": "Here\'s your folder" }, { "type": "file", "id": "409042867", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "0", "limit": "2"}'),
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047868", "sequence_id": "1", "etag": "1", "name": "Here\'s another folder" }, { "type": "file", "id": "409042810", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "2", "limit": "2"}')
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047868", "sequence_id": "1", "etag": "1", "name": "Here\'s another folder" }, { "type": "file", "id": "409042810", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "2", "limit": "2"}')
]

RubyBox::Session.any_instance.stub(:request) { items.pop }
Expand Down Expand Up @@ -96,7 +96,7 @@
it "should allow you to filter files by name" do
items = [
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047867", "sequence_id": "1", "etag": "1", "name": "Here\'s your folder" }, { "type": "file", "id": "409042867", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "0", "limit": "2"}'),
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047868", "sequence_id": "1", "etag": "1", "name": "Here\'s another folder" }, { "type": "file", "id": "409042810", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "2", "limit": "2"}')
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047868", "sequence_id": "1", "etag": "1", "name": "Here\'s another folder" }, { "type": "file", "id": "409042810", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "2", "limit": "2"}')
]

RubyBox::Session.any_instance.stub(:request) { items.pop }
Expand All @@ -108,7 +108,7 @@

items = [
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047867", "sequence_id": "1", "etag": "1", "name": "Here\'s your folder" }, { "type": "file", "id": "409042867", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "0", "limit": "2"}'),
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047868", "sequence_id": "1", "etag": "1", "name": "Here\'s another folder" }, { "type": "file", "id": "409042810", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "2", "limit": "2"}')
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047868", "sequence_id": "1", "etag": "1", "name": "Here\'s another folder" }, { "type": "file", "id": "409042810", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "2", "limit": "2"}')
]

# should return no files.
Expand Down
Loading