Module: XClarityClient::ManagementMixin
- Defined in:
- lib/xclarity_client/services/xclarity_management_mixin.rb
Instance Method Summary collapse
- #get_all_resources(resource, opts = {}) ⇒ Object
- #get_object(uuids, includeAttributes, excludeAttributes, resource) ⇒ Object
- #get_object_with_exclude_attributes(uuids, attributes, resource) ⇒ Object
- #get_object_with_id(ids, includeAttributes, excludeAttributes, resource) ⇒ Object
- #get_object_with_id_exclude_attributes(uuids, attributes, resource) ⇒ Object
- #get_object_with_id_include_attributes(uuids, attributes, resource) ⇒ Object
- #get_object_with_include_attributes(uuids, attributes, resource) ⇒ Object
- #get_object_with_opts(opts, resource) ⇒ Object
Instance Method Details
#get_all_resources(resource, opts = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/xclarity_client/services/xclarity_management_mixin.rb', line 3 def get_all_resources (resource, opts = {}) $lxca_log.info "XclarityClient::ManagementMixin get_all_resources", "Sending request to #{resource} resource" response = connection(resource::BASE_URI, opts) $lxca_log.info "XclarityClient::ManagementMixin get_all_resources", "Response received from #{resource::BASE_URI}" return [] unless response.success? body = JSON.parse(response.body) if resource == XClarityClient::User body = body['response'] end list_name, body = add_listname_on_body(resource, body) body[list_name].map do |resource_params| resource.new resource_params end end |
#get_object(uuids, includeAttributes, excludeAttributes, resource) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/xclarity_client/services/xclarity_management_mixin.rb', line 24 def get_object(uuids, includeAttributes, excludeAttributes, resource) $lxca_log.info "XclarityClient::ManagementMixin get_object", "Sending request to #{resource} resource" uuids.reject! { |uuid| UUID.validate(uuid).nil? } unless uuids.nil? response = if not includeAttributes.nil? get_object_with_include_attributes(uuids, includeAttributes, resource) elsif not excludeAttributes.nil? get_object_with_exclude_attributes(uuids, excludeAttributes, resource) elsif not uuids.nil? connection(resource::BASE_URI + "/" + uuids.join(",")) else connection(resource::BASE_URI) end return [] unless response.success? body = JSON.parse(response.body) body = {resource::LIST_NAME => body} if body.is_a? Array body = {resource::LIST_NAME => [body]} unless body.has_key? resource::LIST_NAME body[resource::LIST_NAME].map do |resource_params| resource.new resource_params end end |
#get_object_with_exclude_attributes(uuids, attributes, resource) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/xclarity_client/services/xclarity_management_mixin.rb', line 64 def get_object_with_exclude_attributes(uuids, attributes, resource) $lxca_log.info "XclarityClient::ManagementMixin get_object_with_include", "Sending request to #{resource} resource excluding the following attributes: #{attributes.join(",")}" uuids.reject! { |uuid| UUID.validate(uuid).nil? } unless uuids.nil? response = if not uuids.nil? connection(resource::BASE_URI + "/#{uuids.join(",")}"+"?excludeAttributes=#{attributes.join(",")}") else connection(resource::BASE_URI + "?excludeAttributes=" + attributes.join(",")) end end |
#get_object_with_id(ids, includeAttributes, excludeAttributes, resource) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/xclarity_client/services/xclarity_management_mixin.rb', line 77 def get_object_with_id(ids, includeAttributes, excludeAttributes, resource) response = if not includeAttributes.nil? get_object_with_id_include_attributes(ids, includeAttributes, resource) elsif not excludeAttributes.nil? get_object_with_id_exclude_attributes(ids, excludeAttributes, resource) elsif not ids.nil? connection(resource::BASE_URI + "/" + ids.join(",")) else connection(resource::BASE_URI) end return [] unless response.success? body = JSON.parse(response.body) if resource == XClarityClient::User body = body['response'] end body = {resource::LIST_NAME => body} if body.is_a? Array body = {resource::LIST_NAME => [body]} unless body.has_key? resource::LIST_NAME body[resource::LIST_NAME].map do |resource_params| resource.new resource_params end end |
#get_object_with_id_exclude_attributes(uuids, attributes, resource) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/xclarity_client/services/xclarity_management_mixin.rb', line 111 def get_object_with_id_exclude_attributes(uuids, attributes, resource) response = if not uuids.nil? connection(resource::BASE_URI + "/#{uuids.join(",")}"+"?excludeAttributes=#{attributes.join(",")}") else connection(resource::BASE_URI + "?excludeAttributes=" + attributes.join(",")) end end |
#get_object_with_id_include_attributes(uuids, attributes, resource) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/xclarity_client/services/xclarity_management_mixin.rb', line 103 def get_object_with_id_include_attributes(uuids, attributes, resource) response = if not uuids.nil? connection(resource::BASE_URI + "/" + uuids.join(",") + "?includeAttributes=" + attributes.join(",")) else connection(resource::BASE_URI + "?includeAttributes=" + attributes.join(",")) end end |
#get_object_with_include_attributes(uuids, attributes, resource) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/xclarity_client/services/xclarity_management_mixin.rb', line 50 def get_object_with_include_attributes(uuids, attributes, resource) $lxca_log.info "XclarityClient::ManagementMixin get_object_with_include", "Sending request to #{resource} resource including the following attributes: #{attributes.join(",")}" uuids.reject! { |uuid| UUID.validate(uuid).nil? } unless uuids.nil? response = if not uuids.nil? connection(resource::BASE_URI + "/" + uuids.join(",") + "?includeAttributes=" + attributes.join(",")) else connection(resource::BASE_URI + "?includeAttributes=" + attributes.join(",")) end end |
#get_object_with_opts(opts, resource) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/xclarity_client/services/xclarity_management_mixin.rb', line 119 def get_object_with_opts(opts, resource) raise "The opts cannot be empty" if opts.empty? filter = "" response = if not opts.empty? if not opts.has_key? "type" if opts.has_key? "filterWith" filter += "?filterWith=" filter += "#{opts["filterWith"]}" elsif opts.has_key? "sort" filter += ",sort=" if filter != "" filter += "?sort=" if filter == "" filter += "#{opts["sort"]}" end else filter += "?type=#{opts["type"]}" end $lxca_log.info "XclarityClient::ManagementMixin get_object_with_include", "Sending request to #{resource} resource using the following filter: #{filter}" connection(resource::BASE_URI + filter) end return [] unless response.success? body = JSON.parse(response.body) body = {resource::LIST_NAME => body} if body.is_a? Array body = {resource::LIST_NAME => [body]} unless body.has_key? resource::LIST_NAME body[resource::LIST_NAME].map do |resource_params| resource.new resource_params end end |