Class: ContextIO::Account
Instance Attribute Summary collapse
#api_attributes, #primary_key, #resource_url
Instance Method Summary
collapse
Instance Attribute Details
#created_at ⇒ Object
54
55
56
|
# File 'lib/contextio/account.rb', line 54
def created_at
@created_at ||= Time.at(created)
end
|
#first_name ⇒ String
Returns The account holder's first name.
28
29
|
# File 'lib/contextio/account.rb', line 28
lazy_attributes :id, :username, :created, :suspended, :first_name,
:last_name, :password_expired, :nb_messages, :nb_files
|
#id ⇒ String
Returns The id assigned to this account by Context.IO.
28
29
|
# File 'lib/contextio/account.rb', line 28
lazy_attributes :id, :username, :created, :suspended, :first_name,
:last_name, :password_expired, :nb_messages, :nb_files
|
#last_name ⇒ String
Returns The account holder's last name.
28
29
|
# File 'lib/contextio/account.rb', line 28
lazy_attributes :id, :username, :created, :suspended, :first_name,
:last_name, :password_expired, :nb_messages, :nb_files
|
#password_expired? ⇒ Boolean
86
87
88
|
# File 'lib/contextio/account.rb', line 86
def password_expired?
!!password_expired_at
end
|
#password_expired_at ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/contextio/account.rb', line 76
def password_expired_at
return @password_expired_at if instance_variable_defined?(:@password_expired_at)
@password_expired_at = password_expired == 0 ? nil : Time.at(password_expired)
@password_expired_at
end
|
#suspended? ⇒ Boolean
70
71
72
|
# File 'lib/contextio/account.rb', line 70
def suspended?
!!suspended_at
end
|
#suspended_at ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/contextio/account.rb', line 60
def suspended_at
return @suspended_at if instance_variable_defined?(:@suspended_at)
@suspended_at = suspended == 0 ? nil : Time.at(suspended)
@suspended_at
end
|
#username ⇒ String
Returns The username assigned to this account by Context.IO.
28
29
|
# File 'lib/contextio/account.rb', line 28
lazy_attributes :id, :username, :created, :suspended, :first_name,
:last_name, :password_expired, :nb_messages, :nb_files
|
Instance Method Details
#delete ⇒ Object
128
129
130
|
# File 'lib/contextio/account.rb', line 128
def delete
api.request(:delete, resource_url)['success']
end
|
#email_addresses ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/contextio/account.rb', line 32
def email_addresses
@email_addresses = nil if @email_addresses.is_a?(Array)
return @email_addresses if @email_addresses
association_class = ContextIO::API::AssociationHelpers.class_for_association_name(:email_addresses)
reconstructed_email_hashes = api_attributes['email_addresses'].collect do |addy|
{'email' => addy}
end
@email_addresses = association_class.new(
api,
self.class.association_name => self,
attribute_hashes: reconstructed_email_hashes
)
end
|
#sync!(options = {}) ⇒ Object
124
125
126
|
# File 'lib/contextio/account.rb', line 124
def sync!(options={})
api.request(:post, "#{resource_url}/sync", options)['success']
end
|
#sync_data ⇒ Object
114
115
116
117
118
119
120
121
122
|
# File 'lib/contextio/account.rb', line 114
def sync_data
return @sync_data if @sync_data
sync_hashes = api.request(:get, "#{resource_url}/sync")
@sync_data = ContextIO::AccountSyncData.new(sync_hashes)
return @sync_data
end
|
#update(options = {}) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/contextio/account.rb', line 94
def update(options={})
first_name = options[:first_name] || options['first_name']
last_name = options[:last_name] || options['last_name']
attrs = {}
attrs[:first_name] = first_name if first_name
attrs[:last_name] = last_name if last_name
return nil if attrs.empty?
it_worked = api.request(:post, resource_url, attrs)['success']
if it_worked
@first_name = first_name || @first_name
@last_name = last_name || @last_name
end
it_worked
end
|