messagemedia-soap 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +8 -13
- data/Rakefile +1 -3
- data/lib/messagemedia-soap.rb +4 -4
- data/lib/messagemedia/soap/client.rb +223 -231
- data/lib/messagemedia/soap/message.rb +69 -76
- data/lib/messagemedia/soap/recipient.rb +21 -23
- data/lib/messagemedia/soap/version.rb +1 -5
- data/messagemedia-soap.gemspec +10 -10
- data/test/test_message.rb +32 -33
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzRiMzFiZjA0NTE0YmFmYmE0MTVlOTk1YTYyZDJiMjFiZmYxMDczNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzlmN2Y0NDI0YjVhMWUwYzk5YjcxMjQwYmE0NzU3OTMzMjE2MWM0Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjI2ZmUyMmEzODVmZDUxNzBjMGFmYmFjMTYwOTFlNDQzMjQ0YmIzOTM4NGYy
|
10
|
+
MzVlMDM4Zjc2MzMxZDAzZGM5NDlhY2M2OWUzYjgyNzZjODhmMGU4ZDZhMzBh
|
11
|
+
YWNlYWU4MzUzMjU4NWM0Mzk3N2YzNTFkN2E5NjBlNDVjNGE3ZGY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGVhYzhiZWFlMDk0NTBmOTU2MDBjNWI2MDhlMGRmYzIyNzk1ZTgzMGRmNDY4
|
14
|
+
YmVkZjAzMWU4ZDNmMDRlYTJlMjhmNzc2MGRmZTdmODgwZTYzYjc1MzA3YWRk
|
15
|
+
ZTM5YmU4MWEyNDI0ZTdjYjMzMzI5ZDA0N2FlNzkyZjYyM2RkZDM=
|
data/README.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
# MessageMedia Ruby SDK
|
2
|
+
This library provides a simple interface for sending and receiving messages using the [MessageMedia SOAP API](http://www.messagemedia.com.au/wp-content/uploads/2013/05/MessageMedia_Messaging_Web_Service.pdf?eacfbb).
|
2
3
|
|
3
|
-
|
4
|
+
If you have any issue using this sample code, or would like to report a defect, you could [create a new Issue](https://github.com/messagemedia/messagemedia-ruby/issues/new) in Github or [Contact us](http://www.messagemedia.com.au/contact-us).
|
4
5
|
|
6
|
+
## Installation
|
7
|
+
The messagemedia-soap Gem can be installed from Rubygems:
|
8
|
+
|
9
|
+
gem install messagemedia-soap
|
10
|
+
|
11
|
+
## Usage
|
5
12
|
The following actions have been implemented:
|
6
13
|
|
7
14
|
* sendMessages
|
@@ -11,16 +18,7 @@ The following actions have been implemented:
|
|
11
18
|
* confirmReplies
|
12
19
|
* confirmReports
|
13
20
|
|
14
|
-
## Installation
|
15
|
-
|
16
|
-
The messagemedia-soap Gem can be installed from Rubygems:
|
17
|
-
|
18
|
-
gem install messagemedia-soap
|
19
|
-
|
20
|
-
## Usage
|
21
|
-
|
22
21
|
### Initialise the client
|
23
|
-
|
24
22
|
Initialise the client using your MessageMedia username and password:
|
25
23
|
|
26
24
|
require 'messagemedia-soap'
|
@@ -28,7 +26,6 @@ Initialise the client using your MessageMedia username and password:
|
|
28
26
|
client = Messagemedia::SOAP::Client.new(YOUR_USERNAME, YOUR_PASSWORD)
|
29
27
|
|
30
28
|
### Send Messages
|
31
|
-
|
32
29
|
To send a single message:
|
33
30
|
|
34
31
|
client.send_message(<TO_NUMBER>, <MESSAGE>, <MESSSAGE_ID>)
|
@@ -52,11 +49,9 @@ To send multiple messages:
|
|
52
49
|
client.send_messages([message1, message2])
|
53
50
|
|
54
51
|
### Other Actions
|
55
|
-
|
56
52
|
Check out 'example.rb' in the 'bin' directory to see examples of how you can use the other actions provided by this SDK.
|
57
53
|
|
58
54
|
## Contributing
|
59
|
-
|
60
55
|
We welcome contributions from our users. Contributing is easy:
|
61
56
|
|
62
57
|
1. Fork this repo
|
data/Rakefile
CHANGED
data/lib/messagemedia-soap.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'messagemedia/soap/version'
|
2
|
+
require 'messagemedia/soap/recipient'
|
3
|
+
require 'messagemedia/soap/message'
|
4
|
+
require 'messagemedia/soap/client'
|
@@ -1,244 +1,236 @@
|
|
1
1
|
require 'savon'
|
2
2
|
|
3
3
|
module Messagemedia
|
4
|
+
module SOAP
|
5
|
+
|
6
|
+
SOAP_ENDPOINT = 'https://soap.m4u.com.au/?wsdl'
|
7
|
+
|
8
|
+
#
|
9
|
+
# This class is a light-weight wrapper around the MessageMedia SOAP API.
|
10
|
+
#
|
11
|
+
class Client
|
12
|
+
|
13
|
+
#
|
14
|
+
# Initialize the SOAP client.
|
15
|
+
#
|
16
|
+
# Your MessageMedia username and password must be provided.
|
17
|
+
#
|
18
|
+
# These credentials will not be authenticated until an actual request
|
19
|
+
# is made using one of the other methods available in this class.
|
20
|
+
#
|
21
|
+
def initialize(username, password, debug = false)
|
22
|
+
# Store the credentials for use with other methods
|
23
|
+
@credentials = {
|
24
|
+
:'api:userId' => username,
|
25
|
+
:'api:password' => password
|
26
|
+
}
|
27
|
+
|
28
|
+
# Create a new Savon-based SOAP client
|
29
|
+
@client = Savon.client(wsdl: SOAP_ENDPOINT, log: debug)
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Send a message to a recipient.
|
35
|
+
#
|
36
|
+
# A destination number (destination_number) is required.
|
37
|
+
#
|
38
|
+
# The source number (source_number), message content (content), and
|
39
|
+
# message identifier (messageId) are optional. Optional arguments
|
40
|
+
# may be omitted by providing nil as an argument.
|
41
|
+
#
|
42
|
+
# If a message identifier is provided, then it will be returned as
|
43
|
+
# part of any replies or delivery reports produced as a result of
|
44
|
+
# this message.
|
45
|
+
#
|
46
|
+
# If a source number is not provided, the message will be sent using
|
47
|
+
# the MessageMedia rotary.
|
48
|
+
#
|
49
|
+
def send_message(destination_number, content, message_id, source_number = nil)
|
50
|
+
|
51
|
+
# Construct a Message object to represent the message
|
52
|
+
message = Message.new
|
53
|
+
message.content = content
|
54
|
+
message.delivery_report = true
|
55
|
+
message.format = FORMAT_SMS
|
56
|
+
message.validity_period = 1
|
57
|
+
message.origin = source_number
|
58
|
+
message.add_recipient(message_id, destination_number)
|
59
|
+
|
60
|
+
messages = {
|
61
|
+
:'@sendMode' => "normal",
|
62
|
+
:'api:message' => [message.to_api_hash]
|
63
|
+
}
|
64
|
+
|
65
|
+
body = {
|
66
|
+
:'api:authentication' => @credentials,
|
67
|
+
:'api:requestBody' => {:'api:messages' => messages}
|
68
|
+
}
|
69
|
+
|
70
|
+
# Make a request to the MessageMedia SOAP service. Note that the
|
71
|
+
# message parameter below refers to the body of the SOAP request,
|
72
|
+
# not the message object that we constructed above.
|
73
|
+
response = @client.call(:send_messages, message: body)
|
74
|
+
|
75
|
+
response.body[:send_messages_response][:result]
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# Send multiple messages using a single request.
|
80
|
+
#
|
81
|
+
# An array of Message objects must be provided. Unlike the send_message
|
82
|
+
# method, this method requires the Message objects to be constructed
|
83
|
+
# manually.
|
84
|
+
#
|
85
|
+
# Constructing an instance of Message is straight-forward:
|
86
|
+
# message = Message.new
|
87
|
+
# message.content = <message content>
|
88
|
+
# message.delivery_report = <true|false>
|
89
|
+
# message.format = <FORMAT_SMS|FORMAT_VOICE>
|
90
|
+
# message.validity_period = 1
|
91
|
+
# message.origin = <source_number>
|
92
|
+
# message.add_recipient(<message ID>, <destination number>)
|
93
|
+
#
|
94
|
+
def send_messages(messages)
|
95
|
+
messages = {
|
96
|
+
:'@sendMode' => 'normal',
|
97
|
+
:'api:message' => messages.map { |m| m.to_api_hash }
|
98
|
+
}
|
99
|
+
|
100
|
+
body = {
|
101
|
+
:'api:authentication' => @credentials,
|
102
|
+
:'api:requestBody' => {:'api:messages' => messages}
|
103
|
+
}
|
104
|
+
|
105
|
+
response = @client.call(:send_messages, message: body)
|
106
|
+
|
107
|
+
response.body[:send_messages_response][:result]
|
108
|
+
end
|
109
|
+
|
110
|
+
#
|
111
|
+
# Retrieve the credit info and other metadata that is available for
|
112
|
+
# a MessageMedia account.
|
113
|
+
#
|
114
|
+
def get_user_info
|
115
|
+
body = {
|
116
|
+
:'api:authentication' => @credentials
|
117
|
+
}
|
118
|
+
|
119
|
+
response = @client.call(:check_user, message: body)
|
120
|
+
|
121
|
+
response.body[:check_user_response][:result]
|
122
|
+
end
|
123
|
+
|
124
|
+
#
|
125
|
+
# Check for, and return, the replies that are available.
|
126
|
+
#
|
127
|
+
# A maximum number of replies (max_replies) may be specified, in order
|
128
|
+
# to limit the size of the response.
|
129
|
+
#
|
130
|
+
# Note that the same replies will be returned by subsequent calls to
|
131
|
+
# this method, unless you also call confirm_replies to confirm that
|
132
|
+
# the replies have been received.
|
133
|
+
#
|
134
|
+
def check_replies(max_replies = nil)
|
135
|
+
body = {
|
136
|
+
:'api:authentication' => @credentials,
|
137
|
+
:'api:requestBody' => {}
|
138
|
+
}
|
139
|
+
|
140
|
+
unless max_replies.nil?
|
141
|
+
body[:'api:requestBody'][:'api:maxReplies'] = max_replies
|
142
|
+
end
|
4
143
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
class Client
|
13
|
-
|
14
|
-
#
|
15
|
-
# Initialize the SOAP client.
|
16
|
-
#
|
17
|
-
# Your MessageMedia username and password must be provided.
|
18
|
-
#
|
19
|
-
# These credentials will not be authenticated until an actual request
|
20
|
-
# is made using one of the other methods available in this class.
|
21
|
-
#
|
22
|
-
def initialize(username, password, debug=false)
|
23
|
-
|
24
|
-
# Store the credentials for use with other methods
|
25
|
-
@credentials = {
|
26
|
-
:'api:userId' => username,
|
27
|
-
:'api:password' => password
|
28
|
-
}
|
29
|
-
|
30
|
-
# Create a new Savon-based SOAP client
|
31
|
-
@client = Savon.client(wsdl: SOAP_ENDPOINT, log: debug)
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
# Send a message to a recipient.
|
37
|
-
#
|
38
|
-
# A destination number (destination_number) is required.
|
39
|
-
#
|
40
|
-
# The source number (source_number), message content (content), and
|
41
|
-
# message identifier (messageId) are optional. Optional arguments
|
42
|
-
# may be omitted by providing nil as an argument.
|
43
|
-
#
|
44
|
-
# If a message identifier is provided, then it will be returned as
|
45
|
-
# part of any replies or delivery reports produced as a result of
|
46
|
-
# this message.
|
47
|
-
#
|
48
|
-
# If a source number is not provided, the message will be sent using
|
49
|
-
# the MessageMedia rotary.
|
50
|
-
#
|
51
|
-
def send_message(destination_number, content, message_id, source_number=nil)
|
52
|
-
|
53
|
-
# Construct a Message object to represent the message
|
54
|
-
message = Message.new
|
55
|
-
message.content = content
|
56
|
-
message.delivery_report = true
|
57
|
-
message.format = FORMAT_SMS
|
58
|
-
message.validity_period = 1
|
59
|
-
message.origin = source_number
|
60
|
-
message.add_recipient(message_id, destination_number)
|
61
|
-
|
62
|
-
messages = {
|
63
|
-
:'@sendMode' => "normal",
|
64
|
-
:'api:message' => [ message.to_api_hash ]
|
65
|
-
}
|
66
|
-
|
67
|
-
body = {
|
68
|
-
:'api:authentication' => @credentials,
|
69
|
-
:'api:requestBody' => { :'api:messages' => messages }
|
70
|
-
}
|
71
|
-
|
72
|
-
# Make a request to the MessageMedia SOAP service. Note that the
|
73
|
-
# message parameter below refers to the body of the SOAP request,
|
74
|
-
# not the message object that we constructed above.
|
75
|
-
response = @client.call(:send_messages, message: body)
|
76
|
-
response.body[:send_messages_response][:result]
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
#
|
81
|
-
# Send multiple messages using a single request.
|
82
|
-
#
|
83
|
-
# An array of Message objects must be provided. Unlike the send_message
|
84
|
-
# method, this method requires the Message objects to be constructed
|
85
|
-
# manually.
|
86
|
-
#
|
87
|
-
# Constructing an instance of Message is straight-forward:
|
88
|
-
# message = Message.new
|
89
|
-
# message.content = <message content>
|
90
|
-
# message.delivery_report = <true|false>
|
91
|
-
# message.format = <FORMAT_SMS|FORMAT_VOICE>
|
92
|
-
# message.validity_period = 1
|
93
|
-
# message.origin = <source_number>
|
94
|
-
# message.add_recipient(<message ID>, <destination number>)
|
95
|
-
#
|
96
|
-
def send_messages(messages)
|
97
|
-
|
98
|
-
messages = {
|
99
|
-
:'@sendMode' => "normal",
|
100
|
-
:'api:message' => messages.map { |m| m.to_api_hash }
|
101
|
-
}
|
102
|
-
|
103
|
-
body = {
|
104
|
-
:'api:authentication' => @credentials,
|
105
|
-
:'api:requestBody' => { :'api:messages' => messages }
|
106
|
-
}
|
107
|
-
|
108
|
-
response = @client.call(:send_messages, message: body)
|
109
|
-
response.body[:send_messages_response][:result]
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
#
|
114
|
-
# Retrieve the credit info and other metadata that is available for
|
115
|
-
# a MessageMedia account.
|
116
|
-
#
|
117
|
-
def get_user_info
|
118
|
-
|
119
|
-
body = { :'api:authentication' => @credentials }
|
120
|
-
|
121
|
-
response = @client.call(:check_user, message: body)
|
122
|
-
response.body[:check_user_response][:result]
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
#
|
127
|
-
# Check for, and return, the replies that are available.
|
128
|
-
#
|
129
|
-
# A maximum number of replies (max_replies) may be specified, in order
|
130
|
-
# to limit the size of the response.
|
131
|
-
#
|
132
|
-
# Note that the same replies will be returned by subsequent calls to
|
133
|
-
# this method, unless you also call confirm_replies to confirm that
|
134
|
-
# the replies have been received.
|
135
|
-
#
|
136
|
-
def check_replies(max_replies = nil)
|
137
|
-
|
138
|
-
body = {
|
139
|
-
:'api:authentication' => @credentials,
|
140
|
-
:'api:requestBody' => {}
|
141
|
-
}
|
144
|
+
response = @client.call(:check_replies, message: body).body[:check_replies_response][:result]
|
145
|
+
if response[:replies]
|
146
|
+
response[:replies] = response[:replies][:reply]
|
147
|
+
else
|
148
|
+
response[:replies] = []
|
149
|
+
end
|
142
150
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
# An array of reply IDs (reply_ids) must be provided. Each of the IDs
|
162
|
-
# in this array should correspond to a reply that was received using
|
163
|
-
# the check_replies method.
|
164
|
-
#
|
165
|
-
def confirm_replies(reply_ids)
|
166
|
-
|
167
|
-
body = {
|
168
|
-
:'api:authentication' => @credentials,
|
169
|
-
:'api:requestBody' => {
|
170
|
-
:'api:replies' => {
|
171
|
-
:'api:reply' => reply_ids.map do |reply_id|
|
172
|
-
{ :'@receiptId' => reply_id }
|
173
|
-
end
|
174
|
-
}
|
175
|
-
}
|
151
|
+
response
|
152
|
+
end
|
153
|
+
|
154
|
+
#
|
155
|
+
# Confirm that replies have been received.
|
156
|
+
#
|
157
|
+
# An array of reply IDs (reply_ids) must be provided. Each of the IDs
|
158
|
+
# in this array should correspond to a reply that was received using
|
159
|
+
# the check_replies method.
|
160
|
+
#
|
161
|
+
def confirm_replies(reply_ids)
|
162
|
+
body = {
|
163
|
+
:'api:authentication' => @credentials,
|
164
|
+
:'api:requestBody' => {
|
165
|
+
:'api:replies' => {
|
166
|
+
:'api:reply' => reply_ids.map do |reply_id|
|
167
|
+
{:'@receiptId' => reply_id}
|
168
|
+
end
|
176
169
|
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
response = @client.call(:confirm_replies, message: body)
|
174
|
+
|
175
|
+
response.body[:confirm_replies_response][:result][:'@confirmed']
|
176
|
+
end
|
177
|
+
|
178
|
+
#
|
179
|
+
# Check for, and return, the Delivery Reports that are available.
|
180
|
+
#
|
181
|
+
# A maximum number of reports (max_reports) may be specified, in order
|
182
|
+
# to limit the size of the response.
|
183
|
+
#
|
184
|
+
# Note that the same delivery reports will be returned by subsequent
|
185
|
+
# calls to this method, unless you also call confirm_replies to confirm
|
186
|
+
# that the replies have been received.
|
187
|
+
#
|
188
|
+
# Note also that Delivery Reports are often called Delivery Receipts,
|
189
|
+
# and the terms can be used interchangeably.
|
190
|
+
#
|
191
|
+
def check_reports(max_reports = nil)
|
192
|
+
body = {
|
193
|
+
:'api:authentication' => @credentials,
|
194
|
+
:'api:requestBody' => {}
|
195
|
+
}
|
196
|
+
|
197
|
+
unless max_reports.nil?
|
198
|
+
body[:'api:requestBody'][:'api:maxReports'] = max_reports
|
199
|
+
end
|
177
200
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
# Check for, and return, the Delivery Reports that are available.
|
185
|
-
#
|
186
|
-
# A maximum number of reports (max_reports) may be specified, in order
|
187
|
-
# to limit the size of the response.
|
188
|
-
#
|
189
|
-
# Note that the same delivery reports will be returned by subsequent
|
190
|
-
# calls to this method, unless you also call confirm_replies to confirm
|
191
|
-
# that the replies have been received.
|
192
|
-
#
|
193
|
-
# Note also that Delivery Reports are often called Delivery Receipts,
|
194
|
-
# and the terms can be used interchangeably.
|
195
|
-
#
|
196
|
-
def check_reports(max_reports = nil)
|
197
|
-
|
198
|
-
body = {
|
199
|
-
:'api:authentication' => @credentials,
|
200
|
-
:'api:requestBody' => {}
|
201
|
-
}
|
201
|
+
response = @client.call(:check_reports, message: body).body[:check_reports_response][:result]
|
202
|
+
if response[:reports]
|
203
|
+
response[:reports] = response[:reports][:report]
|
204
|
+
else
|
205
|
+
response[:reports] = []
|
206
|
+
end
|
202
207
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
# An array of delivery report IDs (report_ids) must be provided. Each
|
222
|
-
# of the IDs in this array should correspond to a Delivery Report that
|
223
|
-
# was received using the check_reports method.
|
224
|
-
#
|
225
|
-
def confirm_reports(report_ids)
|
226
|
-
|
227
|
-
body = {
|
228
|
-
:'api:authentication' => @credentials,
|
229
|
-
:'api:requestBody' => {
|
230
|
-
:'api:reports' => {
|
231
|
-
:'api:report' => reply_ids.map do |report_id|
|
232
|
-
{ :'@receiptId' => report_id }
|
233
|
-
end
|
234
|
-
}
|
235
|
-
}
|
208
|
+
response
|
209
|
+
end
|
210
|
+
|
211
|
+
#
|
212
|
+
# Confirm that Delivery Reports have been received.
|
213
|
+
#
|
214
|
+
# An array of delivery report IDs (report_ids) must be provided. Each
|
215
|
+
# of the IDs in this array should correspond to a Delivery Report that
|
216
|
+
# was received using the check_reports method.
|
217
|
+
#
|
218
|
+
def confirm_reports(report_ids)
|
219
|
+
body = {
|
220
|
+
:'api:authentication' => @credentials,
|
221
|
+
:'api:requestBody' => {
|
222
|
+
:'api:reports' => {
|
223
|
+
:'api:report' => report_ids.map do |report_id|
|
224
|
+
{:'@receiptId' => report_id}
|
225
|
+
end
|
236
226
|
}
|
227
|
+
}
|
228
|
+
}
|
237
229
|
|
238
|
-
|
239
|
-
response.body[:confirm_reports_response][:result][:'@confirmed']
|
230
|
+
response = @client.call(:confirm_reports, message: body)
|
240
231
|
|
241
|
-
|
242
|
-
|
232
|
+
response.body[:confirm_reports_response][:result][:'@confirmed']
|
233
|
+
end
|
243
234
|
end
|
235
|
+
end
|
244
236
|
end
|
@@ -1,88 +1,81 @@
|
|
1
1
|
module Messagemedia
|
2
|
+
module SOAP
|
2
3
|
|
3
|
-
|
4
|
+
FORMAT_SMS = 'SMS'
|
5
|
+
FORMAT_VOICE = 'voice'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
+
#
|
8
|
+
# This class is a light-weight wrapper around the message structure used
|
9
|
+
# by the MessageMedia SOAP Client interface.
|
10
|
+
#
|
11
|
+
class Message
|
12
|
+
attr_accessor :sequence_number, :origin, :recipients, :content,
|
13
|
+
:validity_period, :format, :delivery_report
|
7
14
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
15
|
+
#
|
16
|
+
# Initialize an empty Message object
|
17
|
+
#
|
18
|
+
# By default, delivery reports will be enabled, the validity
|
19
|
+
# period will be set to 10 minutes, and the message will be sent as
|
20
|
+
# an SMS.
|
21
|
+
#
|
22
|
+
def initialize
|
23
|
+
@recipients = []
|
24
|
+
@delivery_report = true
|
25
|
+
@validity_period = 1
|
26
|
+
@sequence_number = 0
|
27
|
+
@format = FORMAT_SMS
|
28
|
+
end
|
13
29
|
|
14
|
-
|
15
|
-
|
30
|
+
#
|
31
|
+
# Add a recipient.
|
32
|
+
#
|
33
|
+
# An optional message ID (message_id) may be provided. This allows
|
34
|
+
# for the correlation of replies and delivery reports with messages
|
35
|
+
# that have been sent.
|
36
|
+
#
|
37
|
+
# A recipient number (recipient) must be provided.
|
38
|
+
#
|
39
|
+
def add_recipient(message_id, recipient)
|
40
|
+
@recipients.push(Recipient.new(message_id, recipient))
|
41
|
+
end
|
16
42
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
@recipients
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@format = FORMAT_SMS
|
30
|
-
end
|
31
|
-
|
32
|
-
#
|
33
|
-
# Add a recipient.
|
34
|
-
#
|
35
|
-
# An optional message ID (message_id) may be provided. This allows
|
36
|
-
# for the correlation of replies and delivery reports with messages
|
37
|
-
# that have been sent.
|
38
|
-
#
|
39
|
-
# A recipient number (recipient) must be provided.
|
40
|
-
#
|
41
|
-
def add_recipient(message_id, recipient)
|
42
|
-
@recipients.push(Recipient.new(message_id, recipient))
|
43
|
-
end
|
44
|
-
|
45
|
-
#
|
46
|
-
# Return a hash that can be passed to the Savon SOAP library to
|
47
|
-
# represent a message.
|
48
|
-
#
|
49
|
-
def to_api_hash
|
50
|
-
|
51
|
-
hash = {
|
52
|
-
:'api:content' => @content,
|
53
|
-
:'api:recipients' => {
|
54
|
-
:'api:recipient' => @recipients.map { |r| r.destination_number },
|
55
|
-
:attributes! => {
|
56
|
-
:'api:recipient' => {
|
57
|
-
:uid => @recipients.map { |r| r.message_id }
|
58
|
-
}
|
59
|
-
}
|
43
|
+
#
|
44
|
+
# Return a hash that can be passed to the Savon SOAP library to
|
45
|
+
# represent a message.
|
46
|
+
#
|
47
|
+
def to_api_hash
|
48
|
+
hash = {
|
49
|
+
:'api:content' => @content,
|
50
|
+
:'api:recipients' => {
|
51
|
+
:'api:recipient' => @recipients.map { |r| r.destination_number },
|
52
|
+
:attributes! => {
|
53
|
+
:'api:recipient' => {
|
54
|
+
:uid => @recipients.map { |r| r.message_id }
|
60
55
|
}
|
61
56
|
}
|
57
|
+
}
|
58
|
+
}
|
62
59
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
if not @validity_period.nil? then
|
76
|
-
hash[:'api:validityPeriod'] = @validity_period
|
77
|
-
end
|
78
|
-
|
79
|
-
if not @origin.nil? then
|
80
|
-
hash[:'api:origin'] = @origin
|
81
|
-
end
|
82
|
-
|
83
|
-
return hash
|
84
|
-
|
85
|
-
end
|
60
|
+
unless @format.nil?
|
61
|
+
hash[:'@format'] = @format
|
62
|
+
end
|
63
|
+
unless @sequence_number.nil?
|
64
|
+
hash[:'@sequenceNumber'] = @sequence_number
|
65
|
+
end
|
66
|
+
unless @delivery_report.nil?
|
67
|
+
hash[:'api:deliveryReport'] = @delivery_report
|
68
|
+
end
|
69
|
+
unless @validity_period.nil?
|
70
|
+
hash[:'api:validityPeriod'] = @validity_period
|
86
71
|
end
|
72
|
+
unless @origin.nil?
|
73
|
+
hash[:'api:origin'] = @origin
|
74
|
+
end
|
75
|
+
|
76
|
+
hash
|
77
|
+
end
|
87
78
|
end
|
79
|
+
|
80
|
+
end
|
88
81
|
end
|
@@ -1,29 +1,27 @@
|
|
1
1
|
module Messagemedia
|
2
|
+
module SOAP
|
2
3
|
|
3
|
-
|
4
|
+
#
|
5
|
+
# This class is a light-weight wrapper around the Recipient structure used
|
6
|
+
# by the MessageMedia SoapClient interface.
|
7
|
+
#
|
8
|
+
class Recipient
|
9
|
+
attr_accessor :message_id, :destination_number
|
4
10
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
11
|
+
#
|
12
|
+
# Initialize an empty Recipient object.
|
13
|
+
#
|
14
|
+
# This object represents a single recipient of a message, and allows
|
15
|
+
# an optional message ID (message_id) to be assigned to the message
|
16
|
+
# that will be sent to that recipient.
|
17
|
+
#
|
18
|
+
# A destination number (destination_number) must be provided
|
19
|
+
#
|
20
|
+
def initialize(message_id, destination_number)
|
21
|
+
@message_id = message_id
|
22
|
+
@destination_number = destination_number
|
23
|
+
end
|
10
24
|
|
11
|
-
attr_accessor :message_id, :destination_number
|
12
|
-
|
13
|
-
#
|
14
|
-
# Initialize an empty Recipient object.
|
15
|
-
#
|
16
|
-
# This object represents a single recipient of a message, and allows
|
17
|
-
# an optional message ID (message_id) to be assigned to the message
|
18
|
-
# that will be sent to that recipient.
|
19
|
-
#
|
20
|
-
# A destination number (destination_number) must be provided
|
21
|
-
#
|
22
|
-
def initialize(message_id, destination_number)
|
23
|
-
@message_id = message_id
|
24
|
-
@destination_number = destination_number
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
25
|
end
|
26
|
+
end
|
29
27
|
end
|
data/messagemedia-soap.gemspec
CHANGED
@@ -3,25 +3,25 @@
|
|
3
3
|
lib = File.expand_path('../lib', __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
|
6
|
-
require 'messagemedia/soap/version'
|
6
|
+
require File.dirname(__FILE__) + '/lib/messagemedia/soap/version'
|
7
7
|
|
8
8
|
Gem::Specification.new do |spec|
|
9
9
|
|
10
10
|
spec.name = "messagemedia-soap"
|
11
11
|
spec.version = Messagemedia::SOAP::VERSION
|
12
|
-
spec.authors = [
|
13
|
-
spec.email = [
|
14
|
-
spec.summary =
|
15
|
-
spec.description =
|
16
|
-
spec.homepage =
|
17
|
-
spec.license =
|
12
|
+
spec.authors = ['Chris Hawkins', 'Tristan Penman']
|
13
|
+
spec.email = ['chris.hawkins@outlook.com', 'tristan.penman@messagemedia.com.au']
|
14
|
+
spec.summary = 'Simple Ruby interface for the MessageMedia SOAP API'
|
15
|
+
spec.description = 'Support for Ruby applications to integrate with the MessageMedia SOAP API'
|
16
|
+
spec.homepage = 'http://www.messagemedia.com/'
|
17
|
+
spec.license = 'Apache'
|
18
18
|
spec.files = `git ls-files -z`.split("\x0")
|
19
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
-
spec.require_paths = [
|
21
|
+
spec.require_paths = ['lib']
|
22
22
|
|
23
|
-
spec.add_development_dependency
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
24
24
|
spec.add_development_dependency 'rake', '~> 0'
|
25
|
-
spec.add_dependency
|
25
|
+
spec.add_dependency 'savon', '~> 2.4'
|
26
26
|
|
27
27
|
end
|
data/test/test_message.rb
CHANGED
@@ -5,43 +5,42 @@ require_relative '../lib/messagemedia/soap/message'
|
|
5
5
|
|
6
6
|
class TestMessage < Test::Unit::TestCase
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
:'api:
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
:
|
33
|
-
:
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
]
|
38
|
-
}
|
8
|
+
def test_to_api_hash
|
9
|
+
message = Messagemedia::SOAP::Message.new
|
10
|
+
|
11
|
+
# First test recipient, with a custom message ID
|
12
|
+
message_id_1 = 100
|
13
|
+
recipient_1 = 123456
|
14
|
+
message.add_recipient(message_id_1, recipient_1)
|
15
|
+
|
16
|
+
# Second test recipient, no message ID
|
17
|
+
recipient_2 = 456789
|
18
|
+
message.add_recipient(nil, recipient_2)
|
19
|
+
|
20
|
+
expected_hash = {
|
21
|
+
:'@format' => message.format,
|
22
|
+
:'@sequenceNumber' => message.sequence_number,
|
23
|
+
:'api:deliveryReport' => message.delivery_report,
|
24
|
+
:'api:validityPeriod' => message.validity_period,
|
25
|
+
:'api:content' => message.content,
|
26
|
+
:'api:recipients' => {
|
27
|
+
:'api:recipient' => [
|
28
|
+
recipient_1,
|
29
|
+
recipient_2
|
30
|
+
],
|
31
|
+
:attributes! => {
|
32
|
+
:'api:recipient' => {
|
33
|
+
:uid => [
|
34
|
+
message_id_1,
|
35
|
+
nil
|
36
|
+
]
|
39
37
|
}
|
40
38
|
}
|
41
39
|
}
|
40
|
+
}
|
42
41
|
|
43
|
-
|
42
|
+
assert_equal(expected_hash, message.to_api_hash)
|
44
43
|
|
45
|
-
|
44
|
+
end
|
46
45
|
|
47
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: messagemedia-soap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Hawkins
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.4.6
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: Simple Ruby interface for the MessageMedia SOAP API
|