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.

See Also:


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

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

#emailString


12
13
14
15
16
17
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
# File 'lib/rallio/user.rb', line 12

class User < Base
  attribute :id, Integer
  attribute :email, String
  attribute :first_name, String
  attribute :last_name, String
  attribute :accounts, Array[]
  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
  #
  # @return [Rallio::SignOnToken]
  def sign_on_token
    SignOnToken.create(user_id: id)
  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
    self
  end

  private

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

#first_nameString


12
13
14
15
16
17
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
# File 'lib/rallio/user.rb', line 12

class User < Base
  attribute :id, Integer
  attribute :email, String
  attribute :first_name, String
  attribute :last_name, String
  attribute :accounts, Array[]
  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
  #
  # @return [Rallio::SignOnToken]
  def sign_on_token
    SignOnToken.create(user_id: id)
  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
    self
  end

  private

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

#idInteger


12
13
14
15
16
17
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
# File 'lib/rallio/user.rb', line 12

class User < Base
  attribute :id, Integer
  attribute :email, String
  attribute :first_name, String
  attribute :last_name, String
  attribute :accounts, Array[]
  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
  #
  # @return [Rallio::SignOnToken]
  def sign_on_token
    SignOnToken.create(user_id: id)
  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
    self
  end

  private

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

#last_nameString


12
13
14
15
16
17
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
# File 'lib/rallio/user.rb', line 12

class User < Base
  attribute :id, Integer
  attribute :email, String
  attribute :first_name, String
  attribute :last_name, String
  attribute :accounts, Array[]
  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
  #
  # @return [Rallio::SignOnToken]
  def sign_on_token
    SignOnToken.create(user_id: id)
  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
    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.


25
26
27
28
# File 'lib/rallio/user.rb', line 25

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.

Options Hash (user:):

  • :email (String)

    unique email address

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

37
38
39
40
# File 'lib/rallio/user.rb', line 37

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.

See Also:


65
66
67
# File 'lib/rallio/user.rb', line 65

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

#dashboardRallio::User

Retreives current data for user.


80
81
82
83
84
# File 'lib/rallio/user.rb', line 80

def dashboard
  response = self.class.get('/dashboard', headers: user_credentials)
  self.attributes = response.parsed_response
  self
end

#franchisor_ownershipsArray<Rallio::FranchisorOwnership>

Retreives franchisor ownerships for user.


73
74
75
# File 'lib/rallio/user.rb', line 73

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

#sign_on_tokenRallio::SignOnToken

Creates new single signon for user to be redirected to.

See Also:


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

def sign_on_token
  SignOnToken.create(user_id: id)
end