Class: Smslane::Client
- Inherits:
-
Object
- Object
- Smslane::Client
- Includes:
- HTTParty
- Defined in:
- lib/smslane/client.rb
Instance Method Summary collapse
- #check_balance ⇒ Object
-
#initialize(username, password) ⇒ Client
constructor
A new instance of Client.
- #send(options) ⇒ Object
- #send_sms(recipients, message, flash) ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Client
Returns a new instance of Client.
29 30 31 |
# File 'lib/smslane/client.rb', line 29 def initialize(username,password) @auth = {user: username, password: password} end |
Instance Method Details
#check_balance ⇒ Object
33 34 35 36 37 38 |
# File 'lib/smslane/client.rb', line 33 def check_balance = {:query => @auth} response = self.class.get '/vendorsms/CheckBalance.aspx?', responses = response.split('#') {:result=>responses[0],:response=>responses[1]} end |
#send(options) ⇒ Object
40 41 42 |
# File 'lib/smslane/client.rb', line 40 def send self.class.get '/vendorsms/pushsms.aspx?', end |
#send_sms(recipients, message, flash) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/smslane/client.rb', line 44 def send_sms recipients, , flash flash = flash ? 1 : 0 responses = [] recipients = recipients.each_slice(90).to_a recipients.each do |recipient_list| recipient_list.each_with_index do |number,i| recipient_list[i] = '91'+number[-10..-1] if /^(\+91|91)[789][0-9]{9}$/.match(recipient_list[i]).nil? recipient_list.delete_at(i) end end = {:query => @auth.merge({:msisdn=>recipient_list.join(','), :sid=>'WebSMS', :fl => flash, :msg => })} responses << send().parsed_response end responses.delete('Failed#Invalid Mobile Numbers') responses = responses.join().split('<br />') result = [] responses.each do |response| res = response[-45..-1].split('-') result << {:number => res[0], :message_id=>res[1]} end result end |