globe_connect 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +131 -0
- data/Rakefile +2 -0
- data/Sample.md +121 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/globe_connect.gemspec +41 -0
- data/http/voice.rb +388 -0
- data/lib/globe_connect.rb +18 -0
- data/lib/globe_connect/amax.rb +46 -0
- data/lib/globe_connect/authentication.rb +39 -0
- data/lib/globe_connect/base.rb +58 -0
- data/lib/globe_connect/location_query.rb +29 -0
- data/lib/globe_connect/payment.rb +65 -0
- data/lib/globe_connect/sms.rb +90 -0
- data/lib/globe_connect/subscriber.rb +43 -0
- data/lib/globe_connect/ussd.rb +77 -0
- data/lib/globe_connect/version.rb +3 -0
- data/lib/globe_connect/voice.rb +423 -0
- metadata +112 -0
data/http/voice.rb
ADDED
@@ -0,0 +1,388 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require '../lib/connect_ruby'
|
3
|
+
|
4
|
+
before do
|
5
|
+
content_type 'application/json'
|
6
|
+
end
|
7
|
+
|
8
|
+
get '/answer' do
|
9
|
+
voice = Voice.new
|
10
|
+
|
11
|
+
voice.say("Welcome to my Tropo Web API.")
|
12
|
+
voice.hangup
|
13
|
+
|
14
|
+
content_type :json
|
15
|
+
voice.render
|
16
|
+
end
|
17
|
+
|
18
|
+
get '/ask' do
|
19
|
+
voice = Voice.new
|
20
|
+
|
21
|
+
voice.say("Welcome to my Tropo Web API.");
|
22
|
+
|
23
|
+
say = voice.say("Please enter your 5 digit zip code.", {}, true)
|
24
|
+
choices = voice.choices({ :value => "[5 DIGITS]" }, true)
|
25
|
+
|
26
|
+
voice.ask({
|
27
|
+
:choices => choices,
|
28
|
+
:attempts => 3,
|
29
|
+
:bargein => false,
|
30
|
+
:name => "foo",
|
31
|
+
:required => true,
|
32
|
+
:say => say,
|
33
|
+
:timeout => 10
|
34
|
+
})
|
35
|
+
|
36
|
+
voice.on({
|
37
|
+
:name => "continue",
|
38
|
+
:next => "http://somefakehost.com:8000",
|
39
|
+
:required => true
|
40
|
+
})
|
41
|
+
|
42
|
+
content_type :json
|
43
|
+
voice.render
|
44
|
+
end
|
45
|
+
|
46
|
+
get '/ask-test' do
|
47
|
+
voice = Voice.new
|
48
|
+
|
49
|
+
say = voice.say("Please enter your 5 digit zip code.", {}, true)
|
50
|
+
choices = voice.choices({:value => "[5 DIGITS]"})
|
51
|
+
|
52
|
+
voice.ask({
|
53
|
+
:choices => choices,
|
54
|
+
:attempts => 3,
|
55
|
+
:bargein => false,
|
56
|
+
:name => "foo",
|
57
|
+
:required => true,
|
58
|
+
:say => say,
|
59
|
+
:timeout => 10
|
60
|
+
})
|
61
|
+
|
62
|
+
voice.on({
|
63
|
+
:name => "continue",
|
64
|
+
:next => "http://somefakehost.com:8000",
|
65
|
+
:required => true
|
66
|
+
})
|
67
|
+
|
68
|
+
content_type :json
|
69
|
+
voice.render
|
70
|
+
end
|
71
|
+
|
72
|
+
post '/ask-answer' do
|
73
|
+
# get data from post
|
74
|
+
payload = JSON.parse(request.body.read)
|
75
|
+
|
76
|
+
voice = Voice.new
|
77
|
+
voice.say("Your zip code is " + payload[:result][:actions][:disposition] + ", thank you!")
|
78
|
+
|
79
|
+
content_type :json
|
80
|
+
voice.render
|
81
|
+
end
|
82
|
+
|
83
|
+
get '/call' do
|
84
|
+
voice = Voice.new
|
85
|
+
|
86
|
+
voice.call({
|
87
|
+
:to => "9065263453",
|
88
|
+
:from => "906572450"
|
89
|
+
})
|
90
|
+
|
91
|
+
say = Array.new
|
92
|
+
say << voice.say("Hello world", {}, true)
|
93
|
+
voice.say(say)
|
94
|
+
|
95
|
+
content_type :json
|
96
|
+
voice.render
|
97
|
+
end
|
98
|
+
|
99
|
+
get '/conference' do
|
100
|
+
voice = Voice.new
|
101
|
+
|
102
|
+
voice.say("Welcome to my Tropo Web API Conference Call.");
|
103
|
+
|
104
|
+
voice.conference({
|
105
|
+
:id => "12345",
|
106
|
+
:mute => false,
|
107
|
+
:name => "foo",
|
108
|
+
:play_tones => true,
|
109
|
+
:terminator => "#",
|
110
|
+
:join_prompt => voice.join_prompt({:value => "http://openovate.com/hold-music.mp3"}, true),
|
111
|
+
:leave_prompt => voice.join_prompt({:value => "http://openovate.com/hold-music.mp3"}, true),
|
112
|
+
})
|
113
|
+
|
114
|
+
content_type :json
|
115
|
+
voice.render
|
116
|
+
end
|
117
|
+
|
118
|
+
get '/event' do
|
119
|
+
voice = Voice.new
|
120
|
+
|
121
|
+
voice.say("Welcome to my Tropo Web API.")
|
122
|
+
|
123
|
+
say1 = voice.say("Sorry, I did not hear anything", {:event => "timeout"}, true)
|
124
|
+
|
125
|
+
say2 = voice.say({
|
126
|
+
:value => "Sorry, that was not a valid option.",
|
127
|
+
:event => "nomatch:1"
|
128
|
+
}, {}, true)
|
129
|
+
|
130
|
+
say3 = voice.say({
|
131
|
+
:value => "Nope, still not a valid response",
|
132
|
+
:event => "nomatch:2"
|
133
|
+
}, {}, true)
|
134
|
+
|
135
|
+
say4 = voice.say({
|
136
|
+
:value => "Please enter your 5 digit zip code.",
|
137
|
+
:array => [say1, say2, say3]
|
138
|
+
}, {}, true)
|
139
|
+
|
140
|
+
choices = voice.choices({ :value => "[5 DIGITS]" }, true)
|
141
|
+
|
142
|
+
voice.ask({
|
143
|
+
:choices => choices,
|
144
|
+
:attempts => 3,
|
145
|
+
:bargein => false,
|
146
|
+
:required => true,
|
147
|
+
:say => say4,
|
148
|
+
:timeout => 5
|
149
|
+
})
|
150
|
+
|
151
|
+
voice.on({
|
152
|
+
:event => "continue",
|
153
|
+
:next => "http://somefakehost:8000/",
|
154
|
+
:required => true
|
155
|
+
})
|
156
|
+
|
157
|
+
content_type :json
|
158
|
+
voice.render
|
159
|
+
end
|
160
|
+
|
161
|
+
get '/hangup' do
|
162
|
+
voice = Voice.new
|
163
|
+
|
164
|
+
voice.say("Welcome to my Tropo Web API, thank you!")
|
165
|
+
voice.hangup
|
166
|
+
|
167
|
+
content_type :json
|
168
|
+
voice.render
|
169
|
+
end
|
170
|
+
|
171
|
+
get '/routing' do
|
172
|
+
voice = Voice.new
|
173
|
+
|
174
|
+
voice.say("Welcome to my Tropo Web API.");
|
175
|
+
voice.on({
|
176
|
+
:event => "continue",
|
177
|
+
:next => '/routing-1'
|
178
|
+
});
|
179
|
+
|
180
|
+
content_type :json
|
181
|
+
voice.render
|
182
|
+
end
|
183
|
+
|
184
|
+
get '/routing-1' do
|
185
|
+
voice = Voice.new
|
186
|
+
|
187
|
+
voice.say("Hello from resource one!");
|
188
|
+
voice.on({
|
189
|
+
:event => "continue",
|
190
|
+
:next => '/routing-2'
|
191
|
+
});
|
192
|
+
|
193
|
+
content_type :json
|
194
|
+
voice.render
|
195
|
+
end
|
196
|
+
|
197
|
+
get '/routing-2' do
|
198
|
+
voice = Voice.new
|
199
|
+
|
200
|
+
voice.say("Hello from resource two! thank you.");
|
201
|
+
|
202
|
+
content_type :json
|
203
|
+
voice.render
|
204
|
+
end
|
205
|
+
|
206
|
+
get '/record' do
|
207
|
+
voice = Voice.new
|
208
|
+
|
209
|
+
voice.say("Welcome to my Tropo Web API.");
|
210
|
+
|
211
|
+
timeout = voice.say(
|
212
|
+
"Sorry, I did not hear anything. Please call back.",
|
213
|
+
{ :event => "timeout"},
|
214
|
+
true)
|
215
|
+
|
216
|
+
say = voice.say("Please leave a message", {:array => timeout}, true);
|
217
|
+
|
218
|
+
choices = voice.choices({:terminator => "#"}, true)
|
219
|
+
|
220
|
+
transcription = voice.transcription({
|
221
|
+
:id => "1234",
|
222
|
+
:url => "mailto:address@email.com"
|
223
|
+
}, true)
|
224
|
+
|
225
|
+
voice.record({
|
226
|
+
:attempts => 3,
|
227
|
+
:bargein => false,
|
228
|
+
:method => "POST",
|
229
|
+
:required => true,
|
230
|
+
:say => say,
|
231
|
+
:name => "foo",
|
232
|
+
:url => "http://openovate.com/globe.php",
|
233
|
+
:format => "audio/wav",
|
234
|
+
:choices => choices,
|
235
|
+
:transcription => transcription
|
236
|
+
})
|
237
|
+
|
238
|
+
content_type :json
|
239
|
+
voice.render
|
240
|
+
end
|
241
|
+
|
242
|
+
get '/reject' do
|
243
|
+
voice = Voice.new
|
244
|
+
|
245
|
+
voice.reject
|
246
|
+
|
247
|
+
content_type :json
|
248
|
+
voice.render
|
249
|
+
end
|
250
|
+
|
251
|
+
get '/say' do
|
252
|
+
voice = Voice.new
|
253
|
+
|
254
|
+
voice.say("Welcome to my Tropo Web API.");
|
255
|
+
voice.say("I will play an audio file for you, please wait.");
|
256
|
+
voice.say({
|
257
|
+
:value => "http://openovate.com/tropo-rocks.mp3"
|
258
|
+
})
|
259
|
+
|
260
|
+
content_type :json
|
261
|
+
voice.render
|
262
|
+
end
|
263
|
+
|
264
|
+
get '/transfer' do
|
265
|
+
voice = Voice.new
|
266
|
+
|
267
|
+
voice.say("Welcome to my Tropo Web API, you are now being transferred.");
|
268
|
+
|
269
|
+
e1 = voice.say({
|
270
|
+
:value => "Sorry, I did not hear anything.",
|
271
|
+
:event => "timeout"
|
272
|
+
}, {} ,true)
|
273
|
+
|
274
|
+
e2 = voice.say({
|
275
|
+
:value => "Sorry, that was not a valid option.",
|
276
|
+
:event => "nomatch:1"
|
277
|
+
}, {} ,true)
|
278
|
+
|
279
|
+
e3 = voice.say({
|
280
|
+
:value => "Nope, still not a valid response",
|
281
|
+
:event => "nomatch:2"
|
282
|
+
}, {} ,true)
|
283
|
+
|
284
|
+
# TODO: [e1, e2, e3]
|
285
|
+
say = voice.say("Please enter your 5 digit zip code", {}, true)
|
286
|
+
|
287
|
+
choices = voice.choices({:value => "[5 DIGITs]"}, true)
|
288
|
+
|
289
|
+
ask = voice.ask({
|
290
|
+
:choices => choices,
|
291
|
+
:attempts => 3,
|
292
|
+
:bargein => false,
|
293
|
+
:name => "foo",
|
294
|
+
:required => true,
|
295
|
+
:say => say,
|
296
|
+
:timeout => 5
|
297
|
+
}, true)
|
298
|
+
|
299
|
+
ring = voice.on({
|
300
|
+
:event => "ring",
|
301
|
+
:say => voice.say("http://openovate.com/hold-music.mp3", {} ,true)
|
302
|
+
}, true)
|
303
|
+
|
304
|
+
connect = voice.on({
|
305
|
+
:event => "connect",
|
306
|
+
:ask => ask
|
307
|
+
}, true)
|
308
|
+
|
309
|
+
on = voice.on([ring, connect], true)
|
310
|
+
|
311
|
+
voice.transfer({
|
312
|
+
:to => "9271223448",
|
313
|
+
:ring_repeat => 2,
|
314
|
+
:on => on
|
315
|
+
})
|
316
|
+
|
317
|
+
content_type :json
|
318
|
+
voice.render
|
319
|
+
end
|
320
|
+
|
321
|
+
get '/transfer-whisper' do
|
322
|
+
voice = Voice.new
|
323
|
+
|
324
|
+
voice.say("Welcome to my Tropo Web API, please hold while you are being transferred.");
|
325
|
+
|
326
|
+
say = voice.say("Press 1 to accept this call or any other number to reject", {}, true);
|
327
|
+
|
328
|
+
choices = voice.choices({
|
329
|
+
:value => 1,
|
330
|
+
:mode => "dtmf"
|
331
|
+
}, true)
|
332
|
+
|
333
|
+
ask = voice.ask({
|
334
|
+
:choices => choices,
|
335
|
+
:name => "color",
|
336
|
+
:say => say,
|
337
|
+
:timeout => 60
|
338
|
+
}, true)
|
339
|
+
|
340
|
+
connect1 = voice.on({
|
341
|
+
:event => "connect",
|
342
|
+
:ask => ask
|
343
|
+
}, true)
|
344
|
+
|
345
|
+
connect2 = voice.on({
|
346
|
+
:event => "connect",
|
347
|
+
:say => voice.say("You are now being connected", {}, true)
|
348
|
+
}, true)
|
349
|
+
|
350
|
+
ring = voice.on({
|
351
|
+
:event => "ring",
|
352
|
+
:say => voice.say("http://openovate.com/hold-music.mp3", {}, true)
|
353
|
+
}, true)
|
354
|
+
|
355
|
+
connect = voice.on([ring, connect1, connect2], true)
|
356
|
+
|
357
|
+
voice.transfer({
|
358
|
+
:to => "9271223448",
|
359
|
+
:name => "foo",
|
360
|
+
:connect => connect,
|
361
|
+
:required => true,
|
362
|
+
:terminator => "*"
|
363
|
+
})
|
364
|
+
|
365
|
+
voice.on({
|
366
|
+
:event => "incomplete",
|
367
|
+
:next => "/transfer-whisper-hangup",
|
368
|
+
:say => voice.say("You are now being disconnected", {}, true)
|
369
|
+
})
|
370
|
+
|
371
|
+
content_type :json
|
372
|
+
voice.render
|
373
|
+
end
|
374
|
+
|
375
|
+
get '/wait' do
|
376
|
+
voice = Voice.new
|
377
|
+
|
378
|
+
voice.say("Welcome to my Tropo Web API, please wait for a while.")
|
379
|
+
voice.wait({
|
380
|
+
:wait => 5000,
|
381
|
+
:allowSignals => true
|
382
|
+
})
|
383
|
+
|
384
|
+
voice.say("Thank you for waiting!")
|
385
|
+
|
386
|
+
content_type :json
|
387
|
+
voice.render
|
388
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
require_relative "./globe_connect/base"
|
6
|
+
require_relative "./globe_connect/amax"
|
7
|
+
require_relative "./globe_connect/authentication"
|
8
|
+
require_relative "./globe_connect/location_query"
|
9
|
+
require_relative "./globe_connect/sms"
|
10
|
+
require_relative "./globe_connect/subscriber"
|
11
|
+
require_relative "./globe_connect/payment"
|
12
|
+
require_relative "./globe_connect/ussd"
|
13
|
+
require_relative "./globe_connect/version"
|
14
|
+
require_relative "./globe_connect/voice"
|
15
|
+
|
16
|
+
module GlobeConnect
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class Amax < Base
|
2
|
+
|
3
|
+
AMAX_URL = 'https://devapi.globelabs.com.ph/rewards/v1/transactions/send'
|
4
|
+
|
5
|
+
attr_accessor :app_id, :app_secret
|
6
|
+
|
7
|
+
# Starts up whenever the class is being called
|
8
|
+
#
|
9
|
+
# @param app_id
|
10
|
+
# @param app_secret
|
11
|
+
# @return Amax
|
12
|
+
def initialize(app_id, app_secret)
|
13
|
+
@app_id = app_id
|
14
|
+
@app_secret = app_secret
|
15
|
+
end
|
16
|
+
|
17
|
+
# Sends reward details to the given address
|
18
|
+
#
|
19
|
+
# @param address
|
20
|
+
# @param promo
|
21
|
+
# @param rewards_token
|
22
|
+
# @return json
|
23
|
+
def send_reward_request(address, promo, rewards_token)
|
24
|
+
# set the request url
|
25
|
+
url = AMAX_URL
|
26
|
+
|
27
|
+
# set the payload
|
28
|
+
payload = {
|
29
|
+
"outboundRewardRequest" => {
|
30
|
+
"app_id" => @app_id,
|
31
|
+
"app_secret" => @app_secret,
|
32
|
+
"rewards_token" => rewards_token,
|
33
|
+
"address" => address,
|
34
|
+
"promo" => promo
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
# convert to JSON
|
39
|
+
payload = JSON.generate(payload)
|
40
|
+
|
41
|
+
# send post request
|
42
|
+
response = send_post_request(url, payload)
|
43
|
+
|
44
|
+
return JSON.parse(response)
|
45
|
+
end
|
46
|
+
end
|