Class: Bloomy::User
- Inherits:
-
Object
- Object
- Bloomy::User
- Includes:
- Bloomy::Utilities::UserIdUtility
- Defined in:
- lib/bloomy/operations/users.rb
Overview
Class to handle all the operations related to users
Instance Method Summary collapse
-
#all(include_placeholders: false) ⇒ Array<Hash>
Retrieves all users in the system.
-
#details(user_id = self.user_id, direct_reports: false, positions: false, all: false) ⇒ Hash
Retrieves details of a specific user.
-
#direct_reports(user_id = self.user_id) ⇒ Array<Hash>
Retrieves direct reports of a specific user.
-
#initialize(conn) ⇒ User
constructor
Initializes a new User instance.
-
#positions(user_id = self.user_id) ⇒ Array<Hash>
Retrieves positions of a specific user.
-
#search(term) ⇒ Array<Hash>
Searches for users based on a search term.
Methods included from Bloomy::Utilities::UserIdUtility
Constructor Details
#initialize(conn) ⇒ User
Initializes a new User instance
13 14 15 |
# File 'lib/bloomy/operations/users.rb', line 13 def initialize(conn) @conn = conn end |
Instance Method Details
#all(include_placeholders: false) ⇒ Array<Hash>
Retrieves all users in the system
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/bloomy/operations/users.rb', line 88 def all(include_placeholders: false) users = @conn.get("search/all", term: "%").body users .select { |user| user["ResultType"] == "User" } .reject { |user| !include_placeholders && user["ImageUrl"] == "/i/userplaceholder" } .map do |user| { id: user["Id"], name: user["Name"], email: user["Email"], position: user["Description"], image_url: user["ImageUrl"] } end end |
#details(user_id = self.user_id, direct_reports: false, positions: false, all: false) ⇒ Hash
Retrieves details of a specific user
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bloomy/operations/users.rb', line 24 def details(user_id = self.user_id, direct_reports: false, positions: false, all: false) response = @conn.get("users/#{user_id}").body user_details = { id: response["Id"], name: response["Name"], image_url: response["ImageUrl"] } user_details[:direct_reports] = direct_reports(user_id) if direct_reports || all user_details[:positions] = positions(user_id) if positions || all user_details end |
#direct_reports(user_id = self.user_id) ⇒ Array<Hash>
Retrieves direct reports of a specific user
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bloomy/operations/users.rb', line 41 def direct_reports(user_id = self.user_id) direct_reports_response = @conn.get("users/#{user_id}/directreports").body direct_reports_response.map do |report| { name: report["Name"], id: report["Id"], image_url: report["ImageUrl"] } end end |
#positions(user_id = self.user_id) ⇒ Array<Hash>
Retrieves positions of a specific user
56 57 58 59 60 61 62 63 64 |
# File 'lib/bloomy/operations/users.rb', line 56 def positions(user_id = self.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
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/bloomy/operations/users.rb', line 70 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 |