messagemedia-ruby 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjM5ZTNkNjA1YzUzMGY2YmQ1ZmUwYWU2NzBlNDE3NDgwYjQxNGZhMg==
5
+ data.tar.gz: !binary |-
6
+ YjRjNjM1YjgxNjZhN2QwYmIxMjE4NmMyMDRlYzhiZmY1ZGM4MTJjMA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZjI4ZDYyNTQ1YTBhMmVhN2E5MWY1ZTk1OGUzMGIyYWYzMDkwNThjN2UwZDRh
10
+ ZDdhNWQ4MjQwZTRkZmI5N2YwZWQ0ZDJiOWI1ZTc5OTU0NmI0OWI1ZDI0NmM0
11
+ Nzg2ODQyY2ViMTI1ZTIxODQ3OTk4ZjQ4YWQyYjdlNWQ2ZDgyNTE=
12
+ data.tar.gz: !binary |-
13
+ YTc5NWQ0M2IzNGI0ZTAzODM1M2ZjYzE0MDU0ZWYzZmE1Y2EyMjg2MjEwN2Vh
14
+ MjM4YmE4NmU4OTI5OTE3NmYzMmI3NTM4N2FhZDBmY2MzYjI0ZWEzMWRkZjQ2
15
+ YTk2NTdmMzI1ODgzYmY2YzgzZWMzYjAyMGU5YjkwNDViMDljY2Q=
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .rakeTasks
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -0,0 +1,21 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ bundler_args: --without development
5
+ rvm:
6
+ - ruby-head
7
+ - ruby
8
+ - 2.2.0
9
+ - 2.1.0
10
+ - 2.0.0
11
+ - 1.9.3
12
+ - jruby-head
13
+ - jruby
14
+ - jruby-19mode
15
+ matrix:
16
+ fast_finish: true
17
+ allow_failures:
18
+ - rvm: ruby-head
19
+ - rvm: ruby
20
+ - rvm: jruby-head
21
+ - rvm: jruby
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in messagemedia.gemspec
4
+ gemspec
5
+
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,64 @@
1
+ [![Gem Version](https://badge.fury.io/rb/messagemedia-soap.svg)](http://badge.fury.io/rb/messagemedia-soap)
2
+ [![Build Status](https://travis-ci.org/messagemedia/messagemedia-ruby.svg)](https://travis-ci.org/messagemedia/messagemedia-ruby)
3
+
4
+ # MessageMedia Ruby SDK
5
+ 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).
6
+
7
+ 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).
8
+
9
+ ## Installation
10
+ The messagemedia-ruby Gem can be installed from Rubygems:
11
+
12
+ gem install messagemedia-ruby
13
+
14
+ ## Usage
15
+ The following actions have been implemented:
16
+
17
+ * sendMessages
18
+ * checkUser
19
+ * checkReplies
20
+ * checkReports
21
+ * confirmReplies
22
+ * confirmReports
23
+
24
+ ### Initialise the client
25
+ Initialise the client using your MessageMedia username and password:
26
+
27
+ require 'messagemedia-ruby'
28
+
29
+ client = Messagemedia::SOAP::Client.new(YOUR_USERNAME, YOUR_PASSWORD)
30
+
31
+ ### Send Messages
32
+ To send a single message:
33
+
34
+ client.send_message(<TO_NUMBER>, <MESSAGE>, <MESSSAGE_ID>)
35
+
36
+ To send multiple messages:
37
+
38
+ # Construct the first Message object
39
+ message1 = Messagemedia::SOAP::Message.new
40
+ message1.content = "Content of Message"
41
+ message1.delivery_report = true
42
+ message1.origin = "My Company"
43
+ message1.add_recipient(FIRST_MESSAGE_ID, TO_NUMBER)
44
+
45
+ # Construct the second Message object
46
+ message2 = Messagemedia::SOAP::Message.new
47
+ message2.content = "Content of Message"
48
+ message2.delivery_report = false
49
+ message2.origin = "My Company"
50
+ message2.add_recipient(SECOND_MESSAGE_ID, TO_NUMBER)
51
+
52
+ client.send_messages([message1, message2])
53
+
54
+ ### Other Actions
55
+ Check out 'example.rb' in the 'bin' directory to see examples of how you can use the other actions provided by this SDK.
56
+
57
+ ## Contributing
58
+ We welcome contributions from our users. Contributing is easy:
59
+
60
+ 1. Fork this repo
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create a Pull Request
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc 'Run tests'
8
+ task :default => :test
@@ -0,0 +1,174 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "messagemedia-ruby"
4
+
5
+ USER_ID = "<your username>"; # Your username goes here
6
+ PASSWORD = "<your password>"; # Your password goes here
7
+ DESTINATION_NUMBER = "<destination number>"; # Destination number
8
+
9
+ ##
10
+ # Method used for rendering the results to the console screen.
11
+ #
12
+ def display_result(result)
13
+
14
+ puts "Messages sent #{result[:'@sent']}"
15
+ puts "Messages failed #{result[:'@failed']}"
16
+ puts "Messages scheduled #{result[:'@scheduled']}"
17
+
18
+ if not result[:errors].nil? then
19
+ puts result.errors
20
+ end
21
+
22
+ end
23
+
24
+ ##
25
+ # Example demonstrates how to quickly send a single message with the default
26
+ # settings.
27
+ #
28
+ def send_message
29
+
30
+ puts "EXECUTING SEND MESSAGE..."
31
+ messageId = 1234567890;
32
+
33
+ client = Messagemedia::SOAP::Client.new(USER_ID, PASSWORD)
34
+ result = client.send_message(DESTINATION_NUMBER, "Test Message", messageId)
35
+ display_result result
36
+
37
+ end
38
+
39
+ ##
40
+ # Example shows how to send a batch of messages. It's possible to send
41
+ # multiple individual messages in a single batch.
42
+ #
43
+ def send_multiple_messages
44
+
45
+ puts "EXECUTING SEND MULTIPLE MESSAGES..."
46
+
47
+ client = Messagemedia::SOAP::Client.new(USER_ID, PASSWORD)
48
+
49
+ # Construct the message
50
+ message1 = Messagemedia::SOAP::Message.new
51
+ message1.content = "Content of Message 1 to Recipient 1"
52
+ message1.delivery_report = true
53
+ message1.format = Messagemedia::SOAP::FORMAT_SMS
54
+ message1.validity_period = 1
55
+ # (Optional) This attribute specifies a sequence number that is assigned to the message and is used to identify the message if an error occurs. Each message error in the response will specify the sequence number of the message that caused the error. Sequence numbers should be unique within the request. 1 to 2147483647.
56
+ message1.sequence_number = 1
57
+ # (Optional) This element specifies the message source address. The specified address will be used wherever possible, however due to limitations with various carriers, legislation etc, the final message is not guaranteed to come from the specified address.
58
+ message1.origin = "Origin_1"
59
+ message1.add_recipient(1234567890, DESTINATION_NUMBER)
60
+
61
+ # Construct the message
62
+ message2 = Messagemedia::SOAP::Message.new
63
+ message2.content = "Content of Message 2 to Recipient 2"
64
+ message2.delivery_report = true
65
+ message2.format = Messagemedia::SOAP::FORMAT_SMS
66
+ message2.validity_period = 1
67
+ # (Optional) This attribute specifies a sequence number that is assigned to the message and is used to identify the message if an error occurs. Each message error in the response will specify the sequence number of the message that caused the error. Sequence numbers should be unique within the request. 1 to 2147483647.
68
+ message2.sequence_number = 1
69
+ # (Optional) This element specifies the message source address. The specified address will be used wherever possible, however due to limitations with various carriers, legislation etc, the final message is not guaranteed to come from the specified address.
70
+ message2.origin = "Origin_2"
71
+ message2.add_recipient(234567890, DESTINATION_NUMBER)
72
+
73
+ result = client.send_messages([ message1, message2 ])
74
+ display_result result
75
+
76
+ end
77
+
78
+ ##
79
+ # Example demonstrates how to get account and credit remaining information.
80
+ #
81
+ def check_user_info
82
+
83
+ puts "EXECUTING CHECK USER INFO..."
84
+
85
+ client = Messagemedia::SOAP::Client.new(USER_ID, PASSWORD)
86
+ user_info = client.get_user_info
87
+
88
+ account_details = user_info[:account_details]
89
+ puts "Credit limit: #{account_details[:'@credit_limit']}"
90
+ puts "Remaining credits: #{account_details[:'@credit_remaining']}"
91
+ puts "Account type: #{account_details[:'@type']}"
92
+
93
+ end
94
+
95
+ ##
96
+ # Example demonstrates how to check for replies and to confirm them.
97
+ #
98
+ def check_and_confirm_replies
99
+
100
+ puts "EXECUTING CHECK REPLIES..."
101
+
102
+ client = Messagemedia::SOAP::Client.new(USER_ID, PASSWORD)
103
+ replies = client.check_replies
104
+
105
+ puts "Remaining replies: #{replies[:'@remaining']}"
106
+
107
+ receipt_ids = []
108
+
109
+ if not replies[:replies].nil? then
110
+ replies[:replies].each do |reply|
111
+ puts "Reply receipt id: #{reply[:'@receipt_id']}"
112
+ puts "Reply uid: #{reply[:'@uid']}"
113
+ puts "Reply received date time: #{reply[:received]}"
114
+ puts "Reply origin: #{reply[:origin]}"
115
+ puts "Reply content: #{reply[:content]}"
116
+ puts "Reply format: #{reply[:'@format']}"
117
+ receipt_ids.push reply[:'@receipt_id']
118
+ end
119
+
120
+ if receipt_ids.length > 0
121
+ puts "EXECUTING CONFIRM REPLIES..."
122
+ confirmation = client.confirm_replies(receipt_ids)
123
+ puts "Replies confirmed: #{confirmation}"
124
+ end
125
+ end
126
+ end
127
+
128
+ ##
129
+ # Example demonstrates how to check for delivery reports and to confirm them.
130
+ #
131
+ def check_and_confirm_reports
132
+
133
+ puts "EXECUTING CHECK REPORTS..."
134
+
135
+ client = Messagemedia::SOAP::Client.new(USER_ID, PASSWORD)
136
+ replies = client.check_reports
137
+
138
+ puts "Remaining replies: #{replies[:'@remaining']}"
139
+
140
+ receipt_ids = []
141
+
142
+ if not replies[:replies].nil? then
143
+ replies[:replies].each do |reply|
144
+ puts "Reply receipt id: #{reply[:receipt_id]}"
145
+ puts "Reply uid: #{reply[:uid]}"
146
+ puts "Reply received date time: #{reply[:received]}"
147
+ puts "Reply origin: #{reply[:origin]}"
148
+ puts "Reply content: #{reply[:content]}"
149
+ puts "Reply format: #{reply[:format]}"
150
+ receipt_ids.push reply[:receipt_id]
151
+ end
152
+
153
+ if receipt_ids > 0
154
+ puts "EXECUTING CONFIRM REPORTS..."
155
+ confirmation = client.confirm_replies(receipt_ids)
156
+ puts "Replies confirmed: #{confirmation}"
157
+ end
158
+
159
+ end
160
+
161
+ end
162
+
163
+ check_user_info
164
+ send_message
165
+ check_and_confirm_replies
166
+ check_and_confirm_reports
167
+
168
+ # For example purposes, sending more than one message is unnecessary. However,
169
+ # if you would like to test sending more than one message as part of a single
170
+ # SOAP request, uncomment the following line of code:
171
+
172
+ #send_multiple_messages
173
+
174
+
@@ -0,0 +1,4 @@
1
+ require 'messagemedia/version'
2
+ require 'messagemedia/soap/recipient'
3
+ require 'messagemedia/soap/message'
4
+ require 'messagemedia/soap/client'
@@ -0,0 +1,236 @@
1
+ require 'savon'
2
+
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
143
+
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
150
+
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
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
200
+
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
207
+
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
226
+ }
227
+ }
228
+ }
229
+
230
+ response = @client.call(:confirm_reports, message: body)
231
+
232
+ response.body[:confirm_reports_response][:result][:'@confirmed']
233
+ end
234
+ end
235
+ end
236
+ end
@@ -0,0 +1,81 @@
1
+ module Messagemedia
2
+ module SOAP
3
+
4
+ FORMAT_SMS = 'SMS'
5
+ FORMAT_VOICE = 'voice'
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
14
+
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
29
+
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
42
+
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 }
55
+ }
56
+ }
57
+ }
58
+ }
59
+
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
71
+ end
72
+ unless @origin.nil?
73
+ hash[:'api:origin'] = @origin
74
+ end
75
+
76
+ hash
77
+ end
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,27 @@
1
+ module Messagemedia
2
+ module SOAP
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
10
+
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
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Messagemedia
2
+ VERSION = '0.7.0'
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require File.dirname(__FILE__) + '/lib/messagemedia/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'messagemedia-ruby'
10
+ spec.version = Messagemedia::VERSION
11
+ spec.authors = ['Tristan Penman']
12
+ spec.email = ['tristan.penman@messagemedia.com.au']
13
+ spec.summary = 'Simple Ruby interface for the MessageMedia SOAP API'
14
+ spec.description = 'Support for Ruby applications to integrate with the MessageMedia SOAP API'
15
+ spec.homepage = 'http://www.messagemedia.com/'
16
+ spec.license = 'Apache'
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.5'
23
+ spec.add_dependency 'rake'
24
+ spec.add_dependency 'savon', '~> 2.4'
25
+ spec.add_dependency 'test-unit'
26
+
27
+ end
@@ -0,0 +1,46 @@
1
+ require 'test/unit'
2
+
3
+ require_relative '../lib/messagemedia/soap/recipient'
4
+ require_relative '../lib/messagemedia/soap/message'
5
+
6
+ class TestMessage < Test::Unit::TestCase
7
+
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
+ ]
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+ assert_equal(expected_hash, message.to_api_hash)
43
+
44
+ end
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: messagemedia-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ platform: ruby
6
+ authors:
7
+ - Tristan Penman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: savon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Support for Ruby applications to integrate with the MessageMedia SOAP
70
+ API
71
+ email:
72
+ - tristan.penman@messagemedia.com.au
73
+ executables:
74
+ - example.rb
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - .travis.yml
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/example.rb
85
+ - lib/messagemedia-ruby.rb
86
+ - lib/messagemedia/soap/client.rb
87
+ - lib/messagemedia/soap/message.rb
88
+ - lib/messagemedia/soap/recipient.rb
89
+ - lib/messagemedia/version.rb
90
+ - messagemedia-ruby.gemspec
91
+ - test/test_message.rb
92
+ homepage: http://www.messagemedia.com/
93
+ licenses:
94
+ - Apache
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.6
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Simple Ruby interface for the MessageMedia SOAP API
116
+ test_files:
117
+ - test/test_message.rb