Class: Net::SMS::BulkSMS::Service
- Inherits:
-
Object
- Object
- Net::SMS::BulkSMS::Service
- Defined in:
- lib/net/sms/bulksms.rb
Constant Summary collapse
- MESSAGE_SERVICE_PORT =
The port the message service rus on
80- MESSAGE_SERVICE_PATH =
Path to the message service gateway
'/eapi/submission/send_sms/2/2.0'
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
returns an Account object for the credentials supplied to the service.
Class Method Summary collapse
-
.bulksms_gateway(country) ⇒ Object
Returns the gateway URL for the chosen country.
Instance Method Summary collapse
-
#initialize(username, password, country = INTER) ⇒ Service
constructor
A new instance of Service.
-
#send(message, recipient) ⇒ Object
Creates a new Message object from the message text and recipient given and sends to the gateway using send_message().
-
#send_message(msg) ⇒ Object
Sends the given Message object to the gateway for delivery.
-
#send_multiple(messages) ⇒ Object
Openning single connection & sending an array of message objects.
Constructor Details
Instance Attribute Details
#account ⇒ Object (readonly)
returns an Account object for the credentials supplied to the service
39 40 41 |
# File 'lib/net/sms/bulksms.rb', line 39 def account @account end |
Class Method Details
.bulksms_gateway(country) ⇒ Object
Returns the gateway URL for the chosen country
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/net/sms/bulksms.rb', line 74 def self.bulksms_gateway(country) case country when 'uk' 'www.bulksms.co.uk' when 'usa' 'usa.bulksms.com' when 'international' 'bulksms.vsms.net' when 'safrica' 'bulksms.2way.co.za' when 'spain' 'bulksms.com.es' end end |
Instance Method Details
#send(message, recipient) ⇒ Object
Creates a new Message object from the message text and recipient given and sends to the gateway using send_message()
68 69 70 71 |
# File 'lib/net/sms/bulksms.rb', line 68 def send(, recipient) msg = Message.new(, recipient) self.(msg) end |
#send_message(msg) ⇒ Object
Sends the given Message object to the gateway for delivery
47 48 49 50 51 52 53 |
# File 'lib/net/sms/bulksms.rb', line 47 def (msg) payload = [@account.to_http_query, msg.to_http_query].join('&') Net::HTTP.start(Service.bulksms_gateway(@country), MESSAGE_SERVICE_PORT) do |http| resp = http.post(MESSAGE_SERVICE_PATH, payload) Response.parse(resp.body) end end |
#send_multiple(messages) ⇒ Object
Openning single connection & sending an array of message objects
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/net/sms/bulksms.rb', line 55 def send_multiple() responses=[] Net::HTTP.start(Service.bulksms_gateway(@country), MESSAGE_SERVICE_PORT) do |http| .each do |msg| payload = [@account.to_http_query, msg.to_http_query].join('&') resp = http.post(MESSAGE_SERVICE_PATH, payload) responses << Response.parse(resp.body) end end responses end |