sendsms 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sendsms.rb +102 -0
- metadata +59 -0
data/lib/sendsms.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "net/https"
|
3
|
+
require "uri"
|
4
|
+
require "hpricot"
|
5
|
+
|
6
|
+
class SendSms
|
7
|
+
attr_accessor :username, :password
|
8
|
+
|
9
|
+
URL = 'http://site6.way2sms.com'
|
10
|
+
|
11
|
+
def initialize(username = "", password = "",autologin = true)
|
12
|
+
@username = username
|
13
|
+
@password = password
|
14
|
+
@uri = URI.parse URL
|
15
|
+
@cookie = @action = nil
|
16
|
+
@referer = URL
|
17
|
+
@http = Net::HTTP.new(@uri.host,@uri.port)
|
18
|
+
end
|
19
|
+
|
20
|
+
def set_header(cookie=nil,referer=nil)
|
21
|
+
{"Cookie" => cookie , "Referer" => referer ,"Content-Type" => "application/x-www-form-urlencoded",
|
22
|
+
"User-Agent" => "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20091020 Ubuntu/9.10 (karmic) Firefox/3.5.3 GTB7.0" }
|
23
|
+
end
|
24
|
+
|
25
|
+
def validate(msisdn = nil)
|
26
|
+
result = /^(\+|00)?(91)?(9|8|7)[0-9]{9}$/.match(msisdn)
|
27
|
+
return {:success => false,:message => "Invalid Msisdn"} if result.nil?
|
28
|
+
msisdn_formated = result[0][-10..-1]
|
29
|
+
return {:success => true,:message => "Valid Msisdn",:msisdn => msisdn_formated}
|
30
|
+
end
|
31
|
+
|
32
|
+
def login
|
33
|
+
data = 'username='+@username+'&password='+@password
|
34
|
+
headers = set_header @cookie, @referer
|
35
|
+
response = @http.post("/Login1.action",data,headers.delete_if {|i,j| j.nil? })
|
36
|
+
case response.code
|
37
|
+
when /3\d{2}/
|
38
|
+
if response['location'].include?("Main.action")
|
39
|
+
@cookie ||= response['set-cookie']
|
40
|
+
@referer ||= response['referer']
|
41
|
+
@action = getAction
|
42
|
+
return {:success => true,:message => "Login successfully"}
|
43
|
+
end
|
44
|
+
return {:success => false,:message => "Login failed"}
|
45
|
+
else
|
46
|
+
return {:success => false,:message => "Http Error"}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def getAction
|
51
|
+
headers = set_header @cookie, @referer
|
52
|
+
response = @http.get("/jsp/InstantSMS.jsp",headers.delete_if {|i,j| j.nil? })
|
53
|
+
hdoc = Hpricot(response.body)
|
54
|
+
return (hdoc/"#Action").attr('value')
|
55
|
+
end
|
56
|
+
|
57
|
+
def send_sms msisdn,message
|
58
|
+
headers = set_header @cookie, @referer
|
59
|
+
data = "MobNo=#{msisdn}&textArea=#{message}&HiddenAction=instantsms&login=&pass=&Action=#{@action}"
|
60
|
+
return @http.post("/quicksms.action?custid=\"+custid+\"&sponserid=\"+sponserid+\"",data,headers.delete_if {|i,j| j.nil? })
|
61
|
+
end
|
62
|
+
|
63
|
+
def send msisdn,message
|
64
|
+
if @cookie.nil?
|
65
|
+
login_res = login
|
66
|
+
return {:success => false,:message => "Login failed"} if !login_res[:success]
|
67
|
+
end
|
68
|
+
|
69
|
+
response = send_sms msisdn,message
|
70
|
+
case response.code
|
71
|
+
when /2\d{2}/
|
72
|
+
return {:success => true,:message => "Send successfully"}
|
73
|
+
else
|
74
|
+
return {:success => false,:message => "Sending failed"}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def send_to_many msisdns, message
|
79
|
+
if @cookie.nil?
|
80
|
+
login_res = login
|
81
|
+
return {:success => false,:message => "Login failed"} if !login_res[:success]
|
82
|
+
end
|
83
|
+
|
84
|
+
msisdns = msisdns.split(';')
|
85
|
+
response = {}
|
86
|
+
msisdns.each do | msisdn |
|
87
|
+
response[msisdn] = send msisdn,message
|
88
|
+
end
|
89
|
+
return response
|
90
|
+
end
|
91
|
+
|
92
|
+
def logout
|
93
|
+
response = @http.get("/jsp/logout.jsp");
|
94
|
+
@cookie = nil
|
95
|
+
case response.code
|
96
|
+
when /2\d{2}/
|
97
|
+
return {:success => true,:message => "Logout successfully"}
|
98
|
+
else
|
99
|
+
return {:success => false,:message => "Logout failed"}
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sendsms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Revath S Kumar
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-27 00:00:00.000000000 +05:30
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hpricot
|
17
|
+
requirement: &17388780 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *17388780
|
26
|
+
description: The library Helps you to send SMS via way2sms in India
|
27
|
+
email:
|
28
|
+
- rsk@revathskumar.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/sendsms.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://blog.revathskumar.com
|
36
|
+
licenses: []
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.6.2
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: Send SMS via way2sms
|
59
|
+
test_files: []
|