diff --git a/.rubocop.yml b/.rubocop.yml index d0b95af5f9199af7fff5b3fa40e6d4e650f97c7e..ca9ec06b0c96f156ee1685df2e895d9c483439cf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -55,6 +55,9 @@ Layout/LineLength: Exclude: - Gemfile +Layout/EndAlignment: + EnforcedStyleAlignWith: start_of_line + Layout/SpaceAroundEqualsInParameterDefault: EnforcedStyle: no_space diff --git a/lib/bwmsgsv2_repo.rb b/lib/bwmsgsv2_repo.rb index 429ea6ff25eb930f094abc82ee481f30512b033d..e59c80a771cc78e95f7cbf175e3556dd2390b501 100644 --- a/lib/bwmsgsv2_repo.rb +++ b/lib/bwmsgsv2_repo.rb @@ -50,21 +50,11 @@ class Bwmsgsv2Repo "catapult_fwd_timeout-#{sgx.from_jid}", customer_fwd.timeout.to_i ) - ]).then do - set_default_location(tel) if customer_fwd.v2_safe? - end + ]) end protected - def set_default_location(tel) - # Migrate location if needed - BandwidthIris::SipPeer.new( - site_id: CONFIG[:bandwidth_site], - id: CONFIG[:bandwidth_peer] - ).move_tns([tel]) - end - def set_or_delete(k, v) if v.nil? REDIS.del(k) diff --git a/lib/customer_fwd.rb b/lib/customer_fwd.rb index fbf33631b8d7f2b697d988215b8609d22a5450e0..bee076d3acf7b65b6fdd6cd618d364a6a366981f 100644 --- a/lib/customer_fwd.rb +++ b/lib/customer_fwd.rb @@ -7,14 +7,18 @@ require "uri" class CustomerFwd def self.for(uri:, timeout:) timeout = Timeout.new(timeout) - return None.new(uri: uri, timeout: timeout) if !uri || timeout.zero? - if uri =~ /\Asip:(.*)@sip.cheogram.com\Z/ - uri = "xmpp:#{$1.gsub(/%([0-9A-F]{2})/i) { $1.to_i(16).chr }}" + fwd = if uri + if uri =~ /\Asip:(.*)@sip.cheogram.com\Z/ + uri = "xmpp:#{$1.gsub(/%([0-9A-F]{2})/i) { $1.to_i(16).chr }}" + end + + URIS.fetch(uri.split(":", 2).first.to_sym) { + raise "Unknown forward URI: #{uri}" + }.new(uri: uri, timeout: timeout) end - URIS.fetch(uri.split(":", 2).first.to_sym) { - raise "Unknown forward URI: #{uri}" - }.new(uri: uri, timeout: timeout) + + fwd && !timeout.zero? ? fwd : None.new(uri: uri, timeout: timeout) end class Timeout @@ -57,15 +61,7 @@ class CustomerFwd BANDWIDTH_VOICE.create_call(account, body: request).data.call_id end - def v2_safe? - false - end - class Tel < CustomerFwd - def v2_safe? - true - end - def initialize(values) super raise "Bad tel format: #{uri}" unless uri.match?(/\Atel:\+1\d{10}\Z/) @@ -77,20 +73,12 @@ class CustomerFwd end class SIP < CustomerFwd - def v2_safe? - uri.end_with?(CONFIG[:sip][:realm]) - end - def to uri end end class XMPP < CustomerFwd - def v2_safe? - true - end - def to jid = uri.sub(/^xmpp:/, "") "sip:#{ERB::Util.url_encode(jid)}@sip.cheogram.com"