From 0874c1bf5d274208703050f9a779fd4a4ab55927 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 19 Jan 2022 11:30:13 -0500 Subject: [PATCH] Allow injecting a customer repo into Web --- web.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/web.rb b/web.rb index 3f22f72d871007f3428ef46fedab5aedf0e425a6..a19cb7bad501350e69b5f2e1e6d06922dbe2805d 100644 --- a/web.rb +++ b/web.rb @@ -97,6 +97,10 @@ class Web < Roda end end + def customer_repo(**kwargs) + opts[:customer_repo] || CustomerRepo.new(**kwargs) + end + TEL_CANDIDATES = { "Restricted" => "14", "anonymous" => "15", @@ -152,7 +156,7 @@ class Web < Roda end end - CustomerRepo.new.find_by_tel(params["to"]).then do |customer| + customer_repo.find_by_tel(params["to"]).then do |customer| CDR.for_inbound(customer.customer_id, params).save end end @@ -186,7 +190,7 @@ class Web < Roda "https://jmp.chat" ) - CustomerRepo.new.find_by_tel(params["to"]).then do |customer| + customer_repo.find_by_tel(params["to"]).then do |customer| m = Blather::Stanza::Message.new m.chat_state = nil m.from = from_jid @@ -204,7 +208,7 @@ class Web < Roda Time.parse(params["startTime"]) next "OK<5" unless duration > 5 - CustomerRepo.new.find_by_tel(params["to"]).then do |customer| + customer_repo.find_by_tel(params["to"]).then do |customer| m = Blather::Stanza::Message.new m.chat_state = nil m.from = from_jid @@ -219,8 +223,7 @@ class Web < Roda end r.post do - CustomerRepo - .new(sgx_repo: Bwmsgsv2Repo.new) + customer_repo(sgx_repo: Bwmsgsv2Repo.new) .find_by_tel(params["to"]) .then { |c| EMPromise.all([c, c.ogm(params["from"])]) @@ -239,7 +242,7 @@ class Web < Roda end r.post do - CustomerRepo.new( + customer_repo( sgx_repo: Bwmsgsv2Repo.new ).find_by_tel(params["to"]).then(&:fwd).then do |fwd| call = fwd.create_call(CONFIG[:creds][:account]) { |cc| @@ -272,7 +275,7 @@ class Web < Roda r.post do customer_id = params["from"].sub(/^\+1/, "") - CustomerRepo.new( + customer_repo( sgx_repo: Bwmsgsv2Repo.new ).find(customer_id).then do |c| render :forward, locals: { @@ -298,7 +301,7 @@ class Web < Roda ogm.download.then do File.rename(ogm.path, "#{CONFIG[:ogm_path]}/#{ogm.cid}") File.chmod(0o644, "#{CONFIG[:ogm_path]}/#{ogm.cid}") - CustomerRepo.new.find(params["customer_id"]).then do |customer| + customer_repo.find(params["customer_id"]).then do |customer| customer.set_ogm_url("#{CONFIG[:ogm_web_root]}/#{ogm.cid}.mp3") end end