rfetion 0.5.3 → 0.5.4
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/VERSION +1 -1
- data/lib/rfetion/fetion.rb +49 -38
- data/lib/rfetion/sipc_message.rb +8 -3
- data/rfetion.gemspec +2 -2
- data/spec/rfetion/fetion_spec.rb +9 -4
- data/spec/rfetion/sipc_message_spec.rb +39 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.4
|
data/lib/rfetion/fetion.rb
CHANGED
@@ -8,7 +8,7 @@ require 'openssl'
|
|
8
8
|
require 'logger'
|
9
9
|
|
10
10
|
class Fetion
|
11
|
-
attr_accessor :mobile_no, :sid, :password, :seq, :ssic, :guid, :uri
|
11
|
+
attr_accessor :mobile_no, :sid, :password, :call, :seq, :alive, :ssic, :guid, :uri
|
12
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'
|
@@ -51,9 +51,9 @@ class Fetion
|
|
51
51
|
def Fetion.keep_alive(options)
|
52
52
|
Fetion.open(options) do
|
53
53
|
get_contacts
|
54
|
-
|
54
|
+
pulse
|
55
55
|
sleep(15)
|
56
|
-
|
56
|
+
pulse
|
57
57
|
p receives
|
58
58
|
end
|
59
59
|
end
|
@@ -284,6 +284,14 @@ class Fetion
|
|
284
284
|
@logger.info "fetion keep alive success"
|
285
285
|
end
|
286
286
|
|
287
|
+
def pulse(expected=SipcMessage::OK)
|
288
|
+
@logger.info "fetion pulse"
|
289
|
+
|
290
|
+
curl_exec(SIPP, next_url, expected)
|
291
|
+
|
292
|
+
@logger.info "fetion pulse success"
|
293
|
+
end
|
294
|
+
|
287
295
|
def logout
|
288
296
|
@logger.info "fetion logout"
|
289
297
|
|
@@ -318,6 +326,14 @@ class Fetion
|
|
318
326
|
@logger.info "fetion msg received success"
|
319
327
|
end
|
320
328
|
|
329
|
+
def close_session
|
330
|
+
@logger.info "fetion close_session"
|
331
|
+
|
332
|
+
curl_exec(SipcMessage.close_session(self))
|
333
|
+
|
334
|
+
@logger.info "fetion close_session success"
|
335
|
+
end
|
336
|
+
|
321
337
|
def parse_ssic(response)
|
322
338
|
raise Fetion::LoginException.new('Fetion Error: Login failed.') unless Net::HTTPSuccess === response
|
323
339
|
raise Fetion::LoginException.new('Fetion Error: No ssic found in cookie.') unless response['set-cookie'] =~ /ssic=(.*);/
|
@@ -345,10 +361,6 @@ class Fetion
|
|
345
361
|
@logger.debug "sid: " + @sid
|
346
362
|
end
|
347
363
|
|
348
|
-
def pulse(expected=SipcMessage::OK)
|
349
|
-
curl_exec(SIPP, next_url, expected)
|
350
|
-
end
|
351
|
-
|
352
364
|
def curl_exec(body='', url=next_url, expected=SipcMessage::OK)
|
353
365
|
@logger.debug "fetion curl exec"
|
354
366
|
@logger.debug "url: #{url}"
|
@@ -381,37 +393,10 @@ class Fetion
|
|
381
393
|
@logger.debug "key: #{@key}"
|
382
394
|
@logger.debug "signature: #{@signature}"
|
383
395
|
@logger.debug "response: #{@response}"
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
else
|
389
|
-
response.body.scan(%r{<results>.*?</results>}).each do |results|
|
390
|
-
doc = Nokogiri::XML(results)
|
391
|
-
doc.root.xpath("/results/user-info/personal").each do |personal_element|
|
392
|
-
@nickname = personal_element['nickname']
|
393
|
-
@logger.debug "nickname: #@nickname"
|
394
|
-
end
|
395
|
-
doc.root.xpath("/results/user-info/contact-list/buddy-lists/buddy-list").each do |buddy_list|
|
396
|
-
@buddy_lists << Fetion::BuddyList.parse(buddy_list)
|
397
|
-
end
|
398
|
-
doc.root.xpath("/results/user-info/contact-list/buddies/b").each do |buddy|
|
399
|
-
@buddies << {:uri => buddy["u"]}
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
response.body.scan(%r{<events>.*?</events>}).each do |events|
|
404
|
-
doc = Nokogiri::XML(events)
|
405
|
-
doc.root.xpath("/events/event[@type='PresenceChanged']/contacts/c").each do |c|
|
406
|
-
contact = contacts.find {|contact| contact.id == c['id']}
|
407
|
-
if contact
|
408
|
-
contact.status = c.children.first['b']
|
409
|
-
else
|
410
|
-
@contacts << Fetion::Contact.parse(c) unless c['id'] == @user_id
|
411
|
-
end
|
412
|
-
end
|
413
|
-
end
|
414
|
-
|
396
|
+
end
|
397
|
+
create_session(sipc_response) if sipc_response.contain?('I')
|
398
|
+
session_connected(sipc_response) if sipc_response.contain?('O')
|
399
|
+
if sipc_response.contain?('M')
|
415
400
|
receive_messages = response.body.scan(%r{M #{@sid} SIP-C/4.0.*?BN}m)
|
416
401
|
receive_messages = response.body.scan(%r{M #{@sid} SIP-C/4.0.*?SIPP\r?\n?$}m) if receive_messages.empty?
|
417
402
|
receive_messages.each do |message_response|
|
@@ -429,6 +414,32 @@ class Fetion
|
|
429
414
|
msg_received(message_response)
|
430
415
|
end
|
431
416
|
end
|
417
|
+
|
418
|
+
response.body.scan(%r{<results>.*?</results>}).each do |results|
|
419
|
+
doc = Nokogiri::XML(results)
|
420
|
+
doc.root.xpath("/results/user-info/personal").each do |personal_element|
|
421
|
+
@nickname = personal_element['nickname']
|
422
|
+
@logger.debug "nickname: #@nickname"
|
423
|
+
end
|
424
|
+
doc.root.xpath("/results/user-info/contact-list/buddy-lists/buddy-list").each do |buddy_list|
|
425
|
+
@buddy_lists << Fetion::BuddyList.parse(buddy_list)
|
426
|
+
end
|
427
|
+
doc.root.xpath("/results/user-info/contact-list/buddies/b").each do |buddy|
|
428
|
+
@buddies << {:uri => buddy["u"]}
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
response.body.scan(%r{<events>.*?</events>}).each do |events|
|
433
|
+
doc = Nokogiri::XML(events)
|
434
|
+
doc.root.xpath("/events/event[@type='PresenceChanged']/contacts/c").each do |c|
|
435
|
+
contact = contacts.find {|contact| contact.id == c['id']}
|
436
|
+
if contact
|
437
|
+
contact.status = c.children.first['b']
|
438
|
+
else
|
439
|
+
@contacts << Fetion::Contact.parse(c) unless c['id'] == @user_id
|
440
|
+
end
|
441
|
+
end
|
442
|
+
end
|
432
443
|
end
|
433
444
|
sipc_response
|
434
445
|
end
|
data/lib/rfetion/sipc_message.rb
CHANGED
@@ -2,12 +2,12 @@ require 'guid'
|
|
2
2
|
|
3
3
|
class SipcMessage
|
4
4
|
def self.register_first(fetion)
|
5
|
-
sipc_create(:command => 'R', :F => fetion.sid, :I => 1, :Q =>
|
5
|
+
sipc_create(:command => 'R', :F => fetion.sid, :I => 1, :Q => "#{fetion.next_alive} R", :CN => ::Guid.new.hexdigest.upcase, :CL => %Q|type="pc" ,version="#{Fetion::VERSION}"|, :with_l => false)
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.register_second(fetion)
|
9
9
|
body = %Q|<args><device machine-code="B04B5DA2F5F1B8D01A76C0EBC841414C" /><caps value="ff" /><events value="7f" /><user-info mobile-no="#{fetion.mobile_no}" user-id="#{fetion.user_id}"><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>|
|
10
|
-
sipc_create(:command => 'R', :F => fetion.sid, :I => 1, :Q =>
|
10
|
+
sipc_create(:command => 'R', :F => fetion.sid, :I => 1, :Q => "#{fetion.next_alive} R", :A => %Q|Digest response="#{fetion.response}",algorithm="SHA1-sess-v4"|, :AK => 'ak-value', :body => body)
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.get_group_list(fetion)
|
@@ -55,7 +55,7 @@ class SipcMessage
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def self.logout(fetion)
|
58
|
-
sipc_create(:command => 'R', :F => fetion.sid, :I => 1, :Q =>
|
58
|
+
sipc_create(:command => 'R', :F => fetion.sid, :I => 1, :Q => "#{fetion.next_alive} R", :X => 0, :with_l => false)
|
59
59
|
end
|
60
60
|
|
61
61
|
def self.create_session(fetion, last_sipc_response)
|
@@ -105,6 +105,11 @@ class SipcMessage
|
|
105
105
|
sipc_create(:command => 'B', :F => fetion.sid, :I => fetion.next_call, :Q => '2 B', :T => "sip:#{receiver_uri}", :with_l => false)
|
106
106
|
end
|
107
107
|
|
108
|
+
def self.keep_alive(fetion)
|
109
|
+
body = %Q|<args><credentials domains="fetion.com.cn;m161.com.cn;www.ikuwa.cn;games.fetion.com.cn" /></args>|
|
110
|
+
sipc_create(:command => 'R', :F => fetion.sid, :I => 1, :Q => "#{fetion.next_alive} R", :N => 'KeepAlive', :body => body)
|
111
|
+
end
|
112
|
+
|
108
113
|
def self.sipc_response(http_response_body, fetion)
|
109
114
|
return if http_response_body == Fetion::SIPP
|
110
115
|
|
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.
|
8
|
+
s.version = "0.5.4"
|
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-
|
12
|
+
s.date = %q{2010-05-17}
|
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"]
|
data/spec/rfetion/fetion_spec.rb
CHANGED
@@ -495,7 +495,7 @@ EOF
|
|
495
495
|
end
|
496
496
|
end
|
497
497
|
|
498
|
-
describe "
|
498
|
+
describe "pulse" do
|
499
499
|
before :each do
|
500
500
|
@fetion.instance_variable_set(:@seq, 10)
|
501
501
|
@fetion.instance_variable_set(:@sid, "730020377")
|
@@ -516,7 +516,7 @@ Q: 11 BN
|
|
516
516
|
EOF
|
517
517
|
response_body.gsub!("\n", "\r\n")
|
518
518
|
FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=11", :body => response_body)
|
519
|
-
@fetion.
|
519
|
+
@fetion.pulse
|
520
520
|
@fetion.contacts.find {|contact| contact.id == '295098062'}.status.should == "400"
|
521
521
|
end
|
522
522
|
|
@@ -574,7 +574,7 @@ EOF
|
|
574
574
|
response_body.gsub!("\n", "\r\n")
|
575
575
|
FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=14", :body => response_body)
|
576
576
|
FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=15", :body => "SIPP")
|
577
|
-
@fetion.
|
577
|
+
@fetion.pulse
|
578
578
|
@fetion.receives.collect {|r| r.sip}.should == ["638993408@fetion.com.cn;p=2242"]
|
579
579
|
@fetion.receives.collect {|r| r.sent_at}.should == [Time.parse("Sun, 16 May 2010 02:16:00 GMT")]
|
580
580
|
@fetion.receives.collect {|r| r.text}.should == ["test"]
|
@@ -632,7 +632,7 @@ EOF
|
|
632
632
|
response_body.gsub!("\n", "\r\n")
|
633
633
|
FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=13", :body => response_body)
|
634
634
|
FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=14", :body => "SIPP")
|
635
|
-
@fetion.
|
635
|
+
@fetion.pulse
|
636
636
|
@fetion.receives.collect {|r| r.sip}.should == ["638993408@fetion.com.cn;p=2242"]
|
637
637
|
@fetion.receives.collect {|r| r.sent_at}.should == [Time.parse("Sun, 16 May 2010 02:16:00 GMT")]
|
638
638
|
@fetion.receives.collect {|r| r.text}.should == ["test"]
|
@@ -654,6 +654,11 @@ testtesttestSIPP
|
|
654
654
|
EOF
|
655
655
|
response_body.gsub!("\n", "\r\n")
|
656
656
|
FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=11", :body => response_body)
|
657
|
+
FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=12", :body => "SIPP")
|
658
|
+
@fetion.pulse
|
659
|
+
@fetion.receives.collect {|r| r.sip}.should == ["638993408@fetion.com.cn;p=2242"]
|
660
|
+
@fetion.receives.collect {|r| r.sent_at}.should == [Time.parse("Tue, 11 May 2010 15:18:56 GMT")]
|
661
|
+
@fetion.receives.collect {|r| r.text}.should == ["testtesttest"]
|
657
662
|
end
|
658
663
|
end
|
659
664
|
end
|
@@ -19,6 +19,7 @@ describe SipcMessage do
|
|
19
19
|
Guid.stubs(:new).returns(guid)
|
20
20
|
guid.stubs(:hexdigest).returns(hexdigest)
|
21
21
|
hexdigest.stubs(:upcase).returns("19D28D4978125CAA4F6E54277BA7D9EF")
|
22
|
+
@fetion.alive = 0
|
22
23
|
sipc_message =<<-EOF
|
23
24
|
R fetion.com.cn SIP-C/4.0
|
24
25
|
F: 730020377
|
@@ -34,6 +35,7 @@ EOF
|
|
34
35
|
end
|
35
36
|
|
36
37
|
it "should get register_second" do
|
38
|
+
@fetion.alive = 1
|
37
39
|
sipc_message =<<-EOF
|
38
40
|
R fetion.com.cn SIP-C/4.0
|
39
41
|
F: 730020377
|
@@ -229,7 +231,26 @@ m=message SIPP
|
|
229
231
|
EOF
|
230
232
|
http_response_body.gsub!("\n", "\r\n").chomp!
|
231
233
|
last_sipc_response = SipcMessage.sipc_response(http_response_body, @fetion)
|
232
|
-
sipc_message
|
234
|
+
sipc_message =<<-EOF
|
235
|
+
SIP-C/4.0 200 OK
|
236
|
+
I: -13
|
237
|
+
Q: 14 I
|
238
|
+
F: sip:638993408@fetion.com.cn;p=2242
|
239
|
+
K: text/plain
|
240
|
+
K: text/html-fragment
|
241
|
+
K: multiparty
|
242
|
+
K: nudge
|
243
|
+
L: 129
|
244
|
+
|
245
|
+
v=0
|
246
|
+
o=-0 0 IN 127.0.0.1:8001
|
247
|
+
s=session
|
248
|
+
c=IN IP4 127.0.0.1:8001
|
249
|
+
t=0 0
|
250
|
+
m=message 8001 sip sip:730020377@fetion.com.cn;p=6907
|
251
|
+
SIPP
|
252
|
+
EOF
|
253
|
+
sipc_message.gsub!("\n", "\r\n").chomp!
|
233
254
|
SipcMessage.create_session(@fetion, last_sipc_response).should == sipc_message
|
234
255
|
end
|
235
256
|
|
@@ -294,6 +315,22 @@ EOF
|
|
294
315
|
SipcMessage.msg_received(@fetion, http_response_body).should == sipc_message
|
295
316
|
end
|
296
317
|
|
318
|
+
it "should keep alive" do
|
319
|
+
@fetion.alive = 3
|
320
|
+
sipc_message =<<-EOF
|
321
|
+
R fetion.com.cn SIP-C/4.0
|
322
|
+
F: 730020377
|
323
|
+
I: 1
|
324
|
+
Q: 4 R
|
325
|
+
N: KeepAlive
|
326
|
+
L: 97
|
327
|
+
|
328
|
+
<args><credentials domains="fetion.com.cn;m161.com.cn;www.ikuwa.cn;games.fetion.com.cn" /></args>SIPP
|
329
|
+
EOF
|
330
|
+
sipc_message.gsub!("\n", "\r\n").chomp!
|
331
|
+
SipcMessage.keep_alive(@fetion).should == sipc_message
|
332
|
+
end
|
333
|
+
|
297
334
|
it "should close session" do
|
298
335
|
@fetion.call = 5
|
299
336
|
sipc_message =<<-EOF
|
@@ -310,6 +347,7 @@ EOF
|
|
310
347
|
end
|
311
348
|
|
312
349
|
it "should logout" do
|
350
|
+
@fetion.alive = 2
|
313
351
|
sipc_message =<<-EOF
|
314
352
|
R fetion.com.cn SIP-C/4.0
|
315
353
|
F: 730020377
|
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.
|
4
|
+
version: 0.5.4
|
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-
|
12
|
+
date: 2010-05-17 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|