Skip to content

Commit 425fd82

Browse files
committed
Add get_usage_allocation method
1 parent 6ff98d9 commit 425fd82

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

lib/dropbox/account.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,14 @@ def initialize(attrs={})
3434
super(attrs)
3535
end
3636
end
37+
38+
class SpaceUsage
39+
attr_reader :used, :allocation, :allocated
40+
41+
def initialize(attrs={})
42+
@used = attrs['used'] # Space used in bytes
43+
@allocation = attrs['allocation']['.tag'] # The type of allocation
44+
@allocated = attrs['allocation']['allocated'] # Space allocated in bytes
45+
end
46+
end
3747
end

lib/dropbox/client.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def get_account(id)
3737
parse_tagged_response(resp, 'basic_account')
3838
end
3939

40+
# Takes an array of account IDs and returns an array of BasicAccounts
4041
def get_account_batch(ids)
4142
resp = request('/users/get_account_batch', account_ids: ids)
4243
resp.map { |a| parse_tagged_response(a, 'basic_account') }
@@ -57,6 +58,11 @@ def get_preview(path)
5758
return parse_tagged_response(resp, 'file'), body
5859
end
5960

61+
def get_space_usage
62+
resp = request('/users/get_space_usage')
63+
SpaceUsage.new(resp)
64+
end
65+
6066
def get_temporary_link(path)
6167
resp = request('/files/get_temporary_link', path: path)
6268
return parse_tagged_response(resp['metadata'], 'file'), resp['link']

test/test_account.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,15 @@ def test_full_account_initialize
3535
assert_equal false, account.disabled
3636
assert_equal true, account.is_paired
3737
end
38+
39+
def test_space_usage_initialize
40+
usage = Dropbox::SpaceUsage.new({
41+
'used' => 1,
42+
'allocation' => {'.tag' => 'team', 'allocated' => 2}
43+
})
44+
45+
assert_equal 1, usage.used
46+
assert_equal 'team', usage.allocation
47+
assert_equal 2, usage.allocated
48+
end
3849
end

test/test_users.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,12 @@ def test_get_current_account
4545
assert_equal false, account.disabled
4646
end
4747

48+
def test_get_space_usage
49+
usage = @client.get_space_usage
50+
51+
assert usage.used.is_a?(Integer)
52+
assert_equal 'individual', usage.allocation
53+
assert usage.allocated.is_a?(Integer)
54+
end
55+
4856
end

0 commit comments

Comments
 (0)