Module: XClarityClient::Services::ResponseBuilderMixin

Includes:
ListNameInterpreterMixin
Included in:
XClarityService
Defined in:
lib/xclarity_client/services/mixins/response_builder_mixin.rb

Overview

A response builder knows how to treat a response from LXCA and create a ruby response

Instance Method Summary collapse

Methods included from ListNameInterpreterMixin

#add_listname_on_body

Instance Method Details

#build_response_with_resource_list(response, endpoint_class) ⇒ Array

Builds an array from an LXCA response that contains a list of resources.

Parameters:

  • response
    • the LXCA response

  • endpoint_class
    • the class that represents the endpoint that generates the response

Returns:

  • (Array)

    containing the resources of the LXCA response



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/xclarity_client/services/mixins/response_builder_mixin.rb', line 21

def build_response_with_resource_list(response, endpoint_class)
  return [] unless response.success?

  body = JSON.parse(response.body)

  if endpoint_class == XClarityClient::User
    body = body['response']
  end

  list_name, body = add_listname_on_body(endpoint_class, body)

  body[list_name].map do |resource_params|
    endpoint_class.new resource_params
  end
end