@@ -5,6 +5,11 @@ require "ruby-bandwidth-iris"
Faraday.default_adapter = :em_synchrony
class BandwidthTNOrder
+ ORDER_DEFAULTS = {
+ site_id: CONFIG[:bandwidth_site],
+ peer_id: CONFIG[:bandwidth_peer]
+ }.freeze
+
def self.get(id)
EMPromise.resolve(nil).then do
self.for(BandwidthIris::Order.get_order_response(
@@ -15,15 +20,18 @@ class BandwidthTNOrder
end
end
- def self.create(tel, name: "sgx-jmp order #{tel}", **kwargs)
+ def self.create(
+ tel,
+ name: "sgx-jmp order #{tel}",
+ reservation_id: nil,
+ **kwargs
+ )
EMPromise.resolve(nil).then do
Received.new(BandwidthIris::Order.create(
- name: name, **kwargs,
- site_id: CONFIG[:bandwidth_site],
- peer_id: CONFIG[:bandwidth_peer],
+ name: name, **ORDER_DEFAULTS, **kwargs,
existing_telephone_number_order_type: {
telephone_number_list: { telephone_number: [tel.sub(/^\+?1?/, "")] }
- }
+ }.merge(ReservationIdList.new(reservation_id).to_h)
))
end
end
@@ -88,4 +96,16 @@ class BandwidthTNOrder
raise "Order failed: #{id} #{error_description}"
end
end
+
+ class ReservationIdList
+ def initialize(reservation_id)
+ @reservation_id = reservation_id
+ end
+
+ def to_h
+ return {} unless @reservation_id
+
+ { reservation_id_list: { reservation_id: @reservation_id } }
+ end
+ end
end
@@ -11,9 +11,9 @@ class BandwidthTNOrderTest < Minitest::Test
).with(
body: {
Name: "sgx-jmp order +15551234567",
- CustomerOrderId: "test",
SiteId: "test_site",
PeerId: "test_peer",
+ CustomerOrderId: "test",
ExistingTelephoneNumberOrderType: {
TelephoneNumberList: {
TelephoneNumber: "5551234567"
@@ -22,10 +22,42 @@ class BandwidthTNOrderTest < Minitest::Test
}.to_xml(indent: 0, root: "Order")
).to_return(status: 200)
BandwidthTNOrder.create("+15551234567", customer_order_id: "test").sync
+
assert_requested req
end
em :test_create
+ def test_create_with_reservation
+ req = stub_request(
+ :post,
+ "https://dashboard.bandwidth.com/v1.0/accounts//orders"
+ ).with(
+ body: {
+ Name: "sgx-jmp order +15551234567",
+ SiteId: "test_site",
+ PeerId: "test_peer",
+ CustomerOrderId: "test",
+ ExistingTelephoneNumberOrderType: {
+ TelephoneNumberList: {
+ TelephoneNumber: "5551234567"
+ },
+ ReservationIdList: {
+ ReservationId: "res"
+ }
+ }
+ }.to_xml(indent: 0, root: "Order")
+ ).to_return(status: 200)
+
+ BandwidthTNOrder.create(
+ "+15551234567",
+ customer_order_id: "test",
+ reservation_id: "res"
+ ).sync
+
+ assert_requested req
+ end
+ em :test_create_with_reservation
+
def test_for_received
order = BandwidthTNOrder.for(BandwidthIris::Order.new(
order_status: "RECEIVED"