diff --git a/sgx-bwmsgsv2.rb b/sgx-bwmsgsv2.rb index 2e020f2a0f8481aa098fa4754a1ff8e9ae26c696..e22868044ef45dd3c02ff3b16662f01a1aedf3de 100755 --- a/sgx-bwmsgsv2.rb +++ b/sgx-bwmsgsv2.rb @@ -106,12 +106,32 @@ module SGXbwmsgsv2 end def self.send_media(from, to, media_url, desc=nil, subject=nil, m=nil) - # we assume media_url is of the form (always the case so far): + # we assume media_url is one of these (always the case so far): + # https://api.catapult.inetwork.com/v1/users/[uid]/media/[file] # https://messaging.bandwidth.com/api/v2/users/[u]/media/[path] + usr = to + pth = '' + if media_url.start_with?( + 'https://api.catapult.inetwork.com/v1/users/') + + # TODO: MUST fix this TERRIBLE hack + # there must be a catapult_cred- key with V1 creds + usr = 'v1' + + pth = media_url.split('/', 8)[7] + + elsif media_url.start_with?( + 'https://messaging.bandwidth.com/api/v2/users/') + + pth = media_url.split('/', 9)[8] + else + puts "ERROR2: unrecognized media_url: '#{media_url}'" + return + end + # the caller must guarantee that 'to' is a bare JID - proxy_url = ARGV[6] + WEBrick::HTTPUtils.escape(to) + '/' + - media_url.split('/', 9)[8] + proxy_url = ARGV[6] + WEBrick::HTTPUtils.escape(usr) + '/' + pth puts 'ORIG_URL: ' + media_url puts 'PROX_URL: ' + proxy_url