prepare SGX for use with jmp-fwdcalls, which is V1
Denver Gingerich
created
Until Bandwidth supports SIP endpoints in their V2 voice API, we need
to use their V1 voice API. However, to use the V1 voice API alongside
the V2 messages API, we need to be a bit clever. In particular, we
need to detect when we're getting a V1 call and adjust the URL
accordingly.
The hack implemented here to accomplish this allows us to make very
minimal changes to jmp-fwdcalls (letting it continue to use an
unmodified call_catapult() invocation) while still permitting it to
work with the V2 SGX (this one) as well as the V1 SGX. As noted in
this commit's comments, jmp-fwdcalls will need to pass us some V1
credentials to use (since the V2 user won't have these available in
its creds list). But that should be the only added complexity here.
@@ -200,9 +200,25 @@ module SGXbwmsgsv2
token, secret, m, pth, body=nil,
head={}, code=[200], respond_with=:body
)
+ # pth looks like one of:
+ # "api/v2/users/#{user_id}/[endpoint_name]"
+ # "v1/users/#{user_id}/[endpoint_name]"
+
+ url_prefix = ''
+
# TODO: need to make a separate thing for voice.bw.c eventually
+ if pth.start_with? 'api/v2/users'
+ url_prefix = 'https://messaging.bandwidth.com/'
+ elsif pth.start_with? 'v1/users'
+ # begin hack for running V2 messages along with V1 voice
+ url_prefix = 'https://api.catapult.inetwork.com/'
+ # TODO: set token and secret to vals provided at startup
+ else
+ # TODO: error
+ end
+
EM::HttpRequest.new(
- "https://messaging.bandwidth.com/#{pth}"
+ url_prefix + pth
).public_send(
m,
head: {