Class: Candid::CustomSchemas::V1::Client
- Inherits:
-
Object
- Object
- Candid::CustomSchemas::V1::Client
- Defined in:
- lib/candid/custom_schemas/v_1/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Candid::CustomSchemas::V1::Types::Schema
Create custom schema with a set of typed keys.
-
#get(request_options: {}, **params) ⇒ Candid::CustomSchemas::V1::Types::Schema
Return a custom schema with a given ID.
-
#get_multi(request_options: {}, **params) ⇒ Candid::CustomSchemas::V1::Types::SchemaGetMultiResponse
Returns all custom schemas.
- #initialize(client:, base_url: nil, environment: nil) ⇒ void constructor
-
#update(request_options: {}, **params) ⇒ Candid::CustomSchemas::V1::Types::Schema
Update the name, description, or keys on a preexisting schema.
Constructor Details
#initialize(client:, base_url: nil, environment: nil) ⇒ void
12 13 14 15 16 |
# File 'lib/candid/custom_schemas/v_1/client.rb', line 12 def initialize(client:, base_url: nil, environment: nil) @client = client @base_url = base_url @environment = environment end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Candid::CustomSchemas::V1::Types::Schema
Create custom schema with a set of typed keys. Schema keys can be referenced as inputs in user-configurable rules in the Rules Engine, and key-value pairs can be attached to claims via the Encounters API.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/candid/custom_schemas/v_1/client.rb', line 105 def create(request_options: {}, **params) params = Candid::Internal::Types::Utils.normalize_keys(params) request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || @base_url || @environment&.dig(:candid_api), method: "POST", path: "/api/custom-schemas/v1", body: Candid::CustomSchemas::V1::Types::SchemaCreate.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Candid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Candid::CustomSchemas::V1::Types::Schema.load(response.body) else error_class = Candid::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get(request_options: {}, **params) ⇒ Candid::CustomSchemas::V1::Types::Schema
Return a custom schema with a given ID.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/candid/custom_schemas/v_1/client.rb', line 70 def get(request_options: {}, **params) params = Candid::Internal::Types::Utils.normalize_keys(params) request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || @base_url || @environment&.dig(:candid_api), method: "GET", path: "/api/custom-schemas/v1/#{params[:schema_id]}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Candid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Candid::CustomSchemas::V1::Types::Schema.load(response.body) else error_class = Candid::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get_multi(request_options: {}, **params) ⇒ Candid::CustomSchemas::V1::Types::SchemaGetMultiResponse
Returns all custom schemas.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/candid/custom_schemas/v_1/client.rb', line 30 def get_multi(request_options: {}, **params) params = Candid::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[organization_id] query_params = {} query_params["organization_id"] = params[:organization_id] if params.key?(:organization_id) params.except(*query_param_names) request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || @base_url || @environment&.dig(:candid_api), method: "GET", path: "/api/custom-schemas/v1", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Candid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Candid::CustomSchemas::V1::Types::SchemaGetMultiResponse.load(response.body) else error_class = Candid::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update(request_options: {}, **params) ⇒ Candid::CustomSchemas::V1::Types::Schema
Update the name, description, or keys on a preexisting schema.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/candid/custom_schemas/v_1/client.rb', line 140 def update(request_options: {}, **params) params = Candid::Internal::Types::Utils.normalize_keys(params) request_data = Candid::CustomSchemas::V1::Types::SchemaUpdate.new(params).to_h non_body_param_names = ["schema_id"] body = request_data.except(*non_body_param_names) request = Candid::Internal::JSON::Request.new( base_url: [:base_url] || @base_url || @environment&.dig(:candid_api), method: "PATCH", path: "/api/custom-schemas/v1/#{params[:schema_id]}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Candid::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Candid::CustomSchemas::V1::Types::Schema.load(response.body) else error_class = Candid::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |