slybroadcast 1.0.3 → 1.0.4
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 +4 -4
- data/README.md +32 -3
- data/lib/slybroadcast/client.rb +10 -2
- data/lib/slybroadcast/parsers/campaign_call_response.rb +35 -0
- data/lib/slybroadcast/parsers/campaign_status_response.rb +13 -7
- data/lib/slybroadcast/utilities.rb +4 -9
- data/lib/slybroadcast/version.rb +1 -1
- data/test/client.rb +33 -3
- data/test/parsers.rb +3 -3
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: caaeef359ba8cfb00eea77d0203e113171ffe33c
|
|
4
|
+
data.tar.gz: 819d1f1eef95186e44dd82bddcdded3974df6693
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1b90390d2ea2c34a55613af468ec44bb5acc637ab06a35772d35f7cf0fd2f35edea8061f0a1df3141f3bbbc21055871b401935b9647e35c5c0cc202e4b8e9466
|
|
7
|
+
data.tar.gz: d66a1d8b8af92f002472a4334e353f7ce404d0708a91981fdecf240afc20cb59c18fcd5d727b00bda74a957e0805bb5a327ac85403265b4391f814f278533407
|
data/README.md
CHANGED
|
@@ -65,7 +65,7 @@ Campaign submission with audio file previously uploaded.
|
|
|
65
65
|
|
|
66
66
|
``` ruby
|
|
67
67
|
|
|
68
|
-
result = Slybroadcast::Client.
|
|
68
|
+
result = Slybroadcast::Client.campaign_call(
|
|
69
69
|
c_phone: "+16173999981, +16173999982, +16173999983",
|
|
70
70
|
c_record_audio: "Meetup1",
|
|
71
71
|
c_callerID: "+16173999980",
|
|
@@ -93,7 +93,7 @@ Campaign submission using a client's audio file.
|
|
|
93
93
|
|
|
94
94
|
``` ruby
|
|
95
95
|
|
|
96
|
-
result = Slybroadcast::Client.
|
|
96
|
+
result = Slybroadcast::Client.campaign_call(
|
|
97
97
|
c_phone: "+16173999981, +16173999982, +16173999983",
|
|
98
98
|
c_url: "https://user_audio_url",
|
|
99
99
|
c_callerID: "+16173999980",
|
|
@@ -134,7 +134,9 @@ Example
|
|
|
134
134
|
|
|
135
135
|
``` ruby
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
example_body = "9996130985|9996449444|OK||2017-05-11 17:38:18|verizon wireless:6006 - svr/2"
|
|
138
|
+
|
|
139
|
+
Slybroadcast::Utilities.callback_parser(example_body) do |session_id, phone_number, status, failure_reason, delivery_time, carrier|
|
|
138
140
|
{
|
|
139
141
|
session_id: session_id,
|
|
140
142
|
phone_number: phone_number,
|
|
@@ -145,6 +147,33 @@ Slybroadcast::Utilities.callback_parser(body) do |session_id, phone_number, stat
|
|
|
145
147
|
}
|
|
146
148
|
end
|
|
147
149
|
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Request Status Campaign
|
|
153
|
+
|
|
154
|
+
To request the call status of one phone number, the following parameters must be included. Be sure the session_id is the one received in response to your initial campaign submission.
|
|
155
|
+
|
|
156
|
+
``` ruby
|
|
157
|
+
|
|
158
|
+
result = Slybroadcast::Client.campaign_status(
|
|
159
|
+
session_id: "123456",
|
|
160
|
+
c_phone: "9996449444"
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
result.success?
|
|
164
|
+
true
|
|
165
|
+
|
|
166
|
+
result.call
|
|
167
|
+
{
|
|
168
|
+
:session_id=>"123456",
|
|
169
|
+
:phone_number=>"9996449444",
|
|
170
|
+
:status=>"OK",
|
|
171
|
+
:failure_reason=>"",
|
|
172
|
+
:delivery_time=>"2017-05-11 17:38:18",
|
|
173
|
+
:carrier=>"verizon wireless:6006 - svr/2"
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
148
177
|
```
|
|
149
178
|
|
|
150
179
|
### Pause Campaign
|
data/lib/slybroadcast/client.rb
CHANGED
|
@@ -2,6 +2,7 @@ require 'singleton'
|
|
|
2
2
|
require 'uri'
|
|
3
3
|
require 'net/http'
|
|
4
4
|
require_relative 'exceptions'
|
|
5
|
+
require_relative 'parsers/campaign_call_response'
|
|
5
6
|
require_relative 'parsers/campaign_status_response'
|
|
6
7
|
require_relative 'parsers/campaign_actions_response'
|
|
7
8
|
require_relative 'parsers/remaining_messages_response'
|
|
@@ -28,7 +29,8 @@ module Slybroadcast
|
|
|
28
29
|
API_URI = 'https://www.mobile-sphere.com/gateway'.freeze
|
|
29
30
|
ENDPOINTS = {
|
|
30
31
|
verify: 'vmb.php',
|
|
31
|
-
|
|
32
|
+
campaign_call: 'vmb.php',
|
|
33
|
+
campaign_status: 'vmb.php',
|
|
32
34
|
campaign: 'vmb.php',
|
|
33
35
|
account_message_balance: 'vmb.php',
|
|
34
36
|
download_audio_file: 'vmb.dla.php',
|
|
@@ -50,9 +52,15 @@ module Slybroadcast
|
|
|
50
52
|
true
|
|
51
53
|
end
|
|
52
54
|
|
|
53
|
-
def
|
|
55
|
+
def campaign_call(**options)
|
|
54
56
|
params = set_credentials(options)
|
|
55
57
|
res = make_post(endpoint_url, params)
|
|
58
|
+
parse_response(:CampaignCallResponse, res)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def campaign_status(**options)
|
|
62
|
+
params = set_credentials(options.merge(c_option: :callstatus))
|
|
63
|
+
res = make_post(endpoint_url, params)
|
|
56
64
|
parse_response(:CampaignStatusResponse, res)
|
|
57
65
|
end
|
|
58
66
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Parsers
|
|
2
|
+
class CampaignCallResponse
|
|
3
|
+
attr_accessor :success
|
|
4
|
+
attr_accessor :error
|
|
5
|
+
attr_accessor :session_id
|
|
6
|
+
attr_accessor :number_of_phone
|
|
7
|
+
|
|
8
|
+
def initialize(body)
|
|
9
|
+
response_parse(body)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def failed?
|
|
13
|
+
not success?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def success?
|
|
17
|
+
success
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def response_parse(body)
|
|
23
|
+
response = body.split("\n")
|
|
24
|
+
@success = response[0].strip == 'OK'
|
|
25
|
+
|
|
26
|
+
unless success
|
|
27
|
+
@error = response[1]
|
|
28
|
+
else
|
|
29
|
+
@session_id = response[1].split("=")[1]
|
|
30
|
+
@number_of_phone = response[2].split("=")[1]
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -2,8 +2,7 @@ module Parsers
|
|
|
2
2
|
class CampaignStatusResponse
|
|
3
3
|
attr_accessor :success
|
|
4
4
|
attr_accessor :error
|
|
5
|
-
attr_accessor :
|
|
6
|
-
attr_accessor :number_of_phone
|
|
5
|
+
attr_accessor :call
|
|
7
6
|
|
|
8
7
|
def initialize(body)
|
|
9
8
|
response_parse(body)
|
|
@@ -20,14 +19,21 @@ module Parsers
|
|
|
20
19
|
private
|
|
21
20
|
|
|
22
21
|
def response_parse(body)
|
|
23
|
-
|
|
24
|
-
@success = response[0].strip == 'OK'
|
|
22
|
+
@success = !body.include?('ERROR')
|
|
25
23
|
|
|
26
24
|
unless success
|
|
27
|
-
|
|
25
|
+
response = body.split("\n")
|
|
26
|
+
@error = response[1].strip
|
|
28
27
|
else
|
|
29
|
-
|
|
30
|
-
@
|
|
28
|
+
session_id, phone_number, status, failure_reason, delivery_time, carrier = body.gsub('var=','').split('|', 6)
|
|
29
|
+
@call = {
|
|
30
|
+
session_id: session_id,
|
|
31
|
+
phone_number: phone_number,
|
|
32
|
+
status: status,
|
|
33
|
+
failure_reason: failure_reason,
|
|
34
|
+
delivery_time: delivery_time,
|
|
35
|
+
carrier: carrier
|
|
36
|
+
}
|
|
31
37
|
end
|
|
32
38
|
end
|
|
33
39
|
|
|
@@ -4,8 +4,9 @@ module Slybroadcast
|
|
|
4
4
|
|
|
5
5
|
#
|
|
6
6
|
# Usage
|
|
7
|
+
# example_body = "9996130985|9996449444|OK||2017-05-11 17:38:18|verizon wireless:6006 - svr/2"
|
|
7
8
|
#
|
|
8
|
-
# Slybroadcast::Utilities.callback_parser(
|
|
9
|
+
# Slybroadcast::Utilities.callback_parser(example_body) do |session_id, phone_number, status, failure_reason, delivery_time, carrier|
|
|
9
10
|
# {
|
|
10
11
|
# session_id: session_id,
|
|
11
12
|
# phone_number: phone_number,
|
|
@@ -17,14 +18,8 @@ module Slybroadcast
|
|
|
17
18
|
# end
|
|
18
19
|
#
|
|
19
20
|
def callback_parser(body)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
line.delete!('\\"')
|
|
23
|
-
cols = line.split("|",6)
|
|
24
|
-
cols.compact!
|
|
25
|
-
cols.insert(3,nil) if cols.size == 5
|
|
26
|
-
yield *cols
|
|
27
|
-
end
|
|
21
|
+
session_id, phone_number, status, failure_reason, delivery_time, carrier = body.split('|', 6)
|
|
22
|
+
yield session_id, phone_number, status, failure_reason, delivery_time, carrier
|
|
28
23
|
end
|
|
29
24
|
|
|
30
25
|
end
|
data/lib/slybroadcast/version.rb
CHANGED
data/test/client.rb
CHANGED
|
@@ -29,7 +29,7 @@ describe Slybroadcast::Client do
|
|
|
29
29
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
describe '
|
|
32
|
+
describe 'campaign_call' do
|
|
33
33
|
|
|
34
34
|
it 'should return session ID' do
|
|
35
35
|
|
|
@@ -37,7 +37,7 @@ describe Slybroadcast::Client do
|
|
|
37
37
|
mocked_reponse.expect(:body, "OK\nsession ID=123456\nNumber of Phone=2")
|
|
38
38
|
|
|
39
39
|
Net::HTTP.stub :post_form, mocked_reponse do
|
|
40
|
-
result = Slybroadcast::Client.
|
|
40
|
+
result = Slybroadcast::Client.campaign_call({})
|
|
41
41
|
assert_equal result.session_id, "123456"
|
|
42
42
|
assert_equal result.number_of_phone, "2"
|
|
43
43
|
end
|
|
@@ -51,7 +51,37 @@ describe Slybroadcast::Client do
|
|
|
51
51
|
|
|
52
52
|
Net::HTTP.stub :post_form, mocked_reponse do
|
|
53
53
|
assert_raises Slybroadcast::Exceptions::InvalidCredentials do
|
|
54
|
-
Slybroadcast::Client.
|
|
54
|
+
Slybroadcast::Client.campaign_call({})
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe 'campaign_status' do
|
|
63
|
+
|
|
64
|
+
it 'should return session ID' do
|
|
65
|
+
|
|
66
|
+
mocked_reponse = MiniTest::Mock.new
|
|
67
|
+
mocked_reponse.expect(:body, "var=9996130985|9996449444|OK||2017-05-11 17:38:18|verizon wireless:6006 - svr/2")
|
|
68
|
+
|
|
69
|
+
Net::HTTP.stub :post_form, mocked_reponse do
|
|
70
|
+
result = Slybroadcast::Client.campaign_status({})
|
|
71
|
+
assert_equal result.call[:status], "OK"
|
|
72
|
+
assert_equal result.call[:session_id], "9996130985"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'should raise Exceptions::InvalidCredentials' do
|
|
78
|
+
|
|
79
|
+
mocked_reponse = MiniTest::Mock.new
|
|
80
|
+
mocked_reponse.expect(:body, "ERROR\nc_uid: required")
|
|
81
|
+
|
|
82
|
+
Net::HTTP.stub :post_form, mocked_reponse do
|
|
83
|
+
assert_raises Slybroadcast::Exceptions::InvalidCredentials do
|
|
84
|
+
Slybroadcast::Client.campaign_status({})
|
|
55
85
|
end
|
|
56
86
|
end
|
|
57
87
|
|
data/test/parsers.rb
CHANGED
|
@@ -24,12 +24,12 @@ describe Parsers do
|
|
|
24
24
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
describe '
|
|
27
|
+
describe 'CampaignCallResponse' do
|
|
28
28
|
|
|
29
29
|
it 'should return session ID' do
|
|
30
30
|
|
|
31
31
|
response = "OK\nSession ID=123456\nNumber of Phone=123"
|
|
32
|
-
result = Parsers::
|
|
32
|
+
result = Parsers::CampaignCallResponse.new(response)
|
|
33
33
|
assert result.success?
|
|
34
34
|
assert_equal result.session_id, "123456"
|
|
35
35
|
assert_equal result.number_of_phone, "123"
|
|
@@ -39,7 +39,7 @@ describe Parsers do
|
|
|
39
39
|
it 'should return error description' do
|
|
40
40
|
|
|
41
41
|
response = "ERROR\nc_uid: required"
|
|
42
|
-
result = Parsers::
|
|
42
|
+
result = Parsers::CampaignCallResponse.new(response)
|
|
43
43
|
assert result.failed?
|
|
44
44
|
assert_equal result.error, "c_uid: required"
|
|
45
45
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: slybroadcast
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Martin Aceto
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-05-
|
|
11
|
+
date: 2017-05-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A minimal Slybroadcast Ruby client implementation
|
|
14
14
|
email:
|
|
@@ -26,6 +26,7 @@ files:
|
|
|
26
26
|
- lib/slybroadcast/exceptions.rb
|
|
27
27
|
- lib/slybroadcast/parsers/audio_file_list_response.rb
|
|
28
28
|
- lib/slybroadcast/parsers/campaign_actions_response.rb
|
|
29
|
+
- lib/slybroadcast/parsers/campaign_call_response.rb
|
|
29
30
|
- lib/slybroadcast/parsers/campaign_status_response.rb
|
|
30
31
|
- lib/slybroadcast/parsers/download_audio_file_response.rb
|
|
31
32
|
- lib/slybroadcast/parsers/remaining_messages_response.rb
|