Class: Wavix::Numbers::Client
- Inherits:
-
Object
- Object
- Wavix::Numbers::Client
- Defined in:
- lib/wavix/numbers/client.rb
Instance Method Summary collapse
-
#bulk_update(request_options: {}, **params) ⇒ Wavix::Numbers::Types::BulkUpdateNumbersResponse
Applies the same changes to every listed phone number.
-
#delete(request_options: {}, **params) ⇒ Wavix::Numbers::Types::DeleteNumbersResponse
Releases the listed phone numbers back to stock.
-
#get(request_options: {}, **params) ⇒ Wavix::Types::Number
Returns the phone number identified by
id, including its destinations, documents, and feature settings. - #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Wavix::Types::NumberListResponse
Returns a paginated list of the phone numbers owned by the authenticated account.
- #papers ⇒ Wavix::Papers::Client
-
#update(request_options: {}, **params) ⇒ Wavix::Types::Number
Updates the phone number identified by
id.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/wavix/numbers/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#bulk_update(request_options: {}, **params) ⇒ Wavix::Numbers::Types::BulkUpdateNumbersResponse
Applies the same changes to every listed phone number. Only the provided fields are changed. Destination and SMS callback changes are applied asynchronously and may not be reflected in the response immediately.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/wavix/numbers/client.rb', line 114 def bulk_update(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "v1/numbers", body: Wavix::Numbers::Types::NumberBulkUpdateRequest.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::Numbers::Types::BulkUpdateNumbersResponse.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::Numbers::Types::DeleteNumbersResponse
Releases the listed phone numbers back to stock. Selection accepts either ids (record IDs) or dids (phone
numbers), but not both.
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 |
# File 'lib/wavix/numbers/client.rb', line 75 def delete(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["ids"] = params[:ids] if params.key?(:ids) query_params["dids"] = params[:dids] if params.key?(:dids) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "v1/numbers", 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::Numbers::Types::DeleteNumbersResponse.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::Number
Returns the phone number identified by id, including its destinations, documents, and feature settings.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/wavix/numbers/client.rb', line 149 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/numbers/#{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::Number.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::NumberListResponse
Returns a paginated list of the phone numbers owned by the authenticated account.
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 57 58 59 |
# File 'lib/wavix/numbers/client.rb', line 30 def list(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["city_id"] = params[:city_id] if params.key?(:city_id) query_params["search"] = params[:search] if params.key?(:search) query_params["label"] = params[:label] if params.key?(:label) query_params["label_present"] = params[:label_present] if params.key?(:label_present) 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/numbers", 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::NumberListResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#papers ⇒ Wavix::Papers::Client
211 212 213 |
# File 'lib/wavix/numbers/client.rb', line 211 def papers @papers ||= Wavix::Numbers::Papers::Client.new(client: @client) end |
#update(request_options: {}, **params) ⇒ Wavix::Types::Number
Updates the phone number identified by id. Only the provided fields are changed.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/wavix/numbers/client.rb', line 183 def update(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) request_data = Wavix::Numbers::Types::NumberUpdateRequest.new(params).to_h non_body_param_names = %w[id] body = request_data.except(*non_body_param_names) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "v1/numbers/#{URI.encode_uri_component(params[:id].to_s)}", body: body, 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::Number.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |