flyerhzm-rfetion 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/rfetion/fetion.rb +23 -15
  3. data/rfetion.gemspec +2 -2
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -10,7 +10,7 @@ class Fetion
10
10
  FETION_CONFIG_URL = 'http://nav.fetion.com.cn/nav/getsystemconfig.aspx'
11
11
  FETION_SIPP = 'SIPP'
12
12
  GUID = UUID.new.generate
13
- @@nonce = nil
13
+ @nonce = nil
14
14
 
15
15
  def initialize
16
16
  @next_call = 0
@@ -32,6 +32,7 @@ class Fetion
32
32
  fetion.login
33
33
  fetion.register
34
34
  fetion.send_sms(fetion.uri, content)
35
+ fetion.logout
35
36
  end
36
37
 
37
38
  def Fetion.send_sms_to_friends(mobile_no, password, friend_mobiles, content)
@@ -48,6 +49,7 @@ class Fetion
48
49
  fetion.send_sms(contact[:sip], content)
49
50
  end
50
51
  end
52
+ fetion.logout
51
53
  end
52
54
 
53
55
  def login
@@ -97,21 +99,19 @@ class Fetion
97
99
  curl_exec(next_url('i'), @ssic, msg)
98
100
 
99
101
  response = curl_exec(next_url, @ssic, FETION_SIPP)
100
- unless @@nonce
101
- raise FetionException.new("Fetion Error: no nonce found") unless response.body =~ /nonce="(\w+)"/
102
- @@nonce = $1
103
- end
102
+ raise FetionException.new("Fetion Error: no nonce found") unless response.body =~ /nonce="(\w+)"/
104
103
 
105
- @@salt = "777A6D03"
106
- @@cnonce = calc_cnonce
107
- @@response = calc_response
104
+ @nonce = $1
105
+ @salt = "777A6D03"
106
+ @cnonce = calc_cnonce
107
+ @response = calc_response
108
108
 
109
- @logger.debug "nonce: #{@@nonce}"
110
- @logger.debug "salt: #{@@salt}"
111
- @logger.debug "cnonce: #{@@cnonce}"
112
- @logger.debug "response: #{@@response}"
109
+ @logger.debug "nonce: #{@nonce}"
110
+ @logger.debug "salt: #{@salt}"
111
+ @logger.debug "cnonce: #{@cnonce}"
112
+ @logger.debug "response: #{@response}"
113
113
 
114
- msg = sip_create('R fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => call, 'Q' => '2 R', 'A' => "Digest algorithm=\"SHA1-sess\",response=\"#{@@response}\",cnonce=\"#{@@cnonce}\",salt=\"#{@@salt}\""}, arg) + FETION_SIPP
114
+ msg = sip_create('R fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => call, 'Q' => '2 R', 'A' => "Digest algorithm=\"SHA1-sess\",response=\"#{@response}\",cnonce=\"#{@cnonce}\",salt=\"#{@salt}\""}, arg) + FETION_SIPP
115
115
  curl_exec(next_url, @ssic, msg)
116
116
  response = curl_exec(next_url, @ssic, FETION_SIPP)
117
117
 
@@ -162,6 +162,14 @@ class Fetion
162
162
  response.is_a? Net::HTTPSuccess
163
163
  end
164
164
 
165
+ def logout
166
+ @logger.info "fetion logout"
167
+ msg = sip_create('R fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '2 R', 'X' => 0}, '') + FETION_SIPP
168
+ curl_exec(next_url, @ssic, msg)
169
+ response = curl_exec(next_url, @ssic, FETION_SIPP)
170
+ @logger.info "fetion logout success"
171
+ end
172
+
165
173
  def curl_exec(url, ssic, body)
166
174
  @logger.debug "fetion curl exec"
167
175
  @logger.debug "url: #{url}"
@@ -190,10 +198,10 @@ class Fetion
190
198
  str = [hash_password[8..-1]].pack("H*")
191
199
  key = Digest::SHA1.digest("#{@sid}:#{@domain}:#{str}")
192
200
 
193
- h1 = Digest::MD5.hexdigest("#{key}:#{@@nonce}:#{@@cnonce}").upcase
201
+ h1 = Digest::MD5.hexdigest("#{key}:#{@nonce}:#{@cnonce}").upcase
194
202
  h2 = Digest::MD5.hexdigest("REGISTER:#{@sid}").upcase
195
203
 
196
- Digest::MD5.hexdigest("#{h1}:#{@@nonce}:#{h2}").upcase
204
+ Digest::MD5.hexdigest("#{h1}:#{@nonce}:#{h2}").upcase
197
205
  end
198
206
 
199
207
  def calc_cnonce
data/rfetion.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rfetion}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Richard Huang"]
12
- s.date = %q{2009-09-18}
12
+ s.date = %q{2009-09-19}
13
13
  s.description = %q{rfetion is a ruby gem for China Mobile fetion service that you can send SMS free.}
14
14
  s.email = %q{flyerhzm@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flyerhzm-rfetion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-18 00:00:00 -07:00
12
+ date: 2009-09-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15