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:) ⇒ Candid::CustomSchemas::V1::Client



8
9
10
# File 'lib/candid/custom_schemas/v_1/client.rb', line 8

def initialize(client:)
  @client = client
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.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/candid/custom_schemas/v_1/client.rb', line 62

def create(request_options: {}, **params)
  _request = Candid::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Candid::Environment::PRODUCTION,
    method: "POST",
    path: "/api/custom-schemas/v1",
    body: params
  )
  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.



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 38

def get(request_options: {}, **params)
  _request = Candid::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Candid::Environment::PRODUCTION,
    method: "GET",
    path: "/api/custom-schemas/v1/#{params[:schema_id]}"
  )
  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.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/candid/custom_schemas/v_1/client.rb', line 15

def get_multi(request_options: {}, **_params)
  _request = Candid::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Candid::Environment::PRODUCTION,
    method: "GET",
    path: "/api/custom-schemas/v1"
  )
  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.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/candid/custom_schemas/v_1/client.rb', line 86

def update(request_options: {}, **params)
  _path_param_names = ["schema_id"]

  _request = Candid::Internal::JSON::Request.new(
    base_url: request_options[:base_url] || Candid::Environment::PRODUCTION,
    method: "PATCH",
    path: "/api/custom-schemas/v1/#{params[:schema_id]}",
    body: params.except(*_path_param_names)
  )
  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