forked from waits/dropbox-sdk-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
get_account
and get_current_account
methods
- Loading branch information
Showing
5 changed files
with
127 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Dropbox | ||
class Account | ||
attr_reader :account_id, :display_name, :email, :email_verified, :disabled, :profile_photo_url | ||
|
||
def initialize(attrs={}) | ||
@account_id = attrs['account_id'] | ||
@display_name = attrs['name']['display_name'] | ||
@email = attrs['email'] | ||
@email_verified = attrs['email_verified'] | ||
@disabled = attrs['disabled'] | ||
@profile_photo_url = attrs['profile_photo_url'] | ||
end | ||
end | ||
|
||
class BasicAccount < Account | ||
attr_reader :is_teammate, :team_member_id | ||
|
||
def initialize(attrs={}) | ||
@is_teammate = attrs.delete('is_teammate') | ||
@team_member_id = attrs.delete('team_member_id') | ||
super(attrs) | ||
end | ||
end | ||
|
||
class FullAccount < Account | ||
attr_reader :locale, :referral_link, :is_paired, :profile_photo_url, :country | ||
|
||
def initialize(attrs={}) | ||
@locale = attrs.delete('locale') | ||
@referral_link = attrs.delete('referral_link') | ||
@is_paired = attrs.delete('is_paired') | ||
@profile_photo_url = attrs.delete('profile_photo_url') | ||
@country = attrs.delete('country') | ||
super(attrs) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'minitest/autorun' | ||
require 'dropbox' | ||
|
||
class DropboxAccountTest < Minitest::Test | ||
def test_basic_account_initialize | ||
account = Dropbox::BasicAccount.new({ | ||
'account_id' => 'id:123', | ||
'name' => {'display_name' => 'John Smith'}, | ||
'email' => 'email@example.com', | ||
'email_verified' => true, | ||
'disabled' => false, | ||
'profile_photo_url' => 'http://example.com' | ||
}) | ||
|
||
assert_equal 'id:123', account.account_id | ||
assert_equal 'John Smith', account.display_name | ||
assert_equal true, account.email_verified | ||
assert_equal false, account.disabled | ||
end | ||
|
||
def test_full_account_initialize | ||
account = Dropbox::FullAccount.new({ | ||
'account_id' => 'id:123', | ||
'name' => {'display_name' => 'John Smith'}, | ||
'email' => 'email@example.com', | ||
'email_verified' => true, | ||
'is_paired' => true, | ||
'disabled' => false, | ||
'profile_photo_url' => 'http://example.com' | ||
}) | ||
|
||
assert_equal 'id:123', account.account_id | ||
assert_equal 'John Smith', account.display_name | ||
assert_equal true, account.email_verified | ||
assert_equal false, account.disabled | ||
assert_equal true, account.is_paired | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'minitest/autorun' | ||
require 'dropbox' | ||
|
||
class DropboxUsersTest < Minitest::Test | ||
def setup | ||
@client = Dropbox::Client.new(ENV['DROPBOX_SDK_ACCESS_TOKEN']) | ||
end | ||
|
||
def test_get_account | ||
id = @client.get_current_account.account_id | ||
account = @client.get_account(id) | ||
|
||
assert account.is_a?(Dropbox::BasicAccount) | ||
assert_equal id, account.account_id | ||
end | ||
|
||
def test_get_account_error | ||
assert_raises(Dropbox::APIError) do | ||
@client.get_account('invalid_id') | ||
end | ||
end | ||
|
||
def test_get_current_account | ||
account = @client.get_current_account | ||
|
||
assert account.is_a?(Dropbox::FullAccount) | ||
assert_match /^dbid:[a-z0-9_-]+$/i, account.account_id | ||
assert_equal 'Dylan Waits', account.display_name | ||
assert_equal true, account.email_verified | ||
assert_equal false, account.disabled | ||
end | ||
|
||
end |