Class: SmsClub::Client
- Inherits:
-
Object
- Object
- SmsClub::Client
- Defined in:
- lib/sms-club/client.rb
Overview
API documentation smsclub.mobi/en/pages/show/api#xml
Direct Known Subclasses
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
-
#password ⇒ Object
Returns the value of attribute password.
-
#transliterate ⇒ Object
Returns the value of attribute transliterate.
-
#user_name ⇒ Object
Returns the value of attribute user_name.
Instance Method Summary collapse
-
#initialize(user_name, password, from: nil, transliterate: false) ⇒ Client
constructor
A new instance of Client.
- #send_many(message, options = {}) ⇒ Object
- #send_one(message, options = {}) ⇒ Object
- #status_for(smscid) ⇒ Object
- #statuses_for(smscid) ⇒ Object
Constructor Details
#initialize(user_name, password, from: nil, transliterate: false) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 |
# File 'lib/sms-club/client.rb', line 10 def initialize(user_name, password, from: nil, transliterate: false) @user_name = user_name @password = password @from = from @transliterate = transliterate end |
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from.
8 9 10 |
# File 'lib/sms-club/client.rb', line 8 def from @from end |
#password ⇒ Object
Returns the value of attribute password.
8 9 10 |
# File 'lib/sms-club/client.rb', line 8 def password @password end |
#transliterate ⇒ Object
Returns the value of attribute transliterate.
8 9 10 |
# File 'lib/sms-club/client.rb', line 8 def transliterate @transliterate end |
#user_name ⇒ Object
Returns the value of attribute user_name.
8 9 10 |
# File 'lib/sms-club/client.rb', line 8 def user_name @user_name end |
Instance Method Details
#send_many(message, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sms-club/client.rb', line 21 def send_many(, = {}) fail ArgumentError, 'Recepient is not defined' unless [:to] to = [:to] to = to.map(&:to_s).join(';') if to.is_a? Array = if transliterate || [:transliterate] msg_from = [:from] || from payload = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| xml.request_sendsms do xml.username { xml.cdata @user_name } xml.password { xml.cdata @password } xml.from { xml.cdata msg_from } xml.to { xml.cdata to } xml.text_ { xml.cdata } end end response = connection.post '/hfw_smpp_addon/xmlsendsmspost.php', xmlrequest: payload.to_xml doc = Nokogiri::XML(response.body) raise SmsClubError, response_error(doc) if response_failed?(doc) doc.xpath('//mess').map(&:content) end |
#send_one(message, options = {}) ⇒ Object
17 18 19 |
# File 'lib/sms-club/client.rb', line 17 def send_one(, = {}) send_many(, ).first end |
#status_for(smscid) ⇒ Object
48 49 50 |
# File 'lib/sms-club/client.rb', line 48 def status_for(smscid) statuses_for(smscid).first[smscid] end |
#statuses_for(smscid) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sms-club/client.rb', line 52 def statuses_for(smscid) smscid = smscid.map(&:to_s).join(';') if smscid.is_a? Array payload = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| xml.request_getstate do xml.username { xml.cdata @user_name } xml.password { xml.cdata @password } xml.smscid { xml.cdata smscid } end end response = connection.post '/hfw_smpp_addon/xmlgetsmsstatepost.php', xmlrequest: payload.to_xml doc = Nokogiri::XML(response.body) raise SmsClubError, response_error(doc) if response_failed?(doc) doc.xpath('//entry').map do |entry| { entry.xpath('smscid').text => entry.xpath('state').text.downcase.to_sym } end end |