Class: Wavix::Cart::Client
- Inherits:
-
Object
- Object
- Wavix::Cart::Client
- Defined in:
- lib/wavix/cart/client.rb
Instance Method Summary collapse
-
#add(request_options: {}, **params) ⇒ Array[Object]
Adds the listed phone numbers to the purchase cart.
-
#checkout(request_options: {}, **params) ⇒ Wavix::Cart::Types::CheckoutCartResponse
Purchases the listed phone numbers from the cart.
-
#get(request_options: {}, **_params) ⇒ Wavix::Cart::Types::GetCartResponse
Returns the current purchase cart, including the phone numbers it contains and the documents each requires.
- #initialize(client:) ⇒ void constructor
-
#remove(request_options: {}, **params) ⇒ Wavix::Cart::Types::RemoveCartResponse
Removes the listed phone numbers from the purchase cart.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/wavix/cart/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#add(request_options: {}, **params) ⇒ Array[Object]
Adds the listed phone numbers to the purchase cart.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/wavix/cart/client.rb', line 56 def add(request_options: {}, **params) params = Wavix::Internal::Types::Utils.normalize_keys(params) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "PUT", path: "v1/buy/cart", body: Wavix::Cart::Types::AddCartRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Wavix::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#checkout(request_options: {}, **params) ⇒ Wavix::Cart::Types::CheckoutCartResponse
Purchases the listed phone numbers from the cart. Activation and monthly fees are deducted from the account balance.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/wavix/cart/client.rb', line 123 def checkout(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/buy/cart/checkout", body: Wavix::Cart::Types::CheckoutCartRequest.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::Cart::Types::CheckoutCartResponse.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::Cart::Types::GetCartResponse
Returns the current purchase cart, including the phone numbers it contains and the documents each requires.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wavix/cart/client.rb', line 24 def get(request_options: {}, **_params) request = Wavix::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "v1/buy/cart", 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::Cart::Types::GetCartResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#remove(request_options: {}, **params) ⇒ Wavix::Cart::Types::RemoveCartResponse
Removes the listed phone numbers from the purchase cart.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/wavix/cart/client.rb', line 88 def remove(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/buy/cart", body: Wavix::Cart::Types::RemoveCartRequest.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::Cart::Types::RemoveCartResponse.load(response.body) else error_class = Wavix::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |