Class: Rallio::User

Inherits:
Base
  • Object
show all
Defined in:
lib/rallio/user.rb

Overview

Represents a user object as it comes from Rallio.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

app_credentials

Instance Attribute Details

#access_tokenRallio::AccessToken

Creates or returns the API access token for user. NOTE: These tokens do not expire so it is suggested (recommended) that the token be cached and reused whenever possible.

Returns:

See Also:



67
68
69
# File 'lib/rallio/user.rb', line 67

def access_token
  @access_token ||= AccessToken.create(user_id: id)
end

#accountsArray<Rallio::Account>

Returns accounts user has access to.

Returns:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rallio/user.rb', line 18

class User < Base
  attribute :id, Integer
  attribute :email, String
  attribute :first_name, String
  attribute :last_name, String
  attribute :name, String
  attribute :accounts, Array[Account]
  attribute :franchisors, Array[Franchisor]

  attr_writer :access_token

  # Lists accessible users on Rallio's platform for application.
  #
  # @return [Array<Rallio::User>] array of users accessible to application
  def self.accessible_users
    response = self.get('/accessible_users', headers: app_credentials)
    response.parsed_response['users'].map { |u| new u }
  end

  # Create a user on the Rallio platform.
  #
  # @param user [Hash] user info used to create new user
  # @option user [String] :email unique email address
  # @option user [String] :first_name
  # @option user [String] :last_name
  # @return [Rallio::User] user object that was just created
  def self.create(user:)
    response = self.post('/users', headers: app_credentials, body: { user: user })
    new response.parsed_response['user']
  end

  # Creates new single signon for user to be redirected to.
  # @see Rallio::SignOnToken
  #
  # @param params [Hash] optional uri params sent with request
  # @option params [String] :connect_account_id account id to display social
  #   connections for
  # @return [Rallio::SignOnToken]
  def sign_on_token(params: {})
    SignOnToken.create(user_id: id, params: params)
  end

  # Creates or returns the API access token for user.
  # @see Rallio::AccessToken
  #
  # NOTE: These tokens do not expire so it is suggested (recommended) that the
  # token be cached and reused whenever possible.
  #
  # @return [Rallio::AccessToken]
  def access_token
    @access_token ||= AccessToken.create(user_id: id)
  end

  # Retreives account ownerships for user.
  # @see Rallio::AccountOwnership
  #
  # @return [Array<Rallio::AccountOwnership>] array of user's account ownerships
  def 
    AccountOwnership.for(access_token: access_token.access_token)
  end

  # Retreives franchisor ownerships for user.
  # @see Rallio::FranchisorOwnership
  #
  # @return [Array<Rallio::FranchisorOwnership>] array of user's franchisor ownerships
  def franchisor_ownerships
    FranchisorOwnership.for(access_token: access_token.access_token)
  end

  # Retreives current data for user.
  #
  # @return [Rallio::User]
  def dashboard
    response = self.class.get('/dashboard', headers: user_credentials)
    self.attributes = response.parsed_response['me']
    self.accounts = response.parsed_response['accounts']
    self.franchisors = response.parsed_response['franchisors']
    self
  end

  private

  def user_credentials
    {
      'Authorization' => "Bearer #{access_token.access_token}"
    }
  end
end

#emailString

Returns user email.

Returns:

  • (String)

    user email



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rallio/user.rb', line 18

class User < Base
  attribute :id, Integer
  attribute :email, String
  attribute :first_name, String
  attribute :last_name, String
  attribute :name, String
  attribute :accounts, Array[Account]
  attribute :franchisors, Array[Franchisor]

  attr_writer :access_token

  # Lists accessible users on Rallio's platform for application.
  #
  # @return [Array<Rallio::User>] array of users accessible to application
  def self.accessible_users
    response = self.get('/accessible_users', headers: app_credentials)
    response.parsed_response['users'].map { |u| new u }
  end

  # Create a user on the Rallio platform.
  #
  # @param user [Hash] user info used to create new user
  # @option user [String] :email unique email address
  # @option user [String] :first_name
  # @option user [String] :last_name
  # @return [Rallio::User] user object that was just created
  def self.create(user:)
    response = self.post('/users', headers: app_credentials, body: { user: user })
    new response.parsed_response['user']
  end

  # Creates new single signon for user to be redirected to.
  # @see Rallio::SignOnToken
  #
  # @param params [Hash] optional uri params sent with request
  # @option params [String] :connect_account_id account id to display social
  #   connections for
  # @return [Rallio::SignOnToken]
  def sign_on_token(params: {})
    SignOnToken.create(user_id: id, params: params)
  end

  # Creates or returns the API access token for user.
  # @see Rallio::AccessToken
  #
  # NOTE: These tokens do not expire so it is suggested (recommended) that the
  # token be cached and reused whenever possible.
  #
  # @return [Rallio::AccessToken]
  def access_token
    @access_token ||= AccessToken.create(user_id: id)
  end

  # Retreives account ownerships for user.
  # @see Rallio::AccountOwnership
  #
  # @return [Array<Rallio::AccountOwnership>] array of user's account ownerships
  def 
    AccountOwnership.for(access_token: access_token.access_token)
  end

  # Retreives franchisor ownerships for user.
  # @see Rallio::FranchisorOwnership
  #
  # @return [Array<Rallio::FranchisorOwnership>] array of user's franchisor ownerships
  def franchisor_ownerships
    FranchisorOwnership.for(access_token: access_token.access_token)
  end

  # Retreives current data for user.
  #
  # @return [Rallio::User]
  def dashboard
    response = self.class.get('/dashboard', headers: user_credentials)
    self.attributes = response.parsed_response['me']
    self.accounts = response.parsed_response['accounts']
    self.franchisors = response.parsed_response['franchisors']
    self
  end

  private

  def user_credentials
    {
      'Authorization' => "Bearer #{access_token.access_token}"
    }
  end
end

#first_nameString

Returns user first name.

Returns:

  • (String)

    user first name



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rallio/user.rb', line 18

class User < Base
  attribute :id, Integer
  attribute :email, String
  attribute :first_name, String
  attribute :last_name, String
  attribute :name, String
  attribute :accounts, Array[Account]
  attribute :franchisors, Array[Franchisor]

  attr_writer :access_token

  # Lists accessible users on Rallio's platform for application.
  #
  # @return [Array<Rallio::User>] array of users accessible to application
  def self.accessible_users
    response = self.get('/accessible_users', headers: app_credentials)
    response.parsed_response['users'].map { |u| new u }
  end

  # Create a user on the Rallio platform.
  #
  # @param user [Hash] user info used to create new user
  # @option user [String] :email unique email address
  # @option user [String] :first_name
  # @option user [String] :last_name
  # @return [Rallio::User] user object that was just created
  def self.create(user:)
    response = self.post('/users', headers: app_credentials, body: { user: user })
    new response.parsed_response['user']
  end

  # Creates new single signon for user to be redirected to.
  # @see Rallio::SignOnToken
  #
  # @param params [Hash] optional uri params sent with request
  # @option params [String] :connect_account_id account id to display social
  #   connections for
  # @return [Rallio::SignOnToken]
  def sign_on_token(params: {})
    SignOnToken.create(user_id: id, params: params)
  end

  # Creates or returns the API access token for user.
  # @see Rallio::AccessToken
  #
  # NOTE: These tokens do not expire so it is suggested (recommended) that the
  # token be cached and reused whenever possible.
  #
  # @return [Rallio::AccessToken]
  def access_token
    @access_token ||= AccessToken.create(user_id: id)
  end

  # Retreives account ownerships for user.
  # @see Rallio::AccountOwnership
  #
  # @return [Array<Rallio::AccountOwnership>] array of user's account ownerships
  def 
    AccountOwnership.for(access_token: access_token.access_token)
  end

  # Retreives franchisor ownerships for user.
  # @see Rallio::FranchisorOwnership
  #
  # @return [Array<Rallio::FranchisorOwnership>] array of user's franchisor ownerships
  def franchisor_ownerships
    FranchisorOwnership.for(access_token: access_token.access_token)
  end

  # Retreives current data for user.
  #
  # @return [Rallio::User]
  def dashboard
    response = self.class.get('/dashboard', headers: user_credentials)
    self.attributes = response.parsed_response['me']
    self.accounts = response.parsed_response['accounts']
    self.franchisors = response.parsed_response['franchisors']
    self
  end

  private

  def user_credentials
    {
      'Authorization' => "Bearer #{access_token.access_token}"
    }
  end
end

#franchisorsArray<Rallio::Franchisor>

Returns franchisors user has access to.

Returns:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rallio/user.rb', line 18

class User < Base
  attribute :id, Integer
  attribute :email, String
  attribute :first_name, String
  attribute :last_name, String
  attribute :name, String
  attribute :accounts, Array[Account]
  attribute :franchisors, Array[Franchisor]

  attr_writer :access_token

  # Lists accessible users on Rallio's platform for application.
  #
  # @return [Array<Rallio::User>] array of users accessible to application
  def self.accessible_users
    response = self.get('/accessible_users', headers: app_credentials)
    response.parsed_response['users'].map { |u| new u }
  end

  # Create a user on the Rallio platform.
  #
  # @param user [Hash] user info used to create new user
  # @option user [String] :email unique email address
  # @option user [String] :first_name
  # @option user [String] :last_name
  # @return [Rallio::User] user object that was just created
  def self.create(user:)
    response = self.post('/users', headers: app_credentials, body: { user: user })
    new response.parsed_response['user']
  end

  # Creates new single signon for user to be redirected to.
  # @see Rallio::SignOnToken
  #
  # @param params [Hash] optional uri params sent with request
  # @option params [String] :connect_account_id account id to display social
  #   connections for
  # @return [Rallio::SignOnToken]
  def sign_on_token(params: {})
    SignOnToken.create(user_id: id, params: params)
  end

  # Creates or returns the API access token for user.
  # @see Rallio::AccessToken
  #
  # NOTE: These tokens do not expire so it is suggested (recommended) that the
  # token be cached and reused whenever possible.
  #
  # @return [Rallio::AccessToken]
  def access_token
    @access_token ||= AccessToken.create(user_id: id)
  end

  # Retreives account ownerships for user.
  # @see Rallio::AccountOwnership
  #
  # @return [Array<Rallio::AccountOwnership>] array of user's account ownerships
  def 
    AccountOwnership.for(access_token: access_token.access_token)
  end

  # Retreives franchisor ownerships for user.
  # @see Rallio::FranchisorOwnership
  #
  # @return [Array<Rallio::FranchisorOwnership>] array of user's franchisor ownerships
  def franchisor_ownerships
    FranchisorOwnership.for(access_token: access_token.access_token)
  end

  # Retreives current data for user.
  #
  # @return [Rallio::User]
  def dashboard
    response = self.class.get('/dashboard', headers: user_credentials)
    self.attributes = response.parsed_response['me']
    self.accounts = response.parsed_response['accounts']
    self.franchisors = response.parsed_response['franchisors']
    self
  end

  private

  def user_credentials
    {
      'Authorization' => "Bearer #{access_token.access_token}"
    }
  end
end

#idInteger

Returns unique id for user.

Returns:

  • (Integer)

    unique id for user



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rallio/user.rb', line 18

class User < Base
  attribute :id, Integer
  attribute :email, String
  attribute :first_name, String
  attribute :last_name, String
  attribute :name, String
  attribute :accounts, Array[Account]
  attribute :franchisors, Array[Franchisor]

  attr_writer :access_token

  # Lists accessible users on Rallio's platform for application.
  #
  # @return [Array<Rallio::User>] array of users accessible to application
  def self.accessible_users
    response = self.get('/accessible_users', headers: app_credentials)
    response.parsed_response['users'].map { |u| new u }
  end

  # Create a user on the Rallio platform.
  #
  # @param user [Hash] user info used to create new user
  # @option user [String] :email unique email address
  # @option user [String] :first_name
  # @option user [String] :last_name
  # @return [Rallio::User] user object that was just created
  def self.create(user:)
    response = self.post('/users', headers: app_credentials, body: { user: user })
    new response.parsed_response['user']
  end

  # Creates new single signon for user to be redirected to.
  # @see Rallio::SignOnToken
  #
  # @param params [Hash] optional uri params sent with request
  # @option params [String] :connect_account_id account id to display social
  #   connections for
  # @return [Rallio::SignOnToken]
  def sign_on_token(params: {})
    SignOnToken.create(user_id: id, params: params)
  end

  # Creates or returns the API access token for user.
  # @see Rallio::AccessToken
  #
  # NOTE: These tokens do not expire so it is suggested (recommended) that the
  # token be cached and reused whenever possible.
  #
  # @return [Rallio::AccessToken]
  def access_token
    @access_token ||= AccessToken.create(user_id: id)
  end

  # Retreives account ownerships for user.
  # @see Rallio::AccountOwnership
  #
  # @return [Array<Rallio::AccountOwnership>] array of user's account ownerships
  def 
    AccountOwnership.for(access_token: access_token.access_token)
  end

  # Retreives franchisor ownerships for user.
  # @see Rallio::FranchisorOwnership
  #
  # @return [Array<Rallio::FranchisorOwnership>] array of user's franchisor ownerships
  def franchisor_ownerships
    FranchisorOwnership.for(access_token: access_token.access_token)
  end

  # Retreives current data for user.
  #
  # @return [Rallio::User]
  def dashboard
    response = self.class.get('/dashboard', headers: user_credentials)
    self.attributes = response.parsed_response['me']
    self.accounts = response.parsed_response['accounts']
    self.franchisors = response.parsed_response['franchisors']
    self
  end

  private

  def user_credentials
    {
      'Authorization' => "Bearer #{access_token.access_token}"
    }
  end
end

#last_nameString

Returns user last name.

Returns:

  • (String)

    user last name



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rallio/user.rb', line 18

class User < Base
  attribute :id, Integer
  attribute :email, String
  attribute :first_name, String
  attribute :last_name, String
  attribute :name, String
  attribute :accounts, Array[Account]
  attribute :franchisors, Array[Franchisor]

  attr_writer :access_token

  # Lists accessible users on Rallio's platform for application.
  #
  # @return [Array<Rallio::User>] array of users accessible to application
  def self.accessible_users
    response = self.get('/accessible_users', headers: app_credentials)
    response.parsed_response['users'].map { |u| new u }
  end

  # Create a user on the Rallio platform.
  #
  # @param user [Hash] user info used to create new user
  # @option user [String] :email unique email address
  # @option user [String] :first_name
  # @option user [String] :last_name
  # @return [Rallio::User] user object that was just created
  def self.create(user:)
    response = self.post('/users', headers: app_credentials, body: { user: user })
    new response.parsed_response['user']
  end

  # Creates new single signon for user to be redirected to.
  # @see Rallio::SignOnToken
  #
  # @param params [Hash] optional uri params sent with request
  # @option params [String] :connect_account_id account id to display social
  #   connections for
  # @return [Rallio::SignOnToken]
  def sign_on_token(params: {})
    SignOnToken.create(user_id: id, params: params)
  end

  # Creates or returns the API access token for user.
  # @see Rallio::AccessToken
  #
  # NOTE: These tokens do not expire so it is suggested (recommended) that the
  # token be cached and reused whenever possible.
  #
  # @return [Rallio::AccessToken]
  def access_token
    @access_token ||= AccessToken.create(user_id: id)
  end

  # Retreives account ownerships for user.
  # @see Rallio::AccountOwnership
  #
  # @return [Array<Rallio::AccountOwnership>] array of user's account ownerships
  def 
    AccountOwnership.for(access_token: access_token.access_token)
  end

  # Retreives franchisor ownerships for user.
  # @see Rallio::FranchisorOwnership
  #
  # @return [Array<Rallio::FranchisorOwnership>] array of user's franchisor ownerships
  def franchisor_ownerships
    FranchisorOwnership.for(access_token: access_token.access_token)
  end

  # Retreives current data for user.
  #
  # @return [Rallio::User]
  def dashboard
    response = self.class.get('/dashboard', headers: user_credentials)
    self.attributes = response.parsed_response['me']
    self.accounts = response.parsed_response['accounts']
    self.franchisors = response.parsed_response['franchisors']
    self
  end

  private

  def user_credentials
    {
      'Authorization' => "Bearer #{access_token.access_token}"
    }
  end
end

#nameString

Returns full name if available.

Returns:

  • (String)

    full name if available



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rallio/user.rb', line 18

class User < Base
  attribute :id, Integer
  attribute :email, String
  attribute :first_name, String
  attribute :last_name, String
  attribute :name, String
  attribute :accounts, Array[Account]
  attribute :franchisors, Array[Franchisor]

  attr_writer :access_token

  # Lists accessible users on Rallio's platform for application.
  #
  # @return [Array<Rallio::User>] array of users accessible to application
  def self.accessible_users
    response = self.get('/accessible_users', headers: app_credentials)
    response.parsed_response['users'].map { |u| new u }
  end

  # Create a user on the Rallio platform.
  #
  # @param user [Hash] user info used to create new user
  # @option user [String] :email unique email address
  # @option user [String] :first_name
  # @option user [String] :last_name
  # @return [Rallio::User] user object that was just created
  def self.create(user:)
    response = self.post('/users', headers: app_credentials, body: { user: user })
    new response.parsed_response['user']
  end

  # Creates new single signon for user to be redirected to.
  # @see Rallio::SignOnToken
  #
  # @param params [Hash] optional uri params sent with request
  # @option params [String] :connect_account_id account id to display social
  #   connections for
  # @return [Rallio::SignOnToken]
  def sign_on_token(params: {})
    SignOnToken.create(user_id: id, params: params)
  end

  # Creates or returns the API access token for user.
  # @see Rallio::AccessToken
  #
  # NOTE: These tokens do not expire so it is suggested (recommended) that the
  # token be cached and reused whenever possible.
  #
  # @return [Rallio::AccessToken]
  def access_token
    @access_token ||= AccessToken.create(user_id: id)
  end

  # Retreives account ownerships for user.
  # @see Rallio::AccountOwnership
  #
  # @return [Array<Rallio::AccountOwnership>] array of user's account ownerships
  def 
    AccountOwnership.for(access_token: access_token.access_token)
  end

  # Retreives franchisor ownerships for user.
  # @see Rallio::FranchisorOwnership
  #
  # @return [Array<Rallio::FranchisorOwnership>] array of user's franchisor ownerships
  def franchisor_ownerships
    FranchisorOwnership.for(access_token: access_token.access_token)
  end

  # Retreives current data for user.
  #
  # @return [Rallio::User]
  def dashboard
    response = self.class.get('/dashboard', headers: user_credentials)
    self.attributes = response.parsed_response['me']
    self.accounts = response.parsed_response['accounts']
    self.franchisors = response.parsed_response['franchisors']
    self
  end

  private

  def user_credentials
    {
      'Authorization' => "Bearer #{access_token.access_token}"
    }
  end
end

Class Method Details

.accessible_usersArray<Rallio::User>

Lists accessible users on Rallio’s platform for application.

Returns:

  • (Array<Rallio::User>)

    array of users accessible to application



32
33
34
35
# File 'lib/rallio/user.rb', line 32

def self.accessible_users
  response = self.get('/accessible_users', headers: app_credentials)
  response.parsed_response['users'].map { |u| new u }
end

.create(user:) ⇒ Rallio::User

Create a user on the Rallio platform.

Parameters:

  • user (Hash)

    user info used to create new user

Options Hash (user:):

  • :email (String)

    unique email address

  • :first_name (String)
  • :last_name (String)

Returns:



44
45
46
47
# File 'lib/rallio/user.rb', line 44

def self.create(user:)
  response = self.post('/users', headers: app_credentials, body: { user: user })
  new response.parsed_response['user']
end

Instance Method Details

#account_ownershipsArray<Rallio::AccountOwnership>

Retreives account ownerships for user.

Returns:

See Also:



75
76
77
# File 'lib/rallio/user.rb', line 75

def 
  AccountOwnership.for(access_token: access_token.access_token)
end

#dashboardRallio::User

Retreives current data for user.

Returns:



90
91
92
93
94
95
96
# File 'lib/rallio/user.rb', line 90

def dashboard
  response = self.class.get('/dashboard', headers: user_credentials)
  self.attributes = response.parsed_response['me']
  self.accounts = response.parsed_response['accounts']
  self.franchisors = response.parsed_response['franchisors']
  self
end

#franchisor_ownershipsArray<Rallio::FranchisorOwnership>

Retreives franchisor ownerships for user.

Returns:

See Also:



83
84
85
# File 'lib/rallio/user.rb', line 83

def franchisor_ownerships
  FranchisorOwnership.for(access_token: access_token.access_token)
end

#sign_on_token(params: {}) ⇒ Rallio::SignOnToken

Creates new single signon for user to be redirected to.

Parameters:

  • params (Hash) (defaults to: {})

    optional uri params sent with request

Options Hash (params:):

  • :connect_account_id (String)

    account id to display social connections for

Returns:

See Also:



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

def sign_on_token(params: {})
  SignOnToken.create(user_id: id, params: params)
end