Class: User
- Inherits:
-
Object
- Object
- User
- Defined in:
- lib/bloomy/operations/users.rb
Overview
Class to handle all the operations related to users
Instance Attribute Summary collapse
-
#default_user_id ⇒ Object
readonly
Returns the value of attribute default_user_id.
Instance Method Summary collapse
-
#current_user_id ⇒ Integer
Retrieves the current user’s ID.
-
#details(user_id: @default_user_id, direct_reports: false, positions: false, all: false) ⇒ Hash
Retrieves details of a specific user.
-
#direct_reports(user_id: @default_user_id) ⇒ Array<Hash>
Retrieves direct reports of a specific user.
-
#initialize(conn) ⇒ User
constructor
Initializes a new User instance.
-
#positions(user_id: @default_user_id) ⇒ Array<Hash>
Retrieves positions of a specific user.
-
#search(term) ⇒ Array<Hash>
Searches for users based on a search term.
Constructor Details
#initialize(conn) ⇒ User
Initializes a new User instance
10 11 12 13 |
# File 'lib/bloomy/operations/users.rb', line 10 def initialize(conn) @conn = conn @default_user_id = current_user_id end |
Instance Attribute Details
#default_user_id ⇒ Object (readonly)
Returns the value of attribute default_user_id.
5 6 7 |
# File 'lib/bloomy/operations/users.rb', line 5 def default_user_id @default_user_id end |
Instance Method Details
#current_user_id ⇒ Integer
Retrieves the current user’s ID
21 22 23 24 |
# File 'lib/bloomy/operations/users.rb', line 21 def current_user_id response = @conn.get("users/mine").body response["Id"] end |
#details(user_id: @default_user_id, direct_reports: false, positions: false, all: false) ⇒ Hash
Retrieves details of a specific user
36 37 38 39 40 41 42 43 44 |
# File 'lib/bloomy/operations/users.rb', line 36 def details(user_id: @default_user_id, direct_reports: false, positions: false, all: false) response = @conn.get("users/#{user_id}").body user_details = {name: response["Name"], id: response["Id"], image_url: response["ImageUrl"]} user_details[:direct_reports] = direct_reports(user_id: user_id) if direct_reports || all user_details[:positions] = positions(user_id: user_id) if positions || all user_details end |
#direct_reports(user_id: @default_user_id) ⇒ Array<Hash>
Retrieves direct reports of a specific user
53 54 55 56 |
# File 'lib/bloomy/operations/users.rb', line 53 def direct_reports(user_id: @default_user_id) direct_reports_response = @conn.get("users/#{user_id}/directreports").body direct_reports_response.map { |report| {name: report["Name"], id: report["Id"], image_url: report["ImageUrl"]} } end |
#positions(user_id: @default_user_id) ⇒ Array<Hash>
Retrieves positions of a specific user
65 66 67 68 69 70 |
# File 'lib/bloomy/operations/users.rb', line 65 def positions(user_id: @default_user_id) position_response = @conn.get("users/#{user_id}/seats").body position_response.map do |position| {name: position["Group"]["Position"]["Name"], id: position["Group"]["Position"]["Id"]} end end |
#search(term) ⇒ Array<Hash>
Searches for users based on a search term
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/bloomy/operations/users.rb', line 79 def search(term) response = @conn.get("search/user", term: term).body response.map do |user| { id: user["Id"], name: user["Name"], description: user["Description"], email: user["Email"], organization_id: user["OrganizationId"], image_url: user["ImageUrl"] } end end |