Class: Wavix::SipTrunks::Client
- Inherits:
-
Object
- Object
- Wavix::SipTrunks::Client
- Defined in:
- lib/wavix/sip_trunks/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Wavix::Types::SipTrunkResponse
Creates a SIP trunk for routing inbound and outbound calls.
-
#delete(request_options: {}, **params) ⇒ Wavix::Types::SuccessResponse
Deletes the SIP trunk identified by
id. -
#get(request_options: {}, **params) ⇒ Wavix::Types::SipTrunkResponse
Returns the SIP trunk identified by
id. - #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Wavix::Types::SipTrunkListResponse
Returns a paginated list of SIP trunks for the authenticated account.
-
#update(request_options: {}, **params) ⇒ Wavix::Types::SipTrunkResponse
Replaces the configuration of the SIP trunk identified by
id.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/wavix/sip_trunks/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Wavix::Types::SipTrunkResponse
Creates a SIP trunk for routing inbound and outbound calls. Returns the trunk with its generated access_token.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/wavix/sip_trunks/client.rb', line 64 def create(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "v1/trunks", body: Wavix::Types::SipTrunkCreateRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Wavix::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Wavix::Types::SipTrunkResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ Wavix::Types::SuccessResponse
Deletes the SIP trunk identified by id. Deletion is permanent and stops call routing through the trunk.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/wavix/sip_trunks/client.rb', line 171 def delete(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "v1/trunks/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Wavix::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Wavix::Types::SuccessResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get(request_options: {}, **params) ⇒ Wavix::Types::SipTrunkResponse
Returns the SIP trunk identified by id.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/wavix/sip_trunks/client.rb', line 99 def get(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v1/trunks/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Wavix::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Wavix::Types::SipTrunkResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Wavix::Types::SipTrunkListResponse
Returns a paginated list of SIP trunks for the authenticated account.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wavix/sip_trunks/client.rb', line 26 def list(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["page"] = params[:page] if params.key?(:page) query_params["per_page"] = params[:per_page] if params.key?(:per_page) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v1/trunks", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Wavix::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Wavix::Types::SipTrunkListResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update(request_options: {}, **params) ⇒ Wavix::Types::SipTrunkResponse
Replaces the configuration of the SIP trunk identified by id. Omitted fields revert to their defaults.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/wavix/sip_trunks/client.rb', line 133 def update(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) path_param_names = %i[id] body_params = params.except(*path_param_names) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "PUT", path: "v1/trunks/#{URI.encode_uri_component(params[:id].to_s)}", body: Wavix::Types::SipTrunkCreateRequest.new(body_params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Wavix::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Wavix::Types::SipTrunkResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |