Class: Apologist::Users::Client
- Inherits:
-
Object
- Object
- Apologist::Users::Client
- Defined in:
- lib/Apologist/users/client.rb
Instance Method Summary collapse
-
#get_user(request_options: {}, **params) ⇒ Apologist::Users::Types::GetUserResponse
Returns a single user by external id or internal id, with expanded tags and the persisted responder for the agent.
- #initialize(client:) ⇒ void constructor
-
#list_user_flags(request_options: {}, **params) ⇒ Apologist::Users::Types::ListUserFlagsResponse
Returns a paginated list of user flag definitions for the agent's team (all columns from user_flags), ordered by id ascending.
-
#list_users(request_options: {}, **params) ⇒ Apologist::Users::Types::ListUsersResponse
Returns a paginated list of users for the agent's team, with applied tags expanded as { id, name } and the persisted responder id.
-
#update_user(request_options: {}, **params) ⇒ Apologist::Users::Types::UpdateUserResponse
Updates a user's external_id and/or tags and upserts the persisted responder for the agent.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/Apologist/users/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#get_user(request_options: {}, **params) ⇒ Apologist::Users::Types::GetUserResponse
Returns a single user by external id or internal id, with expanded tags and the persisted responder for the agent.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/Apologist/users/client.rb', line 127 def get_user(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "users/#{URI.encode_uri_component(params[:user_id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Apologist::Users::Types::GetUserResponse.load(response.body) else error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list_user_flags(request_options: {}, **params) ⇒ Apologist::Users::Types::ListUserFlagsResponse
Returns a paginated list of user flag definitions for the agent's team (all columns from user_flags), ordered by id ascending.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/Apologist/users/client.rb', line 84 def list_user_flags(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["page"] = params[:page] if params.key?(:page) query_params["per_page"] = params[:per_page] if params.key?(:per_page) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "users/flags", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Apologist::Users::Types::ListUserFlagsResponse.load(response.body) else error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list_users(request_options: {}, **params) ⇒ Apologist::Users::Types::ListUsersResponse
Returns a paginated list of users for the agent's team, with applied tags expanded as { id, name } and the persisted responder id.
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 |
# File 'lib/Apologist/users/client.rb', line 35 def list_users(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["page"] = params[:page] if params.key?(:page) query_params["per_page"] = params[:per_page] if params.key?(:per_page) query_params["external_id"] = params[:external_id] if params.key?(:external_id) query_params["tags"] = params[:tags] if params.key?(:tags) query_params["responder_id"] = params[:responder_id] if params.key?(:responder_id) query_params["min_timestamp"] = params[:min_timestamp] if params.key?(:min_timestamp) query_params["max_timestamp"] = params[:max_timestamp] if params.key?(:max_timestamp) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "users", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Apologist::Users::Types::ListUsersResponse.load(response.body) else error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update_user(request_options: {}, **params) ⇒ Apologist::Users::Types::UpdateUserResponse
Updates a user's external_id and/or tags and upserts the persisted responder for the agent. Only provided fields are changed.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/Apologist/users/client.rb', line 165 def update_user(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) request_data = Apologist::Users::Types::UserUpdateRequest.new(params).to_h non_body_param_names = %w[user_id] body = request_data.except(*non_body_param_names) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "users/#{URI.encode_uri_component(params[:user_id].to_s)}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Apologist::Users::Types::UpdateUserResponse.load(response.body) else error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |