africas_talking 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/africas_talking/base.rb +13 -5
- data/lib/africas_talking/message.rb +13 -30
- data/lib/africas_talking/version.rb +1 -1
- 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: 976f55a5249626e5675cf40c54094c7d9d77ab2f
|
4
|
+
data.tar.gz: 77bc53c0d10571b039e37cb16d2270325d76d95f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fc3ebbb8d19e2037870d82d13d33f1a1f5b943bbe3522797c03040cfadd11277544a02b1876bb05c057a7760fe0d85c68c16f89c42cb563d443540742f41352
|
7
|
+
data.tar.gz: eabfd6eb1cbca68841e462087042b83468aa7a0035a6addee704b7b03608652d8d9e8656570ef48a4981c7c13d5e296b2ca9303e2c6c1b044498ee934a811104
|
data/lib/africas_talking/base.rb
CHANGED
@@ -9,12 +9,14 @@ class AfricasTalking::Base
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def post(url, json_body=nil)
|
12
|
-
|
13
|
-
|
12
|
+
response = Typhoeus.post("#{BASE_URI}#{url}", body: json_body, headers: headers)
|
13
|
+
process_api_response(response)
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def get(url)
|
17
|
+
response = Typhoeus.post("#{BASE_URI}#{url}", headers: headers)
|
18
|
+
response.options[:response_code] == 200 ? build_messages_array(response) : api_error_messages(response)
|
19
|
+
end
|
18
20
|
|
19
21
|
def parse_api_errors(response)
|
20
22
|
reports = parse_api_response(response)["SMSMessageData"]["Recipients"]
|
@@ -39,4 +41,10 @@ class AfricasTalking::Base
|
|
39
41
|
{'Accept' => "application/json", 'apiKey'=> 'c6ec656ed9bceb689289ccaa6e38d7f6c1b0718a1237b4c13391d1efc1108bfb'}
|
40
42
|
end
|
41
43
|
|
44
|
+
def process_api_response(response)
|
45
|
+
return parse_api_response(response) if response.options[:response_code] == 200
|
46
|
+
return parse_api_errors(response) if response.options[:response_code] == 201
|
47
|
+
raise api_error_messages(response)
|
48
|
+
end
|
49
|
+
|
42
50
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class AfricasTalking::Message < AfricasTalking::Base
|
2
|
-
|
2
|
+
|
3
3
|
#POST
|
4
4
|
#/version1/messaging
|
5
5
|
#----------------------------------------------------------------------------
|
@@ -8,8 +8,7 @@ class AfricasTalking::Message < AfricasTalking::Base
|
|
8
8
|
# to = "+254711XXXYYY,+254733YYYZZZ";
|
9
9
|
# And of course we want our recipients to know what we really do
|
10
10
|
def deliver(recipients, message, username)
|
11
|
-
|
12
|
-
process_api_response(response)
|
11
|
+
post('/version1/messaging', {username: username, message: message, to: prepare_recipients(recipients)})
|
13
12
|
end
|
14
13
|
|
15
14
|
#POST
|
@@ -19,14 +18,13 @@ class AfricasTalking::Message < AfricasTalking::Base
|
|
19
18
|
# sender = "shortCode or senderId"
|
20
19
|
|
21
20
|
def deliver_with_shortcode(recipients, message, from, username)
|
22
|
-
|
23
|
-
process_api_response(response)
|
21
|
+
post('/version1/messaging', {username: username, message: message, to: recipients, from: from})
|
24
22
|
end
|
25
23
|
|
26
24
|
#POST
|
27
25
|
#/version1/messaging
|
28
26
|
#----------------------------------------------------------------------------
|
29
|
-
# sender = nil #
|
27
|
+
# sender = nil #
|
30
28
|
# bulkSMSMode # This should always be 1 for bulk messages
|
31
29
|
# # enqueue flag is used to queue messages incase you are sending a high volume.
|
32
30
|
# # The default value is 0.
|
@@ -35,11 +33,9 @@ class AfricasTalking::Message < AfricasTalking::Base
|
|
35
33
|
# reports = gateway.sendMessage(to, message, sender, bulkSMSMode, enqueue)
|
36
34
|
|
37
35
|
def enqueue_messages(opts)
|
38
|
-
|
36
|
+
post('/version1/messaging', {
|
39
37
|
to: opts.fetch(:recipients), message: opts.fetch(:message, ""), sender: opts.fetch(:sender, nil),
|
40
|
-
enqueue: opts.fetch(:enqueue,1), bulkSMSMode: opts.fetch(:bulkSMSMode, 1), username: opts.fetch(:username)}
|
41
|
-
response = post('/version1/messaging', body)
|
42
|
-
process_api_response(response)
|
38
|
+
enqueue: opts.fetch(:enqueue,1), bulkSMSMode: opts.fetch(:bulkSMSMode, 1), username: opts.fetch(:username)})
|
43
39
|
end
|
44
40
|
|
45
41
|
#POST
|
@@ -51,42 +47,29 @@ class AfricasTalking::Message < AfricasTalking::Base
|
|
51
47
|
# To send a premium message, build a HASH (as shown below) with the following attributes keeping in mind the defaults.
|
52
48
|
# 1.Specify your premium shortCode and keyword
|
53
49
|
# 2.Set keyword as None where not used (Mostly for onDemand services)
|
54
|
-
# 3.Set the bulkSMSMode flag to 0 so that the subscriber gets charged
|
50
|
+
# 3.Set the bulkSMSMode flag to 0 so that the subscriber gets charged
|
55
51
|
# 4.Set the enqueue flag to 0 so that your message will not be queued or to 1 for many messages
|
56
52
|
# 5.Incase of an onDemand service, specify the link id. else set it to nil
|
57
53
|
# 6.linkId is received from the message sent by subscriber to your onDemand service
|
58
54
|
# 7.Specify retryDurationInHours: The numbers of hours our API should retry to send the message incase it doesn't go through.
|
59
|
-
|
60
|
-
|
55
|
+
# opts={recipients: "0710335602", message: "Hey there testing something awesome", bulkSMSMode: 0, shortCode:"XXXXX", enqueue: 0, keyword: nil, linkId: "messageLinkId"}
|
56
|
+
|
61
57
|
def deliver_premium_messages(opts)
|
62
|
-
|
58
|
+
post('/version1/messaging', {
|
63
59
|
to: opts.fetch(:recipients), message: opts.fetch(:message),
|
64
60
|
keyword: opts.fetch(:keyword, nil), enqueue: opts.fetch(:enqueue, 0), username: opts.fetch(:username),
|
65
|
-
linkId: opts.fetch(:linkId, nil), retryDurationInHours: opts.fetch(:retryDurationInHours, 1)}
|
66
|
-
response = post('/version1/messaging', body)
|
67
|
-
process_api_response(response)
|
61
|
+
linkId: opts.fetch(:linkId, nil), retryDurationInHours: opts.fetch(:retryDurationInHours, 1)})
|
68
62
|
end
|
69
63
|
|
70
|
-
|
71
64
|
#GET
|
72
65
|
#/?username=#{ENV['africas_talking_username']}&lastReceivedId=#{last_received_id}
|
73
66
|
# The gateway will return 10 messages at a time back to you, starting with
|
74
67
|
# what you currently believe is the lastReceivedId. Specify 0 for the first
|
75
68
|
# time you access the gateway, and the ID of the last message we sent you
|
76
69
|
# on subsequent results
|
77
|
-
|
70
|
+
#
|
78
71
|
def fetch_messages(username, last_received_id=0)
|
79
|
-
|
80
|
-
return build_messages_array(response) if response.options[:response_code] == 200
|
81
|
-
raise api_error_messages(response)
|
82
|
-
end
|
83
|
-
|
84
|
-
private
|
85
|
-
|
86
|
-
def process_api_response(response)
|
87
|
-
return parse_api_response(response) if response.options[:response_code] == 200
|
88
|
-
return parse_api_errors(response) if response.options[:response_code] == 201
|
89
|
-
raise api_error_messages(response)
|
72
|
+
get("/version1/messaging?username=#{username}&lastReceivedId=#{last_received_id}")
|
90
73
|
end
|
91
74
|
|
92
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: africas_talking
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charles Chuck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -208,3 +208,4 @@ test_files:
|
|
208
208
|
- test/mocks/failed_status_report.json
|
209
209
|
- test/mocks/success_status_report.json
|
210
210
|
- test/test_africas_talking.rb
|
211
|
+
has_rdoc:
|