Class: ContextIO::Lite::User

Inherits:
Object
  • Object
show all
Includes:
API::Resource
Defined in:
lib/contextio/lite/user.rb

Instance Attribute Summary collapse

Attributes included from API::Resource

#api, #api_attributes, #primary_key, #resource_url, #with_constraints

Instance Method Summary collapse

Methods included from API::Resource

#initialize, #with

Instance Attribute Details

#created_atObject (readonly)



28
29
30
# File 'lib/contextio/lite/user.rb', line 28

def created_at
  @created_at ||= Time.at(created)
end

#first_nameString (readonly)

Returns The account holder’s first name.

Returns:

  • (String)

    The account holder’s first name.



23
# File 'lib/contextio/lite/user.rb', line 23

lazy_attributes :id, :email_addresses, :username, :created, :first_name, :last_name

#idString (readonly)

Returns The id assigned to this account by Context.IO.

Returns:

  • (String)

    The id assigned to this account by Context.IO.



23
# File 'lib/contextio/lite/user.rb', line 23

lazy_attributes :id, :email_addresses, :username, :created, :first_name, :last_name

#last_nameString (readonly)

Returns The account holder’s last name.

Returns:

  • (String)

    The account holder’s last name.



23
# File 'lib/contextio/lite/user.rb', line 23

lazy_attributes :id, :email_addresses, :username, :created, :first_name, :last_name

#usernameString (readonly)

Returns The username assigned to this account by Context.IO.

Returns:

  • (String)

    The username assigned to this account by Context.IO.



23
# File 'lib/contextio/lite/user.rb', line 23

lazy_attributes :id, :email_addresses, :username, :created, :first_name, :last_name

Instance Method Details

#deleteObject



56
57
58
# File 'lib/contextio/lite/user.rb', line 56

def delete
  api.request(:delete, resource_url)['success']
end

#update(options = {}) ⇒ Object

Updates the account.

Parameters:

  • options (Hash{String, Symbol => String}) (defaults to: {})

    You can update first_name or last_name (or both).



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/contextio/lite/user.rb', line 36

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