Option to "just show me some numbers"

Stephen Paul Weber created

If you use it with a blank search it pulls from a fallback list for now.

Change summary

forms/tn_search.rb          | 12 +++++++++++-
lib/tel_selections.rb       | 11 ++++++++++-
test/test_tel_selections.rb | 18 ++++++++++++++++++
3 files changed, 39 insertions(+), 2 deletions(-)

Detailed changes

forms/tn_search.rb 🔗

@@ -12,7 +12,6 @@ end
 
 field(
 	var: "q",
-	required: true,
 	type: "text-single",
 	label: "Search Telephone Numbers",
 	description:
@@ -21,4 +20,15 @@ field(
 		"or indicate a vanity pattern with ~"
 )
 
+field(
+	label: "Action",
+	type: "list-single",
+	var: "http://jabber.org/protocol/commands#actions",
+	options: [
+		{ label: "Search", value: "next" },
+		{ label: "Just Show Me Some Numbers", value: "feelinglucky" }
+	],
+	value: "next"
+)
+
 xml.set(xmlns: "http://jabber.org/protocol/rsm")

lib/tel_selections.rb 🔗

@@ -80,7 +80,7 @@ class TelSelections
 				qs = form.field("q")&.value.to_s.strip
 				return qs if qs =~ /\A\+1\d{10}\Z/
 
-				q = Q.for(qs, db: db, memcache: memcache)
+				q = Q.for(feelinglucky(qs, form), db: db, memcache: memcache)
 
 				new(
 					q.iris_query
@@ -91,6 +91,15 @@ class TelSelections
 				)
 			end
 
+			ACTION_FIELD = "http://jabber.org/protocol/commands#actions"
+
+			def self.feelinglucky(q, form)
+				return q unless q.empty?
+				return q unless form.field(ACTION_FIELD)&.value == "feelinglucky"
+
+				"810"
+			end
+
 			def initialize(iris_query, fallback: [], memcache: MEMCACHE)
 				@iris_query = iris_query
 				@fallback = fallback

test/test_tel_selections.rb 🔗

@@ -56,6 +56,24 @@ class TelSelectionsTest < Minitest::Test
 			)
 		end
 
+		def test_for_feelinglucky
+			form = Blather::Stanza::X.new
+			form.fields = [
+				{ var: "q", value: "" },
+				{
+					var: "http://jabber.org/protocol/commands#actions",
+					value: "feelinglucky"
+				}
+			]
+			iris_query = TelSelections::ChooseTel::AvailableNumber
+				.for(form, db: FakeDB.new, memcache: FakeMemcache.new)
+				.instance_variable_get(:@iris_query)
+			assert_equal(
+				{ areaCode: "810", enableTNDetail: true, LCA: false, quantity: 10 },
+				iris_query
+			)
+		end
+
 		def test_fallback
 			stub_request(
 				:get,