rfetion 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.3
@@ -1,3 +1,4 @@
1
+ #coding: utf-8
1
2
  class Fetion
2
3
  class Contact
3
4
  attr_accessor :id, :sid, :uri, :mobile_no, :nickname, :impresa, :nickname, :status
@@ -8,8 +8,8 @@ require 'openssl'
8
8
  require 'logger'
9
9
 
10
10
  class Fetion
11
- attr_accessor :mobile_no, :sid, :password
12
- attr_reader :user_id, :uri, :contacts, :buddy_lists, :response, :nickname, :receives
11
+ attr_accessor :mobile_no, :sid, :password, :seq, :ssic, :guid, :uri
12
+ attr_reader :user_id, :contacts, :buddy_lists, :response, :nickname, :receives
13
13
 
14
14
  FETION_URL = 'http://221.176.31.39/ht/sd.aspx'
15
15
  FETION_LOGIN_URL = 'https://uid.fetion.com.cn/ssiportal/SSIAppSignInV4.aspx?mobileno=%mobileno%sid=%sid%&domains=fetion.com.cn;m161.com.cn;www.ikuwa.cn&v4digest-type=1&v4digest=%digest%'
@@ -48,6 +48,16 @@ class Fetion
48
48
  fetion.logout
49
49
  end
50
50
 
51
+ def Fetion.keep_alive(options)
52
+ Fetion.open(options) do
53
+ get_contacts
54
+ keep_alive
55
+ sleep(15)
56
+ keep_alive
57
+ p receives
58
+ end
59
+ end
60
+
51
61
  # options
52
62
  # mobile_no
53
63
  # sid
@@ -283,6 +293,31 @@ class Fetion
283
293
  @logger.info "fetion logout success"
284
294
  end
285
295
 
296
+ def create_session(sipc_response)
297
+ @logger.info "fetion create session"
298
+
299
+ sipc_response = curl_exec(SipcMessage.create_session(self, sipc_response))
300
+ pulse unless sipc_response
301
+
302
+ @logger.info "fetion create session success"
303
+ end
304
+
305
+ def session_connected(sipc_response)
306
+ @logger.info "fetion session connected"
307
+
308
+ curl_exec(SipcMessage.session_connected(self, sipc_response))
309
+
310
+ @logger.info "fetion session connected success"
311
+ end
312
+
313
+ def msg_received(message_response)
314
+ @logger.info "fetion msg received"
315
+
316
+ curl_exec(SipcMessage.msg_received(self, message_response))
317
+
318
+ @logger.info "fetion msg received success"
319
+ end
320
+
286
321
  def parse_ssic(response)
287
322
  raise Fetion::LoginException.new('Fetion Error: Login failed.') unless Net::HTTPSuccess === response
288
323
  raise Fetion::LoginException.new('Fetion Error: No ssic found in cookie.') unless response['set-cookie'] =~ /ssic=(.*);/
@@ -332,9 +367,9 @@ class Fetion
332
367
  sipc_response = SipcMessage.sipc_response(response.body, self)
333
368
 
334
369
  if sipc_response
335
- raise Fetion::SipcException.new(sipc_response, "request_url: #{url}, request_body: #{body}, sipc_response: #{sipc_response}") unless expected === sipc_response
370
+ raise Fetion::SipcException.new(sipc_response, "request_url: #{url}, request_body: #{body}, sipc_response: #{sipc_response}") unless sipc_response.class == expected
336
371
 
337
- if sipc_response.code == 401
372
+ if sipc_response.first_line =~ /401/
338
373
  # unauthorized, get nonce, key and signature
339
374
  raise Fetion::NoNonceException.new("Fetion Error: No nonce found") unless response.body =~ /nonce="(.*?)",key="(.*?)",signature="(.*?)"/
340
375
  @nonce = $1
@@ -346,6 +381,10 @@ class Fetion
346
381
  @logger.debug "key: #{@key}"
347
382
  @logger.debug "signature: #{@signature}"
348
383
  @logger.debug "response: #{@response}"
384
+ elsif sipc_response.contain?('I')
385
+ create_session(sipc_response)
386
+ elsif sipc_response.contain?('O')
387
+ session_connected(sipc_response)
349
388
  else
350
389
  response.body.scan(%r{<results>.*?</results>}).each do |results|
351
390
  doc = Nokogiri::XML(results)
@@ -355,11 +394,9 @@ class Fetion
355
394
  end
356
395
  doc.root.xpath("/results/user-info/contact-list/buddy-lists/buddy-list").each do |buddy_list|
357
396
  @buddy_lists << Fetion::BuddyList.parse(buddy_list)
358
- @logger.debug "buddy_lists: #{@buddy_lists.inspect}"
359
397
  end
360
398
  doc.root.xpath("/results/user-info/contact-list/buddies/b").each do |buddy|
361
399
  @buddies << {:uri => buddy["u"]}
362
- @logger.debug "buddies: #{@buddies.inspect}"
363
400
  end
364
401
  end
365
402
 
@@ -376,11 +413,11 @@ class Fetion
376
413
  end
377
414
 
378
415
  receive_messages = response.body.scan(%r{M #{@sid} SIP-C/4.0.*?BN}m)
379
- receive_messages = response.body.scan(%r{M #{@sid} SIP-C/4.0.*?SIPP$}m) if receive_messages.empty?
416
+ receive_messages = response.body.scan(%r{M #{@sid} SIP-C/4.0.*?SIPP\r?\n?$}m) if receive_messages.empty?
380
417
  receive_messages.each do |message_response|
381
- message_header, message_content = message_response.split(/(\r)?\n(\r)?\n/)
418
+ message_header, message_content = message_response.split(/\r\n\r\n/)
382
419
  sip = sent_at = length = nil
383
- message_header.split(/(\r)?\n/).each do |line|
420
+ message_header.split(/\r\n/).each do |line|
384
421
  case line
385
422
  when /^F: sip:(.+)/ then sip = $1
386
423
  when /^D: (.+)/ then sent_at = Time.parse($1)
@@ -389,10 +426,11 @@ class Fetion
389
426
  end
390
427
  text = message_content.slice(0, length)
391
428
  @receives << Fetion::Message.new(sip, sent_at, text)
429
+ msg_received(message_response)
392
430
  end
393
431
  end
394
432
  end
395
- response
433
+ sipc_response
396
434
  end
397
435
 
398
436
  def next_url(t = 's')
@@ -440,11 +478,10 @@ class Fetion::AddBuddyException < FetionException; end
440
478
  class Fetion::GetContactsException < FetionException; end
441
479
  class Fetion::NoUserException < FetionException; end
442
480
  class Fetion::SipcException < FetionException
443
- attr_reader :code, :description, :message
481
+ attr_reader :first_line, :message
444
482
 
445
483
  def initialize(sipc_response, message)
446
- @code = sipc_response.code
447
- @description = sipc_response.description
484
+ @first_line = sipc_response.first_line
448
485
  @message = message
449
486
  end
450
- end
487
+ end
@@ -58,29 +58,98 @@ class SipcMessage
58
58
  sipc_create(:command => 'R', :F => fetion.sid, :I => 1, :Q => '3 R', :X => 0, :with_l => false)
59
59
  end
60
60
 
61
+ def self.create_session(fetion, last_sipc_response)
62
+ header = {}
63
+ last_sipc_response.sections.each do |section|
64
+ sipc_header = section.split("\r\n\r\n").first
65
+ if sipc_header.split("\r\n").first =~ %r|I #{fetion.sid} SIP-C/4.0|
66
+ sipc_header.split("\r\n")[1..-1].each do |line|
67
+ key, value = line.split(': ', 2)
68
+ if key == 'K'
69
+ header['K'] ? header['K'] << value : header['K'] = [value]
70
+ else
71
+ header[key] = value
72
+ end
73
+ end
74
+ body = %Q|v=0\r\no=-0 0 IN 127.0.0.1:8001\r\ns=session\r\nc=IN IP4 127.0.0.1:8001\r\nt=0 0\r\nm=message 8001 sip sip:#{fetion.uri}\r\n|
75
+ return sipc_response_create(:I => header['I'], :Q => header['Q'], :F => header['F'], :K => header['K'], :body => body, :f_first => false)
76
+ end
77
+ end
78
+ end
79
+
80
+ def self.session_connected(fetion, last_sipc_response)
81
+ header = {}
82
+ last_sipc_response.sections.each do |section|
83
+ sipc_header = section.split("\r\n\r\n").first
84
+ if sipc_header.split("\r\n").first =~ %r|O #{fetion.sid} SIP-C/4.0|
85
+ sipc_header.split("\r\n")[1..-1].each do |line|
86
+ key, value = line.split(': ', 2)
87
+ header[key] = value
88
+ end
89
+ header['K'] = ['text/html-fragment', 'text/plain']
90
+ return sipc_response_create(:F => header['F'], :I => header['I'], :Q => header['Q'], :K => header['K'], :with_l => false)
91
+ end
92
+ end
93
+ end
94
+
95
+ def self.msg_received(fetion, message_response)
96
+ header = {}
97
+ message_response.split("\r\n\r\n").first.split("\r\n")[1..-1].each do |line|
98
+ key, value = line.split(': ', 2)
99
+ header[key] = value
100
+ end
101
+ sipc_response_create(:F => header['F'], :I => header['I'], :Q => header['Q'], :with_l => false)
102
+ end
103
+
104
+ def self.close_session(fetion, receiver_uri)
105
+ sipc_create(:command => 'B', :F => fetion.sid, :I => fetion.next_call, :Q => '2 B', :T => "sip:#{receiver_uri}", :with_l => false)
106
+ end
107
+
61
108
  def self.sipc_response(http_response_body, fetion)
62
109
  return if http_response_body == Fetion::SIPP
63
110
 
64
- if http_response_body =~ %r{^SIP-C/4.0}
65
- sipc, code, *message = http_response_body.split(/(\r)?\n/).first.split(' ')
66
- RESPONSES[code.to_i].new(code.to_i, message.join(' '))
67
- elsif http_response_body =~ %r{(BN|M) #{fetion.sid} SIP-C/4.0}
68
- SipcMessage::OK.new(200, $1)
111
+ sections = []
112
+ body = http_response_body
113
+ while true
114
+ index = body.index(%r{(BN|M|I|O) #{fetion.sid} SIP-C/4.0}, 1)
115
+ if index
116
+ sections << body[0...index]
117
+ body = body[index..-1]
118
+ else
119
+ sections << body
120
+ break
121
+ end
69
122
  end
123
+ SipcMessage::Response.new(sections)
70
124
  rescue NoMethodError
71
- raise FetionException.new("Fetion error: No response to #{code} #{message.join(' ')}")
125
+ raise FetionException.new("Fetion error: No response to #{sections.first.split("\r\n").first}")
72
126
  end
73
127
 
74
128
  class Response
75
- attr_reader :code, :description
129
+ attr_reader :sections
130
+
131
+ def initialize(sections)
132
+ @sections = sections
133
+ end
76
134
 
77
- def initialize(code, description)
78
- @code = code
79
- @description = description
135
+ def class
136
+ if first_line =~ %r|^SIP-C/4.0 (\d{3})|
137
+ RESPONSES[$1.to_i]
138
+ else
139
+ SipcMessage::OK
140
+ end
141
+ end
142
+
143
+ def first_line
144
+ @sections.first.split("\r\n").first
145
+ end
146
+
147
+ def contain?(command)
148
+ @sections.find {|section| section.split("\r\n").first.index(%r|#{command} |) }
80
149
  end
81
150
 
82
151
  def to_s
83
- "#@code #@description"
152
+ @sections.first.split("\r\n").first
84
153
  end
85
154
  end
86
155
 
@@ -116,4 +185,25 @@ class SipcMessage
116
185
  sipc += "\r\n#{body}#{Fetion::SIPP}"
117
186
  sipc
118
187
  end
188
+
189
+ def self.sipc_response_create(options)
190
+ options = {:body => '', :with_l => true, :f_first => true}.merge(options)
191
+ body = options.delete(:body)
192
+ with_l = options.delete(:with_l)
193
+
194
+ sorted_key = options.delete(:f_first) ? [:F, :I, :Q, :K] : [:I, :Q, :F, :K]
195
+ sipc = "SIP-C/4.0 200 OK\r\n"
196
+ sorted_key.each do |k|
197
+ if options[k]
198
+ if k == :K
199
+ sipc += options[:K].collect { |v| "#{k}: #{v}\r\n" }.join("")
200
+ else
201
+ sipc += "#{k}: #{options[k]}\r\n"
202
+ end
203
+ end
204
+ end
205
+ sipc += "L: #{body == '' ? 4 : body.size}\r\n" if with_l
206
+ sipc += "\r\n#{body}#{Fetion::SIPP}"
207
+ sipc
208
+ end
119
209
  end
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.5.2"
8
+ s.version = "0.5.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{2010-05-15}
12
+ s.date = %q{2010-05-16}
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.executables = ["rfetion", "rfetion"]
@@ -69,6 +69,7 @@ W: Digest algorithm="SHA1-sess-v4",nonce="1104E253661D71141DFE3FB020143E5A",key=
69
69
 
70
70
  SIPP
71
71
  EOF
72
+ response_body.gsub!("\n", "\r\n")
72
73
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=3", :body => response_body)
73
74
  @fetion.register_first
74
75
 
@@ -90,6 +91,7 @@ W: Digest algorithm="SHA1-sess-v4",nonce=""
90
91
 
91
92
  SIPP
92
93
  EOF
94
+ response_body.gsub!("\n", "\r\n")
93
95
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=3", :body => response_body)
94
96
  lambda { @fetion.register_first }.should raise_exception(Fetion::NoNonceException)
95
97
  end
@@ -120,6 +122,7 @@ L: 125
120
122
 
121
123
  <events><event type="SyncUserInfo"><user-info><score value="3760" level="7" level-score="3718"/></user-info></event></events>SIPP
122
124
  EOF
125
+ response_body.gsub!("\n", "\r\n")
123
126
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=5", :body => response_body)
124
127
  @fetion.register_second
125
128
 
@@ -146,6 +149,7 @@ L: 59
146
149
 
147
150
  <results><group-list version ="1" ></group-list></results>SIPP
148
151
  EOF
152
+ response_body.gsub!("\n", "\r\n")
149
153
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=7", :body => "SIPP")
150
154
  response_body =<<-EOF
151
155
  SIP-C/4.0 200 OK
@@ -208,6 +212,7 @@ Q: 10 BN
208
212
 
209
213
  <events><event type="MobileMailBoxChanged"><mail unread-count="1"/></event></events>SIPP
210
214
  EOF
215
+ response_body.gsub!("\n", "\r\n")
211
216
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=8", :body => response_body)
212
217
  response_body =<<-EOF
213
218
  SIP-C/4.0 200 OK
@@ -217,6 +222,7 @@ L: 835
217
222
 
218
223
  <results><topic-list event="RecommendGroupTopic" version="171" max-count="5"><topic title="陌上人如玉 韩庚世无双" url="http://group.fetion.com.cn/topic/common/31333572/196313?c=[c:m161.com.cn]" create-date="2010-5-6 15:36:30" id="171" topic-type="1" /><topic title="世博园10大最美景观" url="http://group.fetion.com.cn/topic/common/8249155/196251?c=[c:m161.com.cn]" create-date="2010-5-6 15:33:49" id="170" topic-type="1" /><topic title="诺基亚价值百万的手机" url="http://group.fetion.com.cn/topic/common/7366464/196288?c=[c:m161.com.cn]" create-date="2010-5-6 15:31:57" id="169" topic-type="1" /><topic title="选秀调查:伪娘的真相" url="http://group.fetion.com.cn/topic/common/30660603/196323?c=[c:m161.com.cn]" create-date="2010-5-6 15:22:51" id="168" topic-type="1" /></topic-list></results>SIPP
219
224
  EOF
225
+ response_body.gsub!("\n", "\r\n")
220
226
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=9", :body => response_body)
221
227
  response_body =<<-EOF
222
228
  SIP-C/4.0 200 OK
@@ -226,12 +232,13 @@ L: 61
226
232
 
227
233
  <results><contacts version="326661305" ></contacts></results>SIPP
228
234
  EOF
235
+ response_body.gsub!("\n", "\r\n")
229
236
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=10", :body => response_body)
230
237
  @fetion.get_contacts
231
238
  @fetion.contacts.collect {|contact| contact.sid}.should == ["793401629", "737769829", "660250260", "926157269", "669700695", "760087520", "480867781", "572512981", "638993408"]
232
239
  end
233
240
 
234
- it "should get received msg" do
241
+ it "should get received msg while get contacts" do
235
242
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=6", :body => "SIPP")
236
243
  response_body =<<-EOF
237
244
  SIP-C/4.0 200 OK
@@ -241,6 +248,7 @@ L: 59
241
248
 
242
249
  <results><group-list version ="1" ></group-list></results>SIPP
243
250
  EOF
251
+ response_body.gsub!("\n", "\r\n")
244
252
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=7", :body => "SIPP")
245
253
  response_body =<<-EOF
246
254
  SIP-C/4.0 200 OK
@@ -311,6 +319,7 @@ Q: 11 BN
311
319
 
312
320
  <events><event type="PresenceChanged"><contacts><c id="295098062"><p v="0" sid="638993408" su="sip:638993408@fetion.com.cn;p=2242" m="13634102006" c="CMCC" cs="0" s="1" l="0" svc="" n="梦妍" i="" p="0" sms="0.0:0:0" sp="0" sh="0"/><pr di="" b="0" d="" dt="" dc="0"/></c></contacts></event></events>SIPP
313
321
  EOF
322
+ response_body.gsub!("\n", "\r\n")
314
323
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=8", :body => response_body)
315
324
  response_body =<<-EOF
316
325
  SIP-C/4.0 200 OK
@@ -320,6 +329,7 @@ L: 835
320
329
 
321
330
  <results><topic-list event="RecommendGroupTopic" version="171" max-count="5"><topic title="陌上人如玉 韩庚世无双" url="http://group.fetion.com.cn/topic/common/31333572/196313?c=[c:m161.com.cn]" create-date="2010-5-6 15:36:30" id="171" topic-type="1" /><topic title="世博园10大最美景观" url="http://group.fetion.com.cn/topic/common/8249155/196251?c=[c:m161.com.cn]" create-date="2010-5-6 15:33:49" id="170" topic-type="1" /><topic title="诺基亚价值百万的手机" url="http://group.fetion.com.cn/topic/common/7366464/196288?c=[c:m161.com.cn]" create-date="2010-5-6 15:31:57" id="169" topic-type="1" /><topic title="选秀调查:伪娘的真相" url="http://group.fetion.com.cn/topic/common/30660603/196323?c=[c:m161.com.cn]" create-date="2010-5-6 15:22:51" id="168" topic-type="1" /></topic-list></results>SIPP
322
331
  EOF
332
+ response_body.gsub!("\n", "\r\n")
323
333
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=9", :body => response_body)
324
334
  response_body =<<-EOF
325
335
  SIP-C/4.0 200 OK
@@ -329,7 +339,9 @@ L: 61
329
339
 
330
340
  <results><contacts version="326661305" ></contacts></results>SIPP
331
341
  EOF
342
+ response_body.gsub!("\n", "\r\n")
332
343
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=10", :body => response_body)
344
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=11", :body => "SIPP")
333
345
  @fetion.get_contacts
334
346
  @fetion.contacts.collect {|c| c.sid}.should == ["793401629", "737769829", "660250260", "926157269", "669700695", "760087520", "480867781", "572512981", "638993408"]
335
347
  @fetion.receives.collect {|r| r.sip}.should == ["480867781@fetion.com.cn;p=16105"]
@@ -355,6 +367,7 @@ T: sip:638993408@fetion.com.cn;p=2242
355
367
 
356
368
  SIPP
357
369
  EOF
370
+ response_body.gsub!("\n", "\r\n")
358
371
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=12", :body => response_body)
359
372
  @fetion.send_msg('sip:638993408@fetion.com.cn;p=2242', 'test')
360
373
  end
@@ -375,6 +388,7 @@ Q: 1 M
375
388
 
376
389
  SIPP
377
390
  EOF
391
+ response_body.gsub!("\n", "\r\n")
378
392
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=12", :body => response_body)
379
393
  @fetion.send_sms('sip:638993408@fetion.com.cn;p=2242', 'test')
380
394
  end
@@ -395,6 +409,7 @@ L: 92
395
409
 
396
410
  <results><schedule-sms-list version="36"/><schedule-sms id="2124923" version="1"/></results>SIPP
397
411
  EOF
412
+ response_body.gsub!("\n", "\r\n")
398
413
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=12", :body => response_body)
399
414
  @fetion.set_schedule_sms('sip:638993408@fetion.com.cn;p=2242', 'test', Time.at(Time.now + 24*60*60))
400
415
  end
@@ -428,6 +443,7 @@ Q: 18 BN
428
443
 
429
444
  <events><event type="PresenceChanged"><contacts><c id="295098062"><p v="326156919" sid="638993408" su="sip:638993408@fetion.com.cn;p=2242" m="13634102006" c="CMCC" cs="0" s="1" l="0" svc="" n="梦研" i="" p="0" sms="0.0:0:0" sp="0" sh="0"/><pr di="PCCL030333103486" b="400" d="" dt="PC" dc="17"/></c></contacts></event></events>SIPP
430
445
  EOF
446
+ response_body.gsub!("\n", "\r\n")
431
447
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=13", :body => response_body)
432
448
  @fetion.add_buddy(:friend_mobile => '13634102006')
433
449
  end
@@ -448,6 +464,7 @@ L: 166
448
464
 
449
465
  <results><contact uri="tel:15800681507" version="0" user-id="625007505" mobile-no="15800681507" basic-service-status="0" carrier="CMCC" carrier-status="0"/></results>SIPP
450
466
  EOF
467
+ response_body.gsub!("\n", "\r\n")
451
468
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=13", :body => response_body)
452
469
  @fetion.get_contact_info(:friend_mobile => '15800681507')
453
470
  end
@@ -461,6 +478,7 @@ Q: 1 S
461
478
 
462
479
  SIPP
463
480
  EOF
481
+ response_body.gsub!("\n", "\r\n")
464
482
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=13", :body => response_body)
465
483
  lambda {@fetion.get_contact_info(:friend_mobile => '15800681505')}.should raise_exception(Fetion::SipcException)
466
484
  end
@@ -496,11 +514,130 @@ Q: 11 BN
496
514
 
497
515
  <events><event type="PresenceChanged"><contacts><c id="295098062"><pr di="PCCL030340538483" b="400" d="" dt="PC" dc="17"/></c></contacts></event></events>SIPP
498
516
  EOF
517
+ response_body.gsub!("\n", "\r\n")
499
518
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=11", :body => response_body)
500
519
  @fetion.keep_alive
501
520
  @fetion.contacts.find {|contact| contact.id == '295098062'}.status.should == "400"
502
521
  end
503
522
 
523
+
524
+ it "should get receive msg for first session" do
525
+ response_body =<<-EOF
526
+ I 730020377 SIP-C/4.0
527
+ F: sip:638993408@fetion.com.cn;p=2242
528
+ I: -13
529
+ K: text/plain
530
+ K: text/html-fragment
531
+ K: multiparty
532
+ K: nudge
533
+ Q: 14 I
534
+ L: 21
535
+
536
+ s=session
537
+ m=message SIPP
538
+ EOF
539
+ response_body.gsub!("\n", "\r\n")
540
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=11", :body => response_body)
541
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=12", :body => "SIPP")
542
+ response_body =<<-EOF
543
+ O 730020377 SIP-C/4.0
544
+ I: -13
545
+ Q: 2 O
546
+ K: text/plain
547
+ K: text/html-fragment
548
+ K: multiparty
549
+ K: nudge
550
+ F: sip:638993408@fetion.com.cn;p=2242
551
+
552
+ A 730020377 SIP-C/4.0
553
+ F: sip:638993408@fetion.com.cn;p=2242
554
+ I: -13
555
+ Q: 14 A
556
+
557
+ SIPP
558
+ EOF
559
+ response_body.gsub!("\n", "\r\n")
560
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=13", :body => response_body)
561
+ response_body =<<-EOF
562
+ M 730020377 SIP-C/4.0
563
+ I: -13
564
+ Q: 4 M
565
+ F: sip:638993408@fetion.com.cn;p=2242
566
+ C: text/html-fragment
567
+ K: SaveHistory
568
+ L: 4
569
+ D: Sun, 16 May 2010 02:16:00 GMT
570
+ XI: 0dbdc4e81bff425dbcf8b591b497fe94
571
+
572
+ testSIPP
573
+ EOF
574
+ response_body.gsub!("\n", "\r\n")
575
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=14", :body => response_body)
576
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=15", :body => "SIPP")
577
+ @fetion.keep_alive
578
+ @fetion.receives.collect {|r| r.sip}.should == ["638993408@fetion.com.cn;p=2242"]
579
+ @fetion.receives.collect {|r| r.sent_at}.should == [Time.parse("Sun, 16 May 2010 02:16:00 GMT")]
580
+ @fetion.receives.collect {|r| r.text}.should == ["test"]
581
+ end
582
+
583
+ it "should get receive msg without pulse for first session" do
584
+ response_body =<<-EOF
585
+ I 730020377 SIP-C/4.0
586
+ F: sip:638993408@fetion.com.cn;p=2242
587
+ I: -13
588
+ K: text/plain
589
+ K: text/html-fragment
590
+ K: multiparty
591
+ K: nudge
592
+ Q: 14 I
593
+ L: 21
594
+
595
+ s=session
596
+ m=message SIPP
597
+ EOF
598
+ response_body.gsub!("\n", "\r\n")
599
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=11", :body => response_body)
600
+ response_body =<<-EOF
601
+ O 730020377 SIP-C/4.0
602
+ I: -13
603
+ Q: 2 O
604
+ K: text/plain
605
+ K: text/html-fragment
606
+ K: multiparty
607
+ K: nudge
608
+ F: sip:638993408@fetion.com.cn;p=2242
609
+
610
+ A 730020377 SIP-C/4.0
611
+ F: sip:638993408@fetion.com.cn;p=2242
612
+ I: -13
613
+ Q: 14 A
614
+
615
+ SIPP
616
+ EOF
617
+ response_body.gsub!("\n", "\r\n")
618
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=12", :body => response_body)
619
+ response_body =<<-EOF
620
+ M 730020377 SIP-C/4.0
621
+ I: -13
622
+ Q: 4 M
623
+ F: sip:638993408@fetion.com.cn;p=2242
624
+ C: text/html-fragment
625
+ K: SaveHistory
626
+ L: 4
627
+ D: Sun, 16 May 2010 02:16:00 GMT
628
+ XI: 0dbdc4e81bff425dbcf8b591b497fe94
629
+
630
+ testSIPP
631
+ EOF
632
+ response_body.gsub!("\n", "\r\n")
633
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=13", :body => response_body)
634
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=14", :body => "SIPP")
635
+ @fetion.keep_alive
636
+ @fetion.receives.collect {|r| r.sip}.should == ["638993408@fetion.com.cn;p=2242"]
637
+ @fetion.receives.collect {|r| r.sent_at}.should == [Time.parse("Sun, 16 May 2010 02:16:00 GMT")]
638
+ @fetion.receives.collect {|r| r.text}.should == ["test"]
639
+ end
640
+
504
641
  it "should get receive msg" do
505
642
  response_body =<<-EOF
506
643
  M 730020377 SIP-C/4.0
@@ -515,11 +652,8 @@ XI: 7eb8bc4e9df742b2aa557f9e85c8d8af
515
652
 
516
653
  testtesttestSIPP
517
654
  EOF
655
+ response_body.gsub!("\n", "\r\n")
518
656
  FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=11", :body => response_body)
519
- @fetion.keep_alive
520
- @fetion.receives.collect {|r| r.sip}.should == ["638993408@fetion.com.cn;p=2242"]
521
- @fetion.receives.collect {|r| r.sent_at}.should == [Time.parse("Tue, 11 May 2010 15:18:56 GMT")]
522
- @fetion.receives.collect {|r| r.text}.should == ["testtesttest"]
523
657
  end
524
658
  end
525
659
  end
@@ -10,6 +10,7 @@ describe SipcMessage do
10
10
  @fetion.sid = "730020377"
11
11
  @fetion.user_id = "390937727"
12
12
  @fetion.mobile_no = "15800681509"
13
+ @fetion.uri = "730020377@fetion.com.cn;p=6907"
13
14
  @fetion.response = "62E57A276EB9B7AAC233B8983A39941870CE74E3B2CD6480B5CA9DCF37C57DECEA250F261543CB4424EE9E72354C9F33C805EB9839BF96501D0261614E69BDF0DBDF484047750B3113DF8850FEF39428ADC17FE86E8800ED5A77AA7F6630F21AE8A24E6ECC2F003BF3B93E35051A7778D238F86D21581BC829679EBEAD36390F"
14
15
  end
15
16
 
@@ -18,76 +19,307 @@ describe SipcMessage do
18
19
  Guid.stubs(:new).returns(guid)
19
20
  guid.stubs(:hexdigest).returns(hexdigest)
20
21
  hexdigest.stubs(:upcase).returns("19D28D4978125CAA4F6E54277BA7D9EF")
21
- sipc_message = %Q|R fetion.com.cn SIP-C/4.0\r\nF: 730020377\r\nI: 1\r\nQ: 1 R\r\nCN: 19D28D4978125CAA4F6E54277BA7D9EF\r\nCL: type="pc" ,version="3.6.2020"\r\n\r\nSIPP|
22
+ sipc_message =<<-EOF
23
+ R fetion.com.cn SIP-C/4.0
24
+ F: 730020377
25
+ I: 1
26
+ Q: 1 R
27
+ CN: 19D28D4978125CAA4F6E54277BA7D9EF
28
+ CL: type="pc" ,version="3.6.2020"
29
+
30
+ SIPP
31
+ EOF
32
+ sipc_message.gsub!("\n", "\r\n").chomp!
22
33
  SipcMessage.register_first(@fetion).should == sipc_message
23
34
  end
24
35
 
25
36
  it "should get register_second" do
26
- sipc_message = %Q|R fetion.com.cn SIP-C/4.0\r\nF: 730020377\r\nI: 1\r\nQ: 2 R\r\nA: Digest response="62E57A276EB9B7AAC233B8983A39941870CE74E3B2CD6480B5CA9DCF37C57DECEA250F261543CB4424EE9E72354C9F33C805EB9839BF96501D0261614E69BDF0DBDF484047750B3113DF8850FEF39428ADC17FE86E8800ED5A77AA7F6630F21AE8A24E6ECC2F003BF3B93E35051A7778D238F86D21581BC829679EBEAD36390F",algorithm="SHA1-sess-v4"\r\nAK: ak-value\r\nL: 447\r\n\r\n<args><device machine-code="B04B5DA2F5F1B8D01A76C0EBC841414C" /><caps value="ff" /><events value="7f" /><user-info mobile-no="15800681509" user-id="390937727"><personal version="0" attributes="v4default" /><custom-config version="0" /><contact-list version="0" buddy-attributes="v4default" /></user-info><credentials domains="fetion.com.cn;m161.com.cn;www.ikuwa.cn;games.fetion.com.cn" /><presence><basic value="400" desc="" /></presence></args>SIPP|
37
+ sipc_message =<<-EOF
38
+ R fetion.com.cn SIP-C/4.0
39
+ F: 730020377
40
+ I: 1
41
+ Q: 2 R
42
+ A: Digest response="62E57A276EB9B7AAC233B8983A39941870CE74E3B2CD6480B5CA9DCF37C57DECEA250F261543CB4424EE9E72354C9F33C805EB9839BF96501D0261614E69BDF0DBDF484047750B3113DF8850FEF39428ADC17FE86E8800ED5A77AA7F6630F21AE8A24E6ECC2F003BF3B93E35051A7778D238F86D21581BC829679EBEAD36390F",algorithm="SHA1-sess-v4"
43
+ AK: ak-value
44
+ L: 447
45
+
46
+ <args><device machine-code="B04B5DA2F5F1B8D01A76C0EBC841414C" /><caps value="ff" /><events value="7f" /><user-info mobile-no="15800681509" user-id="390937727"><personal version="0" attributes="v4default" /><custom-config version="0" /><contact-list version="0" buddy-attributes="v4default" /></user-info><credentials domains="fetion.com.cn;m161.com.cn;www.ikuwa.cn;games.fetion.com.cn" /><presence><basic value="400" desc="" /></presence></args>SIPP
47
+ EOF
48
+ sipc_message.gsub!("\n", "\r\n").chomp!
27
49
  SipcMessage.register_second(@fetion).should == sipc_message
28
50
  end
29
51
 
30
52
  it "should get group list" do
31
53
  @fetion.call = 2
32
- sipc_message = %Q|S fetion.com.cn SIP-C/4.0\r\nF: 730020377\r\nI: 3\r\nQ: 1 S\r\nN: PGGetGroupList\r\nL: 54\r\n\r\n<args><group-list attributes="name;identity" /></args>SIPP|
54
+ sipc_message =<<-EOF
55
+ S fetion.com.cn SIP-C/4.0
56
+ F: 730020377
57
+ I: 3
58
+ Q: 1 S
59
+ N: PGGetGroupList
60
+ L: 54
61
+
62
+ <args><group-list attributes="name;identity" /></args>SIPP
63
+ EOF
64
+ sipc_message.gsub!("\n", "\r\n").chomp!
33
65
  SipcMessage.get_group_list(@fetion).should == sipc_message
34
66
  end
35
67
 
36
68
  it "should presence" do
37
69
  @fetion.call = 3
38
- sipc_message = %Q|SUB fetion.com.cn SIP-C/4.0\r\nF: 730020377\r\nI: 4\r\nQ: 1 SUB\r\nN: PresenceV4\r\nL: 87\r\n\r\n<args><subscription self="v4default;mail-count" buddy="v4default" version="0" /></args>SIPP|
70
+ sipc_message =<<-EOF
71
+ SUB fetion.com.cn SIP-C/4.0
72
+ F: 730020377
73
+ I: 4
74
+ Q: 1 SUB
75
+ N: PresenceV4
76
+ L: 87
77
+
78
+ <args><subscription self="v4default;mail-count" buddy="v4default" version="0" /></args>SIPP
79
+ EOF
80
+ sipc_message.gsub!("\n", "\r\n").chomp!
39
81
  SipcMessage.presence(@fetion).should == sipc_message
40
82
  end
41
83
 
42
84
  it "should get group topic" do
43
85
  @fetion.call = 4
44
- sipc_message = %Q|S fetion.com.cn SIP-C/4.0\r\nF: 730020377\r\nI: 5\r\nQ: 1 S\r\nN: PGGetGroupTopic\r\nL: 27\r\n\r\n<args><topic-list /></args>SIPP|
86
+ sipc_message =<<-EOF
87
+ S fetion.com.cn SIP-C/4.0
88
+ F: 730020377
89
+ I: 5
90
+ Q: 1 S
91
+ N: PGGetGroupTopic
92
+ L: 27
93
+
94
+ <args><topic-list /></args>SIPP
95
+ EOF
96
+ sipc_message.gsub!("\n", "\r\n").chomp!
45
97
  SipcMessage.get_group_topic(@fetion).should == sipc_message
46
98
  end
47
99
 
48
100
  it "should get address list" do
49
101
  @fetion.call = 5
50
- sipc_message = %Q|S fetion.com.cn SIP-C/4.0\r\nF: 730020377\r\nI: 6\r\nQ: 1 S\r\nN: GetAddressListV4\r\nL: 37\r\n\r\n<args><contacts version="0" /></args>SIPP|
102
+ sipc_message =<<-EOF
103
+ S fetion.com.cn SIP-C/4.0
104
+ F: 730020377
105
+ I: 6
106
+ Q: 1 S
107
+ N: GetAddressListV4
108
+ L: 37
109
+
110
+ <args><contacts version="0" /></args>SIPP
111
+ EOF
112
+ sipc_message.gsub!("\n", "\r\n").chomp!
51
113
  SipcMessage.get_address_list(@fetion).should == sipc_message
52
114
  end
53
115
 
54
116
  it "should send cat sms" do
55
117
  @fetion.call = 8
56
- sipc_message = %Q|M fetion.com.cn SIP-C/4.0\r\nF: 730020377\r\nI: 9\r\nQ: 1 M\r\nT: sip:730020377@fetion.com.cn;p=6907\r\nN: SendCatSMS\r\nL: 4\r\n\r\ntestSIPP|
118
+ sipc_message =<<-EOF
119
+ M fetion.com.cn SIP-C/4.0
120
+ F: 730020377
121
+ I: 9
122
+ Q: 1 M
123
+ T: sip:730020377@fetion.com.cn;p=6907
124
+ N: SendCatSMS
125
+ L: 4
126
+
127
+ testSIPP
128
+ EOF
129
+ sipc_message.gsub!("\n", "\r\n").chomp!
57
130
  SipcMessage.send_cat_sms(@fetion, 'sip:730020377@fetion.com.cn;p=6907', 'test').should == sipc_message
58
131
  end
59
132
 
60
133
  it "should send cat msg" do
61
134
  @fetion.call = 8
62
- sipc_message = %Q|M fetion.com.cn SIP-C/4.0\r\nF: 730020377\r\nI: 9\r\nQ: 2 M\r\nT: sip:638993408@fetion.com.cn;p=2242\r\nK: SaveHistory\r\nN: CatMsg\r\nL: 4\r\n\r\ntestSIPP|
135
+ sipc_message =<<-EOF
136
+ M fetion.com.cn SIP-C/4.0
137
+ F: 730020377
138
+ I: 9
139
+ Q: 2 M
140
+ T: sip:638993408@fetion.com.cn;p=2242
141
+ K: SaveHistory
142
+ N: CatMsg
143
+ L: 4
144
+
145
+ testSIPP
146
+ EOF
147
+ sipc_message.gsub!("\n", "\r\n").chomp!
63
148
  SipcMessage.send_cat_msg(@fetion, 'sip:638993408@fetion.com.cn;p=2242', 'test').should == sipc_message
64
149
  end
65
150
 
66
151
  it "should set schedule sms" do
67
152
  @fetion.call = 8
68
- sipc_message = %Q|S fetion.com.cn SIP-C/4.0\r\nF: 730020377\r\nI: 9\r\nQ: 1 S\r\nN: SSSetScheduleCatSms\r\nSV: 1\r\nL: 182\r\n\r\n<args><schedule-sms send-time="2010-05-08 15:50:00" type="0"><message>test</message><receivers><receiver uri="sip:638993408@fetion.com.cn;p=2242" /></receivers></schedule-sms></args>SIPP|
153
+ sipc_message =<<-EOF
154
+ S fetion.com.cn SIP-C/4.0
155
+ F: 730020377
156
+ I: 9
157
+ Q: 1 S
158
+ N: SSSetScheduleCatSms
159
+ SV: 1
160
+ L: 182
161
+
162
+ <args><schedule-sms send-time="2010-05-08 15:50:00" type="0"><message>test</message><receivers><receiver uri="sip:638993408@fetion.com.cn;p=2242" /></receivers></schedule-sms></args>SIPP
163
+ EOF
164
+ sipc_message.gsub!("\n", "\r\n").chomp!
69
165
  SipcMessage.set_schedule_sms(@fetion, ['sip:638993408@fetion.com.cn;p=2242'], 'test', '2010-05-08 15:50:00').should == sipc_message
70
166
  end
71
167
 
72
168
  it "should get contact info" do
73
169
  @fetion.call = 10
74
- sipc_message = %Q|S fetion.com.cn SIP-C/4.0\r\nF: 730020377\r\nI: 11\r\nQ: 1 S\r\nN: GetContactInfoV4\r\nL: 46\r\n\r\n<args><contact uri="tel:15800681507" /></args>SIPP|
170
+ sipc_message =<<-EOF
171
+ S fetion.com.cn SIP-C/4.0
172
+ F: 730020377
173
+ I: 11
174
+ Q: 1 S
175
+ N: GetContactInfoV4
176
+ L: 46
177
+
178
+ <args><contact uri="tel:15800681507" /></args>SIPP
179
+ EOF
180
+ sipc_message.gsub!("\n", "\r\n").chomp!
75
181
  SipcMessage.get_contact_info(@fetion, "tel:15800681507").should == sipc_message
76
182
  end
77
183
 
78
184
  it "should add buddy" do
79
185
  @fetion.call = 9
80
186
  @fetion.instance_variable_set(:@nickname, 'flyerhzm')
81
- sipc_message = %Q|S fetion.com.cn SIP-C/4.0\r\nF: 730020377\r\nI: 10\r\nQ: 1 S\r\nN: AddBuddyV4\r\nL: 175\r\n\r\n<args><contacts><buddies><buddy uri="tel:13634102006" buddy-lists="" desc="flyerhzm" expose-mobile-no="1" expose-name="1" addbuddy-phrase-id="0" /></buddies></contacts></args>SIPP|
187
+ sipc_message =<<-EOF
188
+ S fetion.com.cn SIP-C/4.0
189
+ F: 730020377
190
+ I: 10
191
+ Q: 1 S
192
+ N: AddBuddyV4
193
+ L: 175
194
+
195
+ <args><contacts><buddies><buddy uri="tel:13634102006" buddy-lists="" desc="flyerhzm" expose-mobile-no="1" expose-name="1" addbuddy-phrase-id="0" /></buddies></contacts></args>SIPP
196
+ EOF
197
+ sipc_message.gsub!("\n", "\r\n").chomp!
82
198
  SipcMessage.add_buddy(@fetion, :friend_mobile => "13634102006").should == sipc_message
83
199
 
84
200
  @fetion.call = 9
85
- sipc_message = %Q|S fetion.com.cn SIP-C/4.0\r\nF: 730020377\r\nI: 10\r\nQ: 1 S\r\nN: AddBuddyV4\r\nL: 136\r\n\r\n<args><contacts><buddies><buddy uri="sip:638993408" buddy-lists="" desc="flyerhzm" addbuddy-phrase-id="0" /></buddies></contacts></args>SIPP|
201
+ sipc_message =<<-EOF
202
+ S fetion.com.cn SIP-C/4.0
203
+ F: 730020377
204
+ I: 10
205
+ Q: 1 S
206
+ N: AddBuddyV4
207
+ L: 136
208
+
209
+ <args><contacts><buddies><buddy uri="sip:638993408" buddy-lists="" desc="flyerhzm" addbuddy-phrase-id="0" /></buddies></contacts></args>SIPP
210
+ EOF
211
+ sipc_message.gsub!("\n", "\r\n").chomp!
86
212
  SipcMessage.add_buddy(@fetion, :friend_sip => "638993408").should == sipc_message
87
213
  end
88
214
 
215
+ it "should create session" do
216
+ http_response_body =<<-EOF
217
+ I 730020377 SIP-C/4.0
218
+ F: sip:638993408@fetion.com.cn;p=2242
219
+ I: -13
220
+ K: text/plain
221
+ K: text/html-fragment
222
+ K: multiparty
223
+ K: nudge
224
+ Q: 14 I
225
+ L: 21
226
+
227
+ s=session
228
+ m=message SIPP
229
+ EOF
230
+ http_response_body.gsub!("\n", "\r\n").chomp!
231
+ last_sipc_response = SipcMessage.sipc_response(http_response_body, @fetion)
232
+ sipc_message = %Q|SIP-C/4.0 200 OK\r\nI: -13\r\nQ: 14 I\r\nF: sip:638993408@fetion.com.cn;p=2242\r\nK: text/plain\r\nK: text/html-fragment\r\nK: multiparty\r\nK: nudge\r\nL: 129\r\n\r\nv=0\r\no=-0 0 IN 127.0.0.1:8001\r\ns=session\r\nc=IN IP4 127.0.0.1:8001\r\nt=0 0\r\nm=message 8001 sip sip:730020377@fetion.com.cn;p=6907\r\nSIPP|
233
+ SipcMessage.create_session(@fetion, last_sipc_response).should == sipc_message
234
+ end
235
+
236
+ it "shoud session connected" do
237
+ http_response_body =<<-EOF
238
+ O 730020377 SIP-C/4.0
239
+ I: -13
240
+ Q: 2 O
241
+ K: text/plain
242
+ K: text/html-fragment
243
+ K: multiparty
244
+ K: nudge
245
+ F: sip:638993408@fetion.com.cn;p=2242
246
+
247
+ A 730020377 SIP-C/4.0
248
+ F: sip:638993408@fetion.com.cn;p=2242
249
+ I: -13
250
+ Q: 14 A
251
+
252
+ SIPP
253
+ EOF
254
+ http_response_body.gsub!("\n", "\r\n").chomp!
255
+ last_sipc_response = SipcMessage.sipc_response(http_response_body, @fetion)
256
+ sipc_message =<<-EOF
257
+ SIP-C/4.0 200 OK
258
+ F: sip:638993408@fetion.com.cn;p=2242
259
+ I: -13
260
+ Q: 2 O
261
+ K: text/html-fragment
262
+ K: text/plain
263
+
264
+ SIPP
265
+ EOF
266
+ sipc_message.gsub!("\n", "\r\n").chomp!
267
+ SipcMessage.session_connected(@fetion, last_sipc_response).should == sipc_message
268
+ end
269
+
270
+ it "should msg_received" do
271
+ http_response_body =<<-EOF
272
+ M 730020377 SIP-C/4.0
273
+ I: -13
274
+ Q: 4 M
275
+ F: sip:638993408@fetion.com.cn;p=2242
276
+ C: text/html-fragment
277
+ K: SaveHistory
278
+ L: 4
279
+ D: Sun, 16 May 2010 02:16:00 GMT
280
+ XI: 0dbdc4e81bff425dbcf8b591b497fe94
281
+
282
+ testSIPP
283
+ EOF
284
+ http_response_body.gsub!("\n", "\r\n").chomp!
285
+ sipc_message =<<-EOF
286
+ SIP-C/4.0 200 OK
287
+ F: sip:638993408@fetion.com.cn;p=2242
288
+ I: -13
289
+ Q: 4 M
290
+
291
+ SIPP
292
+ EOF
293
+ sipc_message.gsub!("\n", "\r\n").chomp!
294
+ SipcMessage.msg_received(@fetion, http_response_body).should == sipc_message
295
+ end
296
+
297
+ it "should close session" do
298
+ @fetion.call = 5
299
+ sipc_message =<<-EOF
300
+ B fetion.com.cn SIP-C/4.0
301
+ F: 730020377
302
+ I: 6
303
+ Q: 2 B
304
+ T: sip:638993408@fetion.com.cn;p=2242
305
+
306
+ SIPP
307
+ EOF
308
+ sipc_message.gsub!("\n", "\r\n").chomp!
309
+ SipcMessage.close_session(@fetion, "638993408@fetion.com.cn;p=2242").should == sipc_message
310
+ end
311
+
89
312
  it "should logout" do
90
- sipc_message = %Q|R fetion.com.cn SIP-C/4.0\r\nF: 730020377\r\nI: 1\r\nQ: 3 R\r\nX: 0\r\n\r\nSIPP|
313
+ sipc_message =<<-EOF
314
+ R fetion.com.cn SIP-C/4.0
315
+ F: 730020377
316
+ I: 1
317
+ Q: 3 R
318
+ X: 0
319
+
320
+ SIPP
321
+ EOF
322
+ sipc_message.gsub!("\n", "\r\n").chomp!
91
323
  SipcMessage.logout(@fetion).should == sipc_message
92
324
  end
93
325
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfetion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.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: 2010-05-15 00:00:00 -06:00
12
+ date: 2010-05-16 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency