Class: Candid::CustomSchemas::V1::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/candid/custom_schemas/v_1/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:, base_url: nil, environment: nil) ⇒ void

Parameters:



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.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



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: request_options[: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: 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.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:



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: request_options[:base_url] || @base_url || @environment&.dig(:candid_api),
    method: "GET",
    path: "/api/custom-schemas/v1/#{params[:schema_id]}",
    request_options: 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.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :organization_id (String, nil)

Returns:



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: request_options[:base_url] || @base_url || @environment&.dig(:candid_api),
    method: "GET",
    path: "/api/custom-schemas/v1",
    query: query_params,
    request_options: 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.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:



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: request_options[:base_url] || @base_url || @environment&.dig(:candid_api),
    method: "PATCH",
    path: "/api/custom-schemas/v1/#{params[:schema_id]}",
    body: body,
    request_options: 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