lib/bandwidth_tn_repo.rb 🔗
@@ -8,7 +8,7 @@ class BandwidthTnRepo
tel,
region,
locality,
- bandwidth_account_id,
+ source,
available_after
) VALUES (
$1,
Stephen Paul Weber created
And don't return anything where source starts with xmpp: we'll use that
for internal inventory stuff like offer codes.
lib/bandwidth_tn_repo.rb | 2 +-
lib/tel_selections.rb | 28 ++++++++++++++++------------
test/test_tel_selections.rb | 33 ++++++++++++++++++++++-----------
3 files changed, 39 insertions(+), 24 deletions(-)
@@ -8,7 +8,7 @@ class BandwidthTnRepo
tel,
region,
locality,
- bandwidth_account_id,
+ source,
available_after
) VALUES (
$1,
@@ -182,7 +182,7 @@ class TelSelections
full_number: row["tel"].sub(/\A\+1/, ""),
city: row["locality"],
state: row["region"]
- ), row["bandwidth_account_id"], price: row["premium_price"])
+ ), row["source"], price: row["premium_price"])
}
}
end
@@ -242,9 +242,9 @@ class TelSelections
def self.for_pending_value(value)
if value.start_with?("LocalInventory/")
- tel, account, price =
+ tel, source, price =
value.sub(/\ALocalInventory\//, "").split("/", 3)
- LocalInventory.new(Tn.new(tel), account, price: price.to_d)
+ LocalInventory.new(Tn.new(tel), source, price: price.to_d)
else
Bandwidth.new(Tn.new(value))
end
@@ -327,9 +327,9 @@ class TelSelections
attr_reader :price
- def initialize(tn, bandwidth_account_id, price: 0)
+ def initialize(tn, source, price: 0)
super(tn)
- @bandwidth_account_id = bandwidth_account_id
+ @source = source
@price = price || 0
end
@@ -372,20 +372,20 @@ class TelSelections
full_number: row["tel"].sub(/\A\+1/, ""),
city: row["locality"],
state: row["region"]
- ), row["bandwidth_account_id"], price: row["premium_price"])
+ ), row["source"], price: row["premium_price"])
}
}
end
def pending_value
- "LocalInventory/#{tel}/#{@bandwidth_account_id}/#{price}"
+ "LocalInventory/#{tel}/#{@source}/#{price}"
end
def order(db, _customer)
# Move always moves to wrong account, oops
# Also probably can't move from/to same account
# BandwidthTnRepo.new.move(
- # tel, customer.customer_id, @bandwidth_account_id
+ # tel, customer.customer_id, @source
# )
db.exec_defer("DELETE FROM tel_inventory WHERE tel = $1", [tel])
.then { |r| raise unless r.cmd_tuples.positive? }
@@ -444,7 +444,8 @@ class TelSelections
define_method(:sql_query) do
[
"SELECT * FROM tel_inventory " \
- "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1",
+ "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1 " \
+ "AND source NOT LIKE 'xmpp:%'",
"+1#{@q}%"
]
end
@@ -478,7 +479,8 @@ class TelSelections
def sql_query
[
"SELECT * FROM tel_inventory " \
- "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1",
+ "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1 " \
+ "AND source NOT LIKE 'xmpp:%'",
"%#{q_digits}%"
]
end
@@ -518,7 +520,8 @@ class TelSelections
def sql_query
[
"SELECT * FROM tel_inventory " \
- "WHERE available_after < LOCALTIMESTAMP AND region = $1",
+ "WHERE available_after < LOCALTIMESTAMP AND region = $1 " \
+ "AND source NOT LIKE 'xmpp:%'",
@state
]
end
@@ -570,7 +573,8 @@ class TelSelections
[
"SELECT * FROM tel_inventory " \
"WHERE available_after < LOCALTIMESTAMP " \
- "AND region = $1 AND locality = $2",
+ "AND region = $1 AND locality = $2 " \
+ "AND source NOT LIKE 'xmpp:%'",
@state.to_s, @city
]
end
@@ -227,7 +227,8 @@ class TelSelectionsTest < Minitest::Test
assert_equal(
[
"SELECT * FROM tel_inventory " \
- "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1",
+ "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1 " \
+ "AND source NOT LIKE 'xmpp:%'",
"+1226%"
],
q.sql_query
@@ -244,7 +245,8 @@ class TelSelectionsTest < Minitest::Test
assert_equal(
[
"SELECT * FROM tel_inventory " \
- "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1",
+ "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1 " \
+ "AND source NOT LIKE 'xmpp:%'",
"+1226666%"
],
q.sql_query
@@ -261,7 +263,8 @@ class TelSelectionsTest < Minitest::Test
assert_equal(
[
"SELECT * FROM tel_inventory " \
- "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1",
+ "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1 "\
+ "AND source NOT LIKE 'xmpp:%'",
"+12266667%"
],
q.sql_query
@@ -288,7 +291,8 @@ class TelSelectionsTest < Minitest::Test
assert_equal(
[
"SELECT * FROM tel_inventory " \
- "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1",
+ "WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1 " \
+ "AND source NOT LIKE 'xmpp:%'",
"%6262%"
],
q.sql_query
@@ -305,7 +309,8 @@ class TelSelectionsTest < Minitest::Test
assert_equal(
[
"SELECT * FROM tel_inventory " \
- "WHERE available_after < LOCALTIMESTAMP AND region = $1",
+ "WHERE available_after < LOCALTIMESTAMP AND region = $1 " \
+ "AND source NOT LIKE 'xmpp:%'",
"ON"
],
q.sql_query
@@ -322,7 +327,8 @@ class TelSelectionsTest < Minitest::Test
assert_equal(
[
"SELECT * FROM tel_inventory " \
- "WHERE available_after < LOCALTIMESTAMP AND region = $1",
+ "WHERE available_after < LOCALTIMESTAMP AND region = $1 " \
+ "AND source NOT LIKE 'xmpp:%'",
"ON"
],
q.sql_query
@@ -339,7 +345,8 @@ class TelSelectionsTest < Minitest::Test
assert_equal(
[
"SELECT * FROM tel_inventory " \
- "WHERE available_after < LOCALTIMESTAMP AND region = $1",
+ "WHERE available_after < LOCALTIMESTAMP AND region = $1 " \
+ "AND source NOT LIKE 'xmpp:%'",
"NY"
],
q.sql_query
@@ -365,7 +372,8 @@ class TelSelectionsTest < Minitest::Test
[
"SELECT * FROM tel_inventory " \
"WHERE available_after < LOCALTIMESTAMP " \
- "AND region = $1 AND locality = $2",
+ "AND region = $1 AND locality = $2 " \
+ "AND source NOT LIKE 'xmpp:%'",
"NY", "New York City"
],
q.sql_query
@@ -391,7 +399,8 @@ class TelSelectionsTest < Minitest::Test
[
"SELECT * FROM tel_inventory " \
"WHERE available_after < LOCALTIMESTAMP " \
- "AND region = $1 AND locality = $2",
+ "AND region = $1 AND locality = $2 " \
+ "AND source NOT LIKE 'xmpp:%'",
"NY", "New York City"
],
q.sql_query
@@ -417,7 +426,8 @@ class TelSelectionsTest < Minitest::Test
[
"SELECT * FROM tel_inventory " \
"WHERE available_after < LOCALTIMESTAMP " \
- "AND region = $1 AND locality = $2",
+ "AND region = $1 AND locality = $2 " \
+ "AND source NOT LIKE 'xmpp:%'",
"ON", "Toronto"
],
q.sql_query
@@ -443,7 +453,8 @@ class TelSelectionsTest < Minitest::Test
[
"SELECT * FROM tel_inventory " \
"WHERE available_after < LOCALTIMESTAMP " \
- "AND region = $1 AND locality = $2",
+ "AND region = $1 AND locality = $2 " \
+ "AND source NOT LIKE 'xmpp:%'",
"ON", "Toronto"
],
q.sql_query