Class: ContextIO::Account
- Inherits:
-
Resource
- Object
- Resource
- ContextIO::Account
- Defined in:
- lib/context-io/account.rb
Overview
An account. Create one of these for every user.
This does not represent a mail account. An Account can have several mail accounts attached to it as Sources.
Only the #first_name and #last_name can be changed after creation.
Instance Attribute Summary (collapse)
-
- (Time) created
readonly
The account creation time.
-
- (Array<String>) email_addresses
readonly
The email addresses associated with the account.
-
- (String) first_name
The first name of the account holder.
-
- (String) id
readonly
The unique ID of the account.
-
- (String) last_name
The last name of the account holder.
-
- (Time?) password_expired
readonly
When the account password expired, or nil if the password hasn't expired.
-
- (Array<ContextIO::Source>) sources
readonly
The sources associated with this account.
-
- (Time?) suspended
readonly
The account suspension time, or nil if the account isn't suspended.
-
- (String) username
readonly
The username assigned to the account.
Class Method Summary (collapse)
-
+ (Array<ContextIO::Account>) all(query = {})
Get all the accounts, optionally filtered with a query.
-
+ (ContextIO::Account) find(id)
Find an account given its ID.
-
+ (Account) from_json(json)
private
Create an Account instance from the JSON returned by the Context.IO server.
Instance Method Summary (collapse)
-
- (Account) initialize(attributes = {})
constructor
Initialize an Account.
-
- (true, false) save
Send the account info to Context.IO.
-
- (void) sync!
Trigger a sync of all sources on the account.
-
- (Hash) sync_info
Get information about the last time mailboxes in this account were synced.
-
- (true, false) update_attributes(attributes)
Update attributes on the account object and then send them to Context.IO.
Methods included from Request
#delete, #get, #post, #put, #request
Constructor Details
- (Account) initialize(attributes = {})
Initialize an Account
116 117 118 119 120 |
# File 'lib/context-io/account.rb', line 116 def initialize(attributes={}) @email_addresses = [attributes[:email]] if attributes[:email] @first_name = attributes[:first_name] @last_name = attributes[:last_name] end |
Instance Attribute Details
- (Time) created (readonly)
The account creation time.
21 22 23 |
# File 'lib/context-io/account.rb', line 21 def created @created end |
- (Array<String>) email_addresses (readonly)
The email addresses associated with the account.
30 31 32 |
# File 'lib/context-io/account.rb', line 30 def email_addresses @email_addresses end |
- (String) first_name
The first name of the account holder.
34 35 36 |
# File 'lib/context-io/account.rb', line 34 def first_name @first_name end |
- (String) id (readonly)
The unique ID of the account.
13 14 15 |
# File 'lib/context-io/account.rb', line 13 def id @id end |
- (String) last_name
The last name of the account holder.
38 39 40 |
# File 'lib/context-io/account.rb', line 38 def last_name @last_name end |
- (Time?) password_expired (readonly)
When the account password expired, or nil if the password hasn't expired.
43 44 45 |
# File 'lib/context-io/account.rb', line 43 def password_expired @password_expired end |
- (Array<ContextIO::Source>) sources (readonly)
The sources associated with this account.
48 49 50 |
# File 'lib/context-io/account.rb', line 48 def sources @sources end |
- (Time?) suspended (readonly)
The account suspension time, or nil if the account isn't suspended.
26 27 28 |
# File 'lib/context-io/account.rb', line 26 def suspended @suspended end |
- (String) username (readonly)
The username assigned to the account.
17 18 19 |
# File 'lib/context-io/account.rb', line 17 def username @username end |
Class Method Details
+ (Array<ContextIO::Account>) all(query = {})
Get all the accounts, optionally filtered with a query
79 80 81 82 83 84 85 |
# File 'lib/context-io/account.rb', line 79 def self.all(query={}) query[:status] = query[:status].to_s.upcase if query[:status] if query.has_key?(:status_ok) query[:status_ok] = query[:status_ok] ? '1' : '0' end get('/2.0/accounts', query).map { |account| from_json(account) } end |
+ (ContextIO::Account) find(id)
Find an account given its ID
97 98 99 |
# File 'lib/context-io/account.rb', line 97 def self.find(id) from_json(get("/2.0/accounts/#{id}")) end |
+ (Account) from_json(json)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create an Account instance from the JSON returned by the Context.IO server
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/context-io/account.rb', line 260 def self.from_json(json) account = new account.instance_eval do @id = json['id'] @username = json['username'] if json['created'] == 0 @created = nil else @created = Time.at(json['created']) end if json['suspended'] == 0 @suspended = nil else @suspended = Time.at(json['suspended']) end @email_addresses = json['email_addresses'] @first_name = json['first_name'] @last_name = json['last_name'] if json['password_expired'] == 0 @password_expired = nil else @password_expired = json['password_expired'] end @sources = json['sources'].map do |source| Source.from_json(@id, source) end end account end |
Instance Method Details
- (true, false) save
Send the account info to Context.IO
If this is the first time the account is sent to Context.IO, the first email address set will be sent as the primary email address, and the first and last name will be sent if they are specified. You are required to specify one email address.
If the account has been sent to Context.IO before, this will update the first and last name.
142 143 144 |
# File 'lib/context-io/account.rb', line 142 def save id ? update_record : create_record end |
- (void) sync!
This call is metered and charged for each source with basic service level. See Context.IO's pricing page for details.
This method returns an undefined value.
Trigger a sync of all sources on the account
205 206 207 |
# File 'lib/context-io/account.rb', line 205 def sync! post("/2.0/accounts/#{self.id}/sync") end |
- (Hash) sync_info
Get information about the last time mailboxes in this account were synced
The timestamps are unix timestamps (seconds since the epoch). Feed them
into Time.at to get a Time object.
192 193 194 |
# File 'lib/context-io/account.rb', line 192 def sync_info get("/2.0/accounts/#{self.id}/sync") end |
- (true, false) update_attributes(attributes)
Update attributes on the account object and then send them to Context.IO
160 161 162 163 164 165 166 167 |
# File 'lib/context-io/account.rb', line 160 def update_attributes(attributes) @first_name = attributes[:first_name] if attributes[:first_name] @last_name = attributes[:last_name] if attributes[:last_name] response = put("/2.0/accounts/#{self.id}", attributes) response['success'] end |