Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added some docs

  • Loading branch information...
commit 1ce5895d112b2cf50b63a2fa64ccf35734d1dadd 1 parent 2bcde07
@alextk authored
Showing with 13 additions and 7 deletions.
  1. +4 −4 lib/smsim/gateway.rb
  2. +9 −3 lib/smsim/sender.rb
View
8 lib/smsim/gateway.rb
@@ -22,10 +22,10 @@ def initialize(username, password, options = {})
end
# send +text+ string to the phones specified in +phones+ array
- # +options+ hash can have the following keys:
- # * delivery_notification_url - url to which delivery notification will be sent
- # * reply_to_number - to which number sms receiver will reply
- # Returns unique message id string. Uou must save this id if you want to receive delivery notifications via push/pull
+ # Returns response OpenStruct that contains:
+ # * +message_id+ - message id string. You must save this id if you want to receive delivery notifications via push/pull
+ # * +status+ - gateway status of sms send
+ # * +number_of_recipients+ - number of recipients the message was sent to
def send_sms(text, phones)
@sms_sender.send_sms(text, phones)
end
View
12 lib/smsim/sender.rb
@@ -6,6 +6,12 @@ module Smsim
class Sender
include ::HTTParty
+ # Create new sms sender with given +options+ with the following keys:
+ # * +username+ - gateway username
+ # * +password+ - gateway password
+ # * +delivery_notification_url+ - url to which delivery notification will be sent
+ # * +reply_to_number+ - to which number sms receiver will reply
+ # These keys will be used when sending sms messages
def initialize(options)
raise ArgumentError.new("HTTP post url is missing") if options[:http_post_url].blank?
raise ArgumentError.new("Username and password must be present") if options[:username].blank? || options[:password].blank?
@@ -22,7 +28,8 @@ def send_sms(message_text, phones)
xml = build_send_sms_xml(message_text, phones, message_id)
response = self.class.post(@options[:http_post_url], :body => {:InforuXML => xml})
verify_http_response_code(response) # error will be raised if response code is bad
- response = parse_response_xml(response, message_id)
+ response = parse_response_xml(response)
+ response.message_id = message_id
if response.status != 1
raise Smsim::Errors::GatewayError.new(Smsim::Errors::GatewayError.map_send_sms_xml_response_status(response.status), "Sms send failed (status #{response.status}): #{response.description}")
end
@@ -75,7 +82,7 @@ def verify_http_response_code(response)
end
end
- def parse_response_xml(httparty_response, message_id)
+ def parse_response_xml(httparty_response)
xml = httparty_response.parsed_response
begin
doc = ::Nokogiri::XML(xml)
@@ -83,7 +90,6 @@ def parse_response_xml(httparty_response, message_id)
:status => Integer(doc.at_css('Result Status').text),
:number_of_recipients => Integer(doc.at_css('Result NumberOfRecipients').text),
:description => doc.at_css('Result Description').text,
- :message_id => message_id
})
rescue Exception => e
raise Smsim::Errors::GatewayError.new(250, e.message)
Please sign in to comment.
Something went wrong with that request. Please try again.