najdi-sms 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/najdi-sms.rb +42 -0
  2. metadata +63 -0
data/lib/najdi-sms.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'mechanize'
2
+ require 'json'
3
+ class NajdiSms
4
+ def initialize(username, password)
5
+ login(username, password)
6
+ end
7
+
8
+ def login(username, password)
9
+ agent.get("http://www.najdi.si/auth/login.jsp", :lg => 0, :target_url => "http://www.najdi.si/index.jsp")
10
+ r = agent.post("https://id.najdi.si/j_spring_security_check",
11
+ {:j_username => username, :j_password => password}, {"Referer" => "https://id.najdi.si/login"})
12
+ end
13
+
14
+ def send_sms(number, message)
15
+ number.gsub!(/[^\d]/, "")
16
+ number.gsub!(/\A0/, "")
17
+ number =~ /(\d{2})(\d{3})(\d{3})/
18
+ area, num1, num2 = $1, $2, $3
19
+
20
+ params = {
21
+ "sms_action" => 4,
22
+ "sms_so_l_" => "#{num1} #{num2}",
23
+ "sms_so_ac_" => area,
24
+ "myContacts" => "",
25
+ "sms_message_" => message
26
+ }
27
+ 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")
28
+ r = JSON::parse(r.body)
29
+ if r["msg_left"] != nil
30
+ r["msg_left"]
31
+ else
32
+ false
33
+ end
34
+ end
35
+
36
+ private
37
+ def agent
38
+ @agent ||= Mechanize.new do |agent|
39
+ agent.user_agent_alias = 'Mac Safari'
40
+ end
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: najdi-sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jan Berdajs
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Send SMSes through najdi.si (slovenian site).
31
+ email:
32
+ - mrbrdo@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/najdi-sms.rb
38
+ homepage: https://github.com/mrbrdo/najdi-sms
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.24
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Send SMSes through najdi.si (slovenian site).
62
+ test_files: []
63
+ has_rdoc: