Class: Talis::User
Overview
Represents a user known by Talis.
Instance Attribute Summary collapse
-
#email ⇒ String
readonly
The user’s E-mail address.
-
#first_name ⇒ String
readonly
The user’s first name.
-
#guid ⇒ String
readonly
The globally unique identifier for the user.
-
#surname ⇒ String
readonly
The user’s surname.
-
#token ⇒ Talis::Authentication::Token
readonly
To use for user authentication with other Talis primitive services.
Class Method Summary collapse
-
.build(guid:, first_name:, surname:, email:, access_token: nil) ⇒ User
Builds a new user object.
-
.find(request_id: new_req_id, guid:) ⇒ User
Find a single user given the search criterion.
Instance Method Summary collapse
-
#avatar_url(size: nil, colour: nil) ⇒ String
Returns a URL that will resolve to an avatar image belonging to the user when fetched.
-
#full_name ⇒ String
Return the combination of the user’s first and surname.
-
#initialize(guid:, first_name:, surname:, email:, token: nil) ⇒ User
constructor
Creates a new user object.
Methods inherited from Resource
Constructor Details
#initialize(guid:, first_name:, surname:, email:, token: nil) ⇒ User
Creates a new user object. For internal use only, use build.
28 29 30 31 32 33 34 |
# File 'lib/talis/user.rb', line 28 def initialize(guid:, first_name:, surname:, email:, token: nil) @guid = guid @first_name = first_name @surname = surname @email = email @token = token end |
Instance Attribute Details
#email ⇒ String (readonly)
Returns the user’s E-mail address.
15 16 17 |
# File 'lib/talis/user.rb', line 15 def email @email end |
#first_name ⇒ String (readonly)
Returns the user’s first name.
11 12 13 |
# File 'lib/talis/user.rb', line 11 def first_name @first_name end |
#guid ⇒ String (readonly)
Returns the globally unique identifier for the user.
9 10 11 |
# File 'lib/talis/user.rb', line 9 def guid @guid end |
#surname ⇒ String (readonly)
Returns the user’s surname.
13 14 15 |
# File 'lib/talis/user.rb', line 13 def surname @surname end |
#token ⇒ Talis::Authentication::Token (readonly)
Returns to use for user authentication with other Talis primitive services.
18 19 20 |
# File 'lib/talis/user.rb', line 18 def token @token end |
Class Method Details
.build(guid:, first_name:, surname:, email:, access_token: nil) ⇒ User
Builds a new user object. This is for creating user objects as a result of a successful login request.
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/talis/user.rb', line 88 def build(guid:, first_name:, surname:, email:, access_token: nil) = { guid: guid, first_name: first_name, surname: surname, email: email, token: Talis::Authentication::Token.new(jwt: access_token) } new() end |
.find(request_id: new_req_id, guid:) ⇒ User
Find a single user given the search criterion. In order to perform this search, the client must be configured with a valid OAuth client that is allowed to search for users:
Talis::Authentication.client_id = 'client_id'
Talis::Authentication.client_secret = 'client_secret'
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/talis/user.rb', line 69 def find(request_id: new_req_id, guid:) response = get("/users/#{guid}", headers: { 'X-Request-Id' => request_id, 'Authorization' => "Bearer #{token}" }) new(extract_user_data(handle_response(response))) rescue Talis::NotFoundError nil end |
Instance Method Details
#avatar_url(size: nil, colour: nil) ⇒ String
Returns a URL that will resolve to an avatar image belonging to the user when fetched. This URL is cached by browsers when called.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/talis/user.rb', line 47 def avatar_url(size: nil, colour: nil) if size.present? && colour.present? params = "?#{URI.encode_www_form(size: size, colour: colour)}" elsif size.present? params = "?#{URI.encode_www_form(size: size)}" elsif colour.present? params = "?#{URI.encode_www_form(colour: colour)}" end "#{self.class.base_uri}/users/#{guid}/avatar#{params}" end |
#full_name ⇒ String
Return the combination of the user’s first and surname.
38 39 40 |
# File 'lib/talis/user.rb', line 38 def full_name "#{@first_name} #{@surname}" end |