#!/usr/bin/ruby # frozen_string_literal: true require "dhall" require "net/http" require "pg" require "redis" require "ruby-bandwidth-iris" require_relative "../lib/blather_notify" CONFIG = Dhall.load(ARGV[0]).sync BandwidthIris::Client.global_options = { account_id: CONFIG[:creds][:account], username: CONFIG[:creds][:username], password: CONFIG[:creds][:password] } REDIS = Redis.new DB = PG.connect(dbname: "jmp") DB.type_map_for_results = PG::BasicTypeMapForResults.new(DB) DB.type_map_for_queries = PG::BasicTypeMapForQueries.new(DB) def get_location(tel) BandwidthIris::Tn.get(tel).get_sip_peers[:name] rescue BandwidthIris::Errors::GenericError nil end DB.exec( <<~SQL select customer_id from customer_plans where expires_at > localtimestamp SQL ).each do |row| cid = row["customer_id"] next if REDIS.exists?("catapult_cred-customer_#{cid}@jmp.chat") jid = REDIS.get("jmp_customer_jid-#{cid}") tel = REDIS.lindex("catapult_cred-#{jid}", 3) location = get_location(tel) if location.nil? # in catapult puts tel elsif location == "location1" # in dashboard, using v1 else raise "Unexpected location #{location}" end end