Class: Vapi::Sessions::Client
- Inherits:
-
Object
- Object
- Vapi::Sessions::Client
- Defined in:
- lib/vapi/sessions/client.rb
Instance Method Summary collapse
- #create(request_options: {}, **params) ⇒ Vapi::Types::Session
- #delete(request_options: {}, **params) ⇒ Vapi::Types::Session
- #get(request_options: {}, **params) ⇒ Vapi::Types::Session
- #initialize(client:) ⇒ void constructor
- #list(request_options: {}, **params) ⇒ Vapi::Types::SessionPaginatedResponse
- #update(request_options: {}, **params) ⇒ Vapi::Types::Session
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/vapi/sessions/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Vapi::Types::Session
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/vapi/sessions/client.rb', line 112 def create(request_options: {}, **params) params = Vapi::Internal::Types::Utils.normalize_keys(params) request = Vapi::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "session", body: Vapi::Sessions::Types::CreateSessionDto.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Vapi::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Vapi::Types::Session.load(response.body) else error_class = Vapi::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ Vapi::Types::Session
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/vapi/sessions/client.rb', line 177 def delete(request_options: {}, **params) params = Vapi::Internal::Types::Utils.normalize_keys(params) request = Vapi::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "session/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Vapi::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Vapi::Types::Session.load(response.body) else error_class = Vapi::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get(request_options: {}, **params) ⇒ Vapi::Types::Session
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/vapi/sessions/client.rb', line 145 def get(request_options: {}, **params) params = Vapi::Internal::Types::Utils.normalize_keys(params) request = Vapi::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "session/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Vapi::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Vapi::Types::Session.load(response.body) else error_class = Vapi::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Vapi::Types::SessionPaginatedResponse
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 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/vapi/sessions/client.rb', line 49 def list(request_options: {}, **params) params = Vapi::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[id name assistant_id assistant_id_any squad_id workflow_id number_e_164_check_enabled extension assistant_overrides number sip_uri email external_id customer_number_any phone_number_id phone_number_id_any page sort_order limit created_at_gt created_at_lt created_at_ge created_at_le updated_at_gt updated_at_lt updated_at_ge updated_at_le] query_params = {} query_params["id"] = params[:id] if params.key?(:id) query_params["name"] = params[:name] if params.key?(:name) query_params["assistantId"] = params[:assistant_id] if params.key?(:assistant_id) query_params["assistantIdAny"] = params[:assistant_id_any] if params.key?(:assistant_id_any) query_params["squadId"] = params[:squad_id] if params.key?(:squad_id) query_params["workflowId"] = params[:workflow_id] if params.key?(:workflow_id) query_params["numberE164CheckEnabled"] = params[:number_e_164_check_enabled] if params.key?(:number_e_164_check_enabled) query_params["extension"] = params[:extension] if params.key?(:extension) query_params["assistantOverrides"] = params[:assistant_overrides] if params.key?(:assistant_overrides) query_params["number"] = params[:number] if params.key?(:number) query_params["sipUri"] = params[:sip_uri] if params.key?(:sip_uri) query_params["email"] = params[:email] if params.key?(:email) query_params["externalId"] = params[:external_id] if params.key?(:external_id) query_params["customerNumberAny"] = params[:customer_number_any] if params.key?(:customer_number_any) query_params["phoneNumberId"] = params[:phone_number_id] if params.key?(:phone_number_id) query_params["phoneNumberIdAny"] = params[:phone_number_id_any] if params.key?(:phone_number_id_any) query_params["page"] = params[:page] if params.key?(:page) query_params["sortOrder"] = params[:sort_order] if params.key?(:sort_order) query_params["limit"] = params[:limit] if params.key?(:limit) query_params["createdAtGt"] = params[:created_at_gt] if params.key?(:created_at_gt) query_params["createdAtLt"] = params[:created_at_lt] if params.key?(:created_at_lt) query_params["createdAtGe"] = params[:created_at_ge] if params.key?(:created_at_ge) query_params["createdAtLe"] = params[:created_at_le] if params.key?(:created_at_le) query_params["updatedAtGt"] = params[:updated_at_gt] if params.key?(:updated_at_gt) query_params["updatedAtLt"] = params[:updated_at_lt] if params.key?(:updated_at_lt) query_params["updatedAtGe"] = params[:updated_at_ge] if params.key?(:updated_at_ge) query_params["updatedAtLe"] = params[:updated_at_le] if params.key?(:updated_at_le) params.except(*query_param_names) request = Vapi::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "session", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Vapi::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Vapi::Types::SessionPaginatedResponse.load(response.body) else error_class = Vapi::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update(request_options: {}, **params) ⇒ Vapi::Types::Session
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/vapi/sessions/client.rb', line 209 def update(request_options: {}, **params) params = Vapi::Internal::Types::Utils.normalize_keys(params) request_data = Vapi::Sessions::Types::UpdateSessionDto.new(params).to_h non_body_param_names = ["id"] body = request_data.except(*non_body_param_names) request = Vapi::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "session/#{URI.encode_uri_component(params[:id].to_s)}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Vapi::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Vapi::Types::Session.load(response.body) else error_class = Vapi::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |