Class: NajdiSms
- Inherits:
-
Object
- Object
- NajdiSms
- Defined in:
- lib/najdi-sms.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(username, password) ⇒ NajdiSms
constructor
A new instance of NajdiSms.
- #login(username, password) ⇒ Object
- #send_sms(number, message) ⇒ Object
Constructor Details
#initialize(username, password) ⇒ NajdiSms
Returns a new instance of NajdiSms.
4 5 6 |
# File 'lib/najdi-sms.rb', line 4 def initialize(username, password) login(username, password) end |
Class Method Details
.send_sms(username, password, number, message) ⇒ Object
36 37 38 |
# File 'lib/najdi-sms.rb', line 36 def self.send_sms(username, password, number, ) self.new(username, password).send_sms(number, ) end |
Instance Method Details
#login(username, password) ⇒ Object
8 9 10 11 12 |
# File 'lib/najdi-sms.rb', line 8 def login(username, password) agent.get("http://www.najdi.si/auth/login.jsp", :lg => 0, :target_url => "http://www.najdi.si/index.jsp") r = agent.post("https://id.najdi.si/j_spring_security_check", {:j_username => username, :j_password => password}, {"Referer" => "https://id.najdi.si/login"}) end |
#send_sms(number, message) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/najdi-sms.rb', line 14 def send_sms(number, ) number.gsub!(/[^\d]/, "") number.gsub!(/\A0/, "") number =~ /(\d{2})(\d{3})(\d{3})/ area, num1, num2 = $1, $2, $3 params = { "sms_action" => 4, "sms_so_l_" => "#{num1} #{num2}", "sms_so_ac_" => area, "myContacts" => "", "sms_message_" => } r = agent.get("http://www.najdi.si/sms/smsController.jsp", params, "http://www.najdi.si/", "X-Requested-With" => "XMLHttpRequest", "X-Prototype-Version" => "1.6.0.3") r = JSON::parse(r.body) if r["msg_left"] != nil r["msg_left"] else false end end |