rfetion 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,104 @@
1
+ require 'guid'
2
+
3
+ class SipcMessage
4
+ def self.register_first(fetion)
5
+ sipc_create(:command => 'R', :F => fetion.sid, :I => 1, :Q => '1 R', :CN => ::Guid.new.hexdigest.upcase, :CL => %Q|type="pc" ,version="#{Fetion::VERSION}"|, :with_l => false)
6
+ end
7
+
8
+ def self.register_second(fetion)
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 => '2 R', :A => %Q|Digest response="#{fetion.response}",algorithm="SHA1-sess-v4"|, :AK => 'ak-value', :body => body)
11
+ end
12
+
13
+ def self.get_group_list(fetion)
14
+ body = %Q|<args><group-list attributes="name;identity" /></args>|
15
+ sipc_create(:command => 'S', :F => fetion.sid, :I => fetion.next_call, :Q => '1 S', :N => 'PGGetGroupList', :body => body)
16
+ end
17
+
18
+ def self.presence(fetion)
19
+ body = %Q|<args><subscription self="v4default;mail-count" buddy="v4default" version="0" /></args>|
20
+ sipc_create(:command => 'SUB', :F => fetion.sid, :I => fetion.next_call, :Q => '1 SUB', :N => 'PresenceV4', :body => body)
21
+ end
22
+
23
+ def self.get_group_topic(fetion)
24
+ body = %Q|<args><topic-list /></args>|
25
+ sipc_create(:command => 'S', :F => fetion.sid, :I => fetion.next_call, :Q => '1 S', :N => 'PGGetGroupTopic', :body => body)
26
+ end
27
+
28
+ def self.get_address_list(fetion)
29
+ body = %Q|<args><contacts version="0" /></args>|
30
+ sipc_create(:command => 'S', :F => fetion.sid, :I => fetion.next_call, :Q => '1 S', :N => 'GetAddressListV4', :body => body)
31
+ end
32
+
33
+ def self.send_cat_sms(fetion, receiver, content)
34
+ sipc_create(:command => 'M', :F => fetion.sid, :I => fetion.next_call, :Q => '1 M', :T => receiver, :N => 'SendCatSMS', :body => content)
35
+ end
36
+
37
+ def self.send_msg(fetion, receiver, content)
38
+ sipc_create(:command => 'M', :F => fetion.sid, :I => fetion.next_call, :Q => '3 M', :T => receiver, :K => 'SaveHistory', :body => content)
39
+ end
40
+
41
+ def self.set_schedule_sms(fetion, receivers, content, time)
42
+ receivers_str = receivers.collect { |receiver| %Q[<receiver uri="#{receiver}" />] }.join('')
43
+ body = %Q|<args><schedule-sms send-time="#{time}" type="0"><message>test</message><receivers>#{receivers_str}</receivers></schedule-sms></args>|
44
+ sipc_create(:command => 'S', :F => fetion.sid, :I => fetion.next_call, :Q => '1 S', :N => 'SSSetScheduleCatSms', :SV => '1', :body => body)
45
+ end
46
+
47
+ def self.add_buddy(fetion, options)
48
+ body = options[:friend_mobile] ? %Q|<args><contacts><buddies><buddy uri="tel:#{options[:friend_mobile]}" buddy-lists="" desc="#{fetion.nickname}" expose-mobile-no="1" expose-name="1" addbuddy-phrase-id="0" /></buddies></contacts></args>| : %Q|<args><contacts><buddies><buddy uri="sip:#{options[:friend_sip]}" buddy-lists="" desc="#{fetion.nickname}" addbuddy-phrase-id="0" /></buddies></contacts></args>|
49
+ sipc_create(:command => 'S', :F => fetion.sid, :I => fetion.next_call, :Q => '1 S', :N => 'AddBuddyV4', :body => body)
50
+ end
51
+
52
+ def self.get_contact_info(fetion, mobile_no)
53
+ body = %Q|<args><contact uri="tel:#{mobile_no}" /></args>|
54
+ sipc_create(:command => 'S', :F => fetion.sid, :I => fetion.next_call, :Q => '1 S', :N => 'GetContactInfoV4', :body => body)
55
+ end
56
+
57
+ def self.logout(fetion)
58
+ sipc_create(:command => 'R', :F => fetion.sid, :I => 1, :Q => '3 R', :X => 0, :with_l => false)
59
+ end
60
+
61
+ # command one of 'R', 'S'
62
+ # with_l display L or not
63
+ # body sipc body
64
+ def self.sipc_create(options)
65
+ options = {:body => '', :with_l => true}.merge(options)
66
+ body = options.delete(:body)
67
+ with_l = options.delete(:with_l)
68
+
69
+ sorted_key = [:F, :I, :Q, :CN, :CL, :A, :AK, :X, :T, :N, :K, :SV]
70
+ sipc = "#{options.delete(:command)} fetion.com.cn SIP-C/4.0\r\n"
71
+ sorted_key.each {|k| sipc += "#{k}: #{options[k]}\r\n" if options[k]}
72
+ sipc += "L: #{body == '' ? 4 : body.size}\r\n" if with_l
73
+ sipc += "\r\n#{body}#{Fetion::SIPP}"
74
+ sipc
75
+ end
76
+
77
+ def self.sipc_response(http_response_body)
78
+ sipc, code, message = http_response_body.to_a.first.split(' ')
79
+ RESPONSES[code.to_i].new(code, message)
80
+ end
81
+
82
+ class Response
83
+ attr_reader :code, :message
84
+
85
+ def initialize(code, message)
86
+ @code = code
87
+ @message = message
88
+ end
89
+
90
+ def to_s
91
+ "#@code #@message"
92
+ end
93
+ end
94
+
95
+ class OK < Response; end
96
+ class NotFound < Response; end
97
+ class ExtentionRequired < Response; end
98
+
99
+ RESPONSES = {
100
+ 200 => SipcMessage::OK,
101
+ 404 => SipcMessage::NotFound,
102
+ 421 => SipcMessage::ExtentionRequired
103
+ }
104
+ end
data/lib/rfetion.rb CHANGED
@@ -1,2 +1,4 @@
1
- require File.dirname(__FILE__) + '/rfetion/fetion'
1
+ require 'rubygems'
2
2
  require File.dirname(__FILE__) + '/rfetion/contact'
3
+ require File.dirname(__FILE__) + '/rfetion/sipc_message'
4
+ require File.dirname(__FILE__) + '/rfetion/fetion'
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.4.8"
8
+ s.version = "0.5.0"
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-04-27}
12
+ s.date = %q{2010-05-09}
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"]
@@ -25,13 +25,23 @@ Gem::Specification.new do |s|
25
25
  "lib/rfetion/command.rb",
26
26
  "lib/rfetion/contact.rb",
27
27
  "lib/rfetion/fetion.rb",
28
- "rfetion.gemspec"
28
+ "lib/rfetion/sipc_message.rb",
29
+ "rfetion.gemspec",
30
+ "spec/rfetion/fetion_spec.rb",
31
+ "spec/rfetion/sipc_message_spec.rb",
32
+ "spec/spec.opts",
33
+ "spec/spec_helper.rb"
29
34
  ]
30
35
  s.homepage = %q{http://github.com/flyerhzm/rfetion}
31
36
  s.rdoc_options = ["--charset=UTF-8"]
32
37
  s.require_paths = ["lib"]
33
38
  s.rubygems_version = %q{1.3.5}
34
39
  s.summary = %q{rfetion is a ruby gem for China Mobile fetion service that you can send SMS free.}
40
+ s.test_files = [
41
+ "spec/rfetion/fetion_spec.rb",
42
+ "spec/rfetion/sipc_message_spec.rb",
43
+ "spec/spec_helper.rb"
44
+ ]
35
45
 
36
46
  if s.respond_to? :specification_version then
37
47
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -0,0 +1,369 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe Fetion do
4
+ class Fetion
5
+ attr_accessor :mobile_no, :sid, :password, :status_code, :user_status, :user_id, :ssic, :nonce, :key, :signature, :response
6
+ end
7
+
8
+ before :each do
9
+ @fetion = Fetion.new
10
+ end
11
+
12
+ after :each do
13
+ FakeWeb.clean_registry
14
+ end
15
+
16
+ describe "login" do
17
+ it "should login by mobile no" do
18
+ @fetion.mobile_no = '15800681509'
19
+ @fetion.password = 'password'
20
+ FakeWeb.register_uri(:get, 'https://uid.fetion.com.cn/ssiportal/SSIAppSignInV4.aspx?mobileno=15800681509&domains=fetion.com.cn;m161.com.cn;www.ikuwa.cn&v4digest-type=1&v4digest=79cd56b93f21298dc8ae9d26de1258e3d6ce85a7', :body => %Q|<?xml version="1.0" encoding="utf-8" ?><results status-code="200"><user uri="sip:730020377@fetion.com.cn;p=6907" mobile-no="15800681509" user-status="101" user-id="390937727"><credentials><credential domain="fetion.com.cn" c="CBIOAAAm+FiuQgpcnFi+B4PZgtvTLcLwrzk84mf5XsP9hnneRVyMvEFuPpvTyfV2FFZfhJrCoiLYptvuSd9M95fwTUj4jRE6NuiE43EPl220u/chMyebsSbsUDxSjuJh1hXV76sAAA==" /><credential domain="m161.com.cn" c="CBAOAADowH3pYcBkGIkxcH56EXCIPEJmZ2EXyUKNoOM2xqaJ33i9d5fKaMYY9N7irpMmffobHQws5Eekiz/h+v9nuc3v6zzO8Pd0lIXzutXwzXCROw==" /><credential domain="www.ikuwa.cn" c="ChAOAABbuQDP66jvw7EVpUEjmgWcX/m+qx1KjApplisfSwro1Wp7Aj6Ngu6goEMEx4SHBj+ID4pf+shcudvrfr4C2fUJnmwovu4HZ3+Y1MvS96TtUQ==" /></credentials></user></results>|, :set_cookie => %Q|ssic=DhIOAADVEY68pV4EcRHsJ/GIIeltaYJsYJR2pj7b2+hCYLtgUd2j2mFaOqoqR98S3dm5pPH9t7W1yH5Cp/lVRP6VTwpLVvwxhhvj8qDz/p8rrW/Ljor6P4ZQKUZYz80JHjMt8R4AAA==; path=/|)
21
+ @fetion.login
22
+
23
+ @fetion.status_code.should == "200"
24
+ @fetion.user_status.should == "101"
25
+ @fetion.mobile_no.should == "15800681509"
26
+ @fetion.user_id.should == "390937727"
27
+ @fetion.sid.should == "730020377"
28
+ @fetion.ssic.should == "DhIOAADVEY68pV4EcRHsJ/GIIeltaYJsYJR2pj7b2+hCYLtgUd2j2mFaOqoqR98S3dm5pPH9t7W1yH5Cp/lVRP6VTwpLVvwxhhvj8qDz/p8rrW/Ljor6P4ZQKUZYz80JHjMt8R4AAA=="
29
+ end
30
+
31
+ it "should login by sid" do
32
+ @fetion.sid = "730020377"
33
+ @fetion.password = 'password'
34
+ FakeWeb.register_uri(:get, 'https://uid.fetion.com.cn/ssiportal/SSIAppSignInV4.aspx?sid=730020377&domains=fetion.com.cn;m161.com.cn;www.ikuwa.cn&v4digest-type=1&v4digest=79cd56b93f21298dc8ae9d26de1258e3d6ce85a7', :body => %Q|<?xml version="1.0" encoding="utf-8" ?><results status-code="200"><user uri="sip:730020377@fetion.com.cn;p=6907" mobile-no="15800681509" user-status="101" user-id="390937727"><credentials><credential domain="fetion.com.cn" c="CBIOAAAm+FiuQgpcnFi+B4PZgtvTLcLwrzk84mf5XsP9hnneRVyMvEFuPpvTyfV2FFZfhJrCoiLYptvuSd9M95fwTUj4jRE6NuiE43EPl220u/chMyebsSbsUDxSjuJh1hXV76sAAA==" /><credential domain="m161.com.cn" c="CBAOAADowH3pYcBkGIkxcH56EXCIPEJmZ2EXyUKNoOM2xqaJ33i9d5fKaMYY9N7irpMmffobHQws5Eekiz/h+v9nuc3v6zzO8Pd0lIXzutXwzXCROw==" /><credential domain="www.ikuwa.cn" c="ChAOAABbuQDP66jvw7EVpUEjmgWcX/m+qx1KjApplisfSwro1Wp7Aj6Ngu6goEMEx4SHBj+ID4pf+shcudvrfr4C2fUJnmwovu4HZ3+Y1MvS96TtUQ==" /></credentials></user></results>|, :set_cookie => %Q|ssic=DhIOAADVEY68pV4EcRHsJ/GIIeltaYJsYJR2pj7b2+hCYLtgUd2j2mFaOqoqR98S3dm5pPH9t7W1yH5Cp/lVRP6VTwpLVvwxhhvj8qDz/p8rrW/Ljor6P4ZQKUZYz80JHjMt8R4AAA==; path=/|)
35
+ @fetion.login
36
+
37
+ @fetion.status_code.should == "200"
38
+ @fetion.user_status.should == "101"
39
+ @fetion.mobile_no.should == "15800681509"
40
+ @fetion.user_id.should == "390937727"
41
+ @fetion.sid.should == "730020377"
42
+ @fetion.ssic.should == "DhIOAADVEY68pV4EcRHsJ/GIIeltaYJsYJR2pj7b2+hCYLtgUd2j2mFaOqoqR98S3dm5pPH9t7W1yH5Cp/lVRP6VTwpLVvwxhhvj8qDz/p8rrW/Ljor6P4ZQKUZYz80JHjMt8R4AAA=="
43
+ end
44
+
45
+ it "should get login exception without ssic" do
46
+ @fetion.mobile_no = '15800681509'
47
+ @fetion.password = 'password'
48
+ FakeWeb.register_uri(:get, 'https://uid.fetion.com.cn/ssiportal/SSIAppSignInV4.aspx?mobileno=15800681509&domains=fetion.com.cn;m161.com.cn;www.ikuwa.cn&v4digest-type=1&v4digest=79cd56b93f21298dc8ae9d26de1258e3d6ce85a7', :body => %Q|<?xml version="1.0" encoding="utf-8" ?><results status-code="200"><user uri="sip:730020377@fetion.com.cn;p=6907" mobile-no="15800681509" user-status="101" user-id="390937727"><credentials><credential domain="fetion.com.cn" c="CBIOAAAm+FiuQgpcnFi+B4PZgtvTLcLwrzk84mf5XsP9hnneRVyMvEFuPpvTyfV2FFZfhJrCoiLYptvuSd9M95fwTUj4jRE6NuiE43EPl220u/chMyebsSbsUDxSjuJh1hXV76sAAA==" /><credential domain="m161.com.cn" c="CBAOAADowH3pYcBkGIkxcH56EXCIPEJmZ2EXyUKNoOM2xqaJ33i9d5fKaMYY9N7irpMmffobHQws5Eekiz/h+v9nuc3v6zzO8Pd0lIXzutXwzXCROw==" /><credential domain="www.ikuwa.cn" c="ChAOAABbuQDP66jvw7EVpUEjmgWcX/m+qx1KjApplisfSwro1Wp7Aj6Ngu6goEMEx4SHBj+ID4pf+shcudvrfr4C2fUJnmwovu4HZ3+Y1MvS96TtUQ==" /></credentials></user></results>|)
49
+ lambda { @fetion.login }.should raise_exception(Fetion::LoginException)
50
+ end
51
+ end
52
+
53
+ describe "register" do
54
+ before :each do
55
+ @fetion.instance_variable_set(:@user_id, "390937727")
56
+ @fetion.instance_variable_set(:@password, "password")
57
+ end
58
+
59
+ describe "register first" do
60
+ it "should get nonce, key and signature" do
61
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=i&i=1", :body => "SIPP")
62
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=2", :body => "SIPP")
63
+ response_body =<<EOF
64
+ SIP-C/4.0 401 Unauthoried
65
+ F: 730020377
66
+ I: 1
67
+ Q: 1 R
68
+ W: Digest algorithm="SHA1-sess-v4",nonce="1104E253661D71141DFE3FB020143E5A",key="A355B99E9EA38B7306331739A8EC57586FD4E8EC6C6D295C5EED3B6C3A84CB79889E6BED455ACBEDF68270C3FB23C9E54F0626118A09F06845E79248B4F3164E623F84722D5F8B2DFA75AD9454B7E169FB23D5F626C136CBABC6C2D910FDF56917FAFD73990013332CD87795C04799B5E75E2E6BC756D473FC39BD70BEC64D0D010001",signature="8039306257522D5DA4D5BCD0D6B04730A35E1225E9A5C37FD13804B8DAB40F356EA159A6FB2812C74CB5BB33D8764BF77EB10057E177CD2BD83DBBFD36FD30E652BA963B687DABC2E9FD994FADED19286D12C70065CA255528CBAE5D9B4CC087717ED32631FAFB9A2666C2A7356226A27C48E85C3E3580EB7671EA035FE320E0"
69
+
70
+ SIPP
71
+ EOF
72
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=3", :body => response_body)
73
+ @fetion.register_first
74
+
75
+ @fetion.nonce.should == "1104E253661D71141DFE3FB020143E5A"
76
+ @fetion.key.should == "A355B99E9EA38B7306331739A8EC57586FD4E8EC6C6D295C5EED3B6C3A84CB79889E6BED455ACBEDF68270C3FB23C9E54F0626118A09F06845E79248B4F3164E623F84722D5F8B2DFA75AD9454B7E169FB23D5F626C136CBABC6C2D910FDF56917FAFD73990013332CD87795C04799B5E75E2E6BC756D473FC39BD70BEC64D0D010001"
77
+ @fetion.signature.should == "8039306257522D5DA4D5BCD0D6B04730A35E1225E9A5C37FD13804B8DAB40F356EA159A6FB2812C74CB5BB33D8764BF77EB10057E177CD2BD83DBBFD36FD30E652BA963B687DABC2E9FD994FADED19286D12C70065CA255528CBAE5D9B4CC087717ED32631FAFB9A2666C2A7356226A27C48E85C3E3580EB7671EA035FE320E0"
78
+ @fetion.response.size.should == 256
79
+ end
80
+
81
+ it "should raise no nonce exception" do
82
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=i&i=1", :body => "SIPP")
83
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=2", :body => "SIPP")
84
+ response_body =<<EOF
85
+ SIP-C/4.0 401 Unauthoried
86
+ F: 730020377
87
+ I: 1
88
+ Q: 1 R
89
+ W: Digest algorithm="SHA1-sess-v4",nonce=""
90
+ SIPP
91
+ EOF
92
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=3", :body => response_body)
93
+ lambda { @fetion.register_first }.should raise_exception(Fetion::NoNonceException)
94
+ end
95
+ end
96
+
97
+ describe "register second" do
98
+ before :each do
99
+ @fetion.mobile_no = "15800681509"
100
+ @fetion.user_id = "390937727"
101
+ @fetion.response = "458F72ED91E149D28D8467772AB7AD366527B55AC1A10CD18BA1B9BD95F2E082B1594B6C9B116E0BDECC315A2ABA0F4DD20591BF305FCDCDA4CA7B6434EA7788B893E0BB26E4E02097B6707BE0BD60E704D560DDDCB539A3E6FD49B985631FCA02C44D09A6713358BF1D323BA62B5273C7096B97D6A75C6BF9708768FF0113D0"
102
+ @fetion.instance_variable_set(:@seq, 3)
103
+ end
104
+
105
+ it "should get buddies" do
106
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=4", :body => "SIPP")
107
+ response_body =<<EOF
108
+ SIP-C/4.0 200 OK
109
+ I: 1
110
+ Q: 2 R
111
+ X: 600
112
+ L: 5748
113
+
114
+ <results><client public-ip="118.132.146.9" login-place="" last-login-ip="118.132.146.9" last-login-place="" last-login-time="5/8/2010 1:45:21 PM"/><user-info><personal version="326631997" register-email="" user-id="390937727" sid="730020377" mobile-no="15800681509" uri="sip:730020377@fetion.com.cn;p=6907" name="" nickname="flyerhzm" gender="0" impresa="http://www.fetionrobot.com" portrait-crc="0" birth-date="1983-11-07" birthday-valid="0" carrier="CMCC" carrier-status="0" carrier-region="CN.sh.21." user-region="" profile="" blood-type="0" occupation="" hobby="" job-title="" home-phone="" work-phone="" other-phone="" personal-email="flyerhzm" work-email="" other-email="" primary-email="0" company="" company-website="" global-permission="identity=0;phone=0;email=1;birthday=1;business=0;presence=1;contact=1;location=3;buddy=2;ivr=2;buddy-ex=0;show=0;" sms-online-status="0.0:0:0" save-xeno-msg="0" email-binding-status="0" email-binding-alias="flyerhzm" set-pwd-question="0"/><configs><config name="weather-city">-1</config><config name="directsms-rec">0</config><config name="weather-region">CN.sh.21.</config><config name="alv2-setwarn">0</config></configs><custom-config version="326631997">H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/Ih6fVMvLvG6ytqiWr/O2LZYXR49fz6ur51mbN+0XedNkF3lz9Cwrm/zx3cg33PpNsaDPssXqlKBdf9FcHL2p19q+/93j43VbvcpX5fXpMpuU+cyA733+WLt5U73+4rVpFXzmYJ0tZ/m7ox0Pinzy+G50kF9U1ezlvM6avEnvOjAFhmRB8F/Pq+UFuhKkHt81f/PIaTxn52/y8nVbrXwqBZ8/Plk3bbX4bp6187w2KBCq0c8fPy3qfNpSF6/yZl22Bmz3Y4Wa1y/rvMmXU8Y88tkXWbH8brGcVVe2h8/rar16cv1FNcuBhv8n9d6sykz+2EWv7k8e8ZfLsljmRNM2m7b0x7U/7P6XQqWqzp/mbVaUjccZ/qc0rX00nxeX+VerGTEcmOhomb9rifzhh49f58umcsQ7vsquv1yezcpce/I+8L78oliuiY+P7vsNzIfa7vW0zvPl64yYJ4Dlf/74y/NzDFl7UFKEH4Ztvl2t6+Zor9NIPn38ZN1QB8/WZSmdaL+9j4mA4bDfFKsO8WQqXlRtcX6NSQ7+fvyi8v/+7jxfog/tbuDLxy/yKxU+BaPNux8T9OCDHvj4t4/v9kfx7PTspfnjq+XbZXX1+K7/2f8DdlG53MIEAAA=</custom-config><contact-list version="326067976"><buddy-lists><buddy-list id="1" name="我的好友"/><buddy-list id="2" name="好友"/><buddy-list id="3" name="同学"/></buddy-lists><buddies><b i="222516658" u="sip:793401629@fetion.com.cn;p=1919" n="" l="3" f="0" r="1" o="1" p="identity=1;"/><b i="226911221" u="sip:572512981@fetion.com.cn;p=3544" n="" l="1" f="0" r="1" o="1" p="identity=1;"/><b i="227091544" u="sip:669700695@fetion.com.cn;p=3546" n="郭庆" l="3" f="0" r="1" o="0" p="identity=0;"/><b i="228358286" u="sip:660250260@fetion.com.cn;p=3854" n="蔡智武" l="3" f="0" r="1" o="0" p="identity=0;"/><b i="229415466" u="sip:737769829@fetion.com.cn;p=4078" n="ice" l="3" f="0" r="1" o="0" p=""/><b i="295098062" u="sip:638993408@fetion.com.cn;p=2242" n="" l="1" f="0" r="1" o="0" p="identity=1;"/><b i="296436724" u="sip:760087520@fetion.com.cn;p=2467" n="" l="3" f="0" r="1" o="1" p="identity=1;"/><b i="579113578" u="sip:838271744@fetion.com.cn;p=4805" n="" l="1" f="0" r="1" o="0" p="identity=0;"/><b i="665046562" u="sip:926157269@fetion.com.cn;p=12906" n="" l="1" f="0" r="1" o="0" p="identity=0;"/><b i="687455743" u="sip:881033150@fetion.com.cn;p=5493" n="" l="1" f="0" r="1" o="0" p="identity=0;"/><b i="714355089" u="sip:973921799@fetion.com.cn;p=12193" n="" l="1" f="0" r="1" o="0" p="identity=0;"/><b i="732743291" u="sip:480867781@fetion.com.cn;p=16105" n="" l="1" f="0" r="1" o="0" p="identity=0;"/></buddies><chat-friends></chat-friends><blacklist><k i="234374936" u="sip:590114188@fetion.com.cn;p=7222" n=""/><k i="300922541" u="sip:755180702@fetion.com.cn;p=3265" n=""/><k i="313256153" u="sip:730019733@fetion.com.cn;p=9066" n=""/><k i="320122831" u="sip:638009800@fetion.com.cn;p=5795" n=""/><k i="323662900" u="sip:733249322@fetion.com.cn;p=6482" n=""/></blacklist></contact-list><score value="3760" level="7" level-score="3718"/><services></services><quotas><quota-limit><limit name="max-buddies" value="300"/><limit name="max-groupadmin-count" value="2"/><limit name="max-joingroup-count" value="10"/></quota-limit><quota-frequency><frequency name="send-sms" day-limit="600" day-count="10" month-limit="10000" month-count="91"/></quota-frequency></quotas><capability-list basic-caps="1ffff" contact-caps="ffffff" extended-caps="201fff"><contact carrier="CMCC" contact-caps="ffffff" /><contact carrier="CMHK" contact-caps="9ffc9f" /><contact carrier="CMPAK" contact-caps="857c88" /><contact carrier="HK.OTHER" contact-caps="0" /><contact carrier="" contact-caps="a57008" /><contact carrier="SGSH" contact-caps="9ffc9f" /><contact carrier="SGST" contact-caps="9ffc8f" /></capability-list></user-info><credentials kernel="bBTFdUfekBbVDSRJtp+YybH4bb6D1ZUcUNbJqSZ3WtZlVM8kp4xMRY1TUQjJk4fExbvlncxqB1roH71hpvBM7KLrfBkK+3I6C88mjHfNfoloO7ttuQ5RaI6mlyjS0sdsMW4uO3K5yc+Mr/JiNi06FZZIT457dwMt//iei46YeNphEYfgnon9sJOUC6OeRmeo"><credential domain="fetion.com.cn" c="tzTavUsAZdgV45arZ3NoRxlRxk6I4cOcQEnCs1YdcX6oOe//dwqS7FtyluXcfY+sv3eB4CVQR4gh5IqxzTENVGz8+N4L6vqTHuUJ+/VOr8MkRQDn17nKA+bbfbsi1EwT6u8tSMpNFC+wuUZhbXf4/L826iyCFb9jAY6NagME2nSeScIquJp68de7siHz2/tT"/><credential domain="m161.com.cn" c="GZlt16RoTSmDL6e/q3nNL6uahTF1zvo8SZ/FNuiZuRMsB0Y3Rc//9QhhaxUw0vRJLvm3BbHoaKQpAp5lVRfDKdKbKvtOjVhnl/EjbXAVqiSjt6mQYAnVy6FHUKOAyLd1J5yJMo57Zh0GWqeyPHnsaoP8xOnCrarboFaDbfK/12o="/><credential domain="www.ikuwa.cn" c="cVNfOTZIVlQHA0ZLXZKMnO0ZNS3fIH38O+YiqhbX2JuVBPERbNyjFBJW0cKYGsYMiuGmnGt8h9epgLXeUerrVk0P4DGdp9RVLh3XJ5yy/yOSwiYsUqM0I1qq3k0MWzD4xrkmnhUm1uThDNrPoOHK+Zw21nnDvpS+yVof6qduWg0="/><credential domain="games.fetion.com.cn" c="jP2F8PKfgoKrybCvK8YuNbpzWtRicTtoQHrK+UojMmAiEQK4U3erRDt3EGhC2RAWw18Zsf9M/7bK3FiujH4I8Tj5PgXdchPnoI2BXg+XhMCLqzMVc62QSw8JyFJZCao1R10kuERr1gDtd+6V/iLe1oVXymWallXBrekON44/8QrBuE07saSHM8dAEUHvA0ia"/></credentials></results>BN 730020377 SIP-C/4.0
115
+ N: SyncUserInfoV4
116
+ I: 1
117
+ Q: 1 BN
118
+ L: 125
119
+
120
+ <events><event type="SyncUserInfo"><user-info><score value="3760" level="7" level-score="3718"/></user-info></event></events>SIPP
121
+ EOF
122
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=5", :body => response_body)
123
+ @fetion.register_second
124
+
125
+ @fetion.nickname.should == "flyerhzm"
126
+ end
127
+ end
128
+ end
129
+
130
+ describe "get contacts" do
131
+ before :each do
132
+ @fetion.instance_variable_set(:@seq, 5)
133
+ end
134
+
135
+ it "should get all contacts" do
136
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=6", :body => "SIPP")
137
+ response_body =<<-EOF
138
+ SIP-C/4.0 200 OK
139
+ I: 3
140
+ Q: 1 S
141
+ L: 59
142
+
143
+ <results><group-list version ="1" ></group-list></results>SIPP
144
+ EOF
145
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=7", :body => "SIPP")
146
+ response_body =<<-EOF
147
+ SIP-C/4.0 200 OK
148
+ I: 4
149
+ Q: 1 SUB
150
+
151
+ BN 730020377 SIP-C/4.0
152
+ N: PresenceV4
153
+ I: 1
154
+ L: 322
155
+ Q: 2 BN
156
+
157
+ <events><event type="PresenceChanged"><contacts><c id="222516658"><p v="0" sid="793401629" su="sip:793401629@fetion.com.cn;p=1919" m="13601804916" c="CMCC" cs="0" s="1" l="0" svc="" n="Peter" i="人生哈哈哈" p="428986348" sms="0.0:0:0" sp="0" sh="0"/><pr di="" b="0" d="" dt="" dc="0"/></c></contacts></event></events>BN 730020377 SIP-C/4.0
158
+ N: PresenceV4
159
+ I: 1
160
+ L: 329
161
+ Q: 3 BN
162
+
163
+ <events><event type="PresenceChanged"><contacts><c id="229415466"><p v="0" sid="737769829" su="sip:737769829@fetion.com.cn;p=4078" m="13817731963" c="CMCC" cs="0" s="1" l="8" svc="" n="ice" i="" p="-2000590228" sms="0.0:0:0" sp="0" sh="0"/><pr di="PCCL030516427968" b="400" d="" dt="PC" dc="137"/></c></contacts></event></events>BN 730020377 SIP-C/4.0
164
+ N: PresenceV4
165
+ I: 1
166
+ L: 303
167
+ Q: 4 BN
168
+
169
+ <events><event type="PresenceChanged"><contacts><c id="228358286"><p v="0" sid="660250260" su="sip:660250260@fetion.com.cn;p=3854" m="13795359343" c="CMCC" cs="0" s="1" l="4" 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>BN 730020377 SIP-C/4.0
170
+ N: PresenceV4
171
+ I: 1
172
+ L: 643
173
+ Q: 5 BN
174
+
175
+ <events><event type="PresenceChanged"><contacts><c id="390937727"><p v="0" cs="0" n="flyerhzm" i="http://www.fetionrobot.com" sms="0.0:0:0" sp="0"/></c><c id="665046562"><p v="0" sid="926157269" su="sip:926157269@fetion.com.cn;p=12906" m="" c="CMCC" cs="0" s="1" l="0" svc="" n="黄雅莉" i="" p="0" sms="10099.12:57:24" sp="0" sh="0"/><pr di="" b="0" d="" dt="" dc="0"/></c><c id="227091544"><p v="0" sid="669700695" su="sip:669700695@fetion.com.cn;p=3546" m="13764589545" c="CMCC" cs="0" s="1" l="10" svc="" n="郭庆" i="looloo" p="598224859" sms="0.0:0:0" sp="0" sh="0"/><pr di="" b="0" d="" dt="" dc="0"/></c></contacts></event></events>BN 730020377 SIP-C/4.0
176
+ N: PresenceV4
177
+ I: 1
178
+ L: 338
179
+ Q: 6 BN
180
+
181
+ <events><event type="PresenceChanged"><contacts><c id="296436724"><p v="0" sid="760087520" su="sip:760087520@fetion.com.cn;p=2467" m="13656681075" c="CMCC" cs="0" s="1" l="5" svc="" n="蒋健" i="TD只需成功,不许失败" p="2074595345" sms="0.0:0:0" sp="0" sh="0"/><pr di="" b="0" d="" dt="" dc="0"/></c></contacts></event></events>BN 730020377 SIP-C/4.0
182
+ N: PresenceV4
183
+ I: 1
184
+ L: 291
185
+ Q: 7 BN
186
+
187
+ <events><event type="PresenceChanged"><contacts><c id="732743291"><p v="0" sid="480867781" su="sip:480867781@fetion.com.cn;p=16105" m="" c="" cs="1" s="1" l="0" svc="" n="黄志敏" i="" p="0" sms="365.0:0:0" sp="0" sh="1"/><pr di="" b="0" d="" dt="" dc="0"/></c></contacts></event></events>BN 730020377 SIP-C/4.0
188
+ N: PresenceV4
189
+ I: 1
190
+ L: 369
191
+ Q: 8 BN
192
+
193
+ <events><event type="PresenceChanged"><contacts><c id="226911221"><p v="0" sid="572512981" su="sip:572512981@fetion.com.cn;p=3544" m="13764325001" c="CMCC" cs="0" s="1" l="10" svc="" n="陈勇sh" i="http://slide.news.sina.com.cn/c/slide_1_797_11165.html#p=1" p="-98773891" sms="0.0:0:0" sp="0" sh="0"/><pr di="" b="0" d="" dt="" dc="0"/></c></contacts></event></events>BN 730020377 SIP-C/4.0
194
+ N: PresenceV4
195
+ I: 1
196
+ L: 300
197
+ Q: 9 BN
198
+
199
+ <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>BN 730020377 SIP-C/4.0
200
+ N: SystemNotifyV4
201
+ L: 84
202
+ I: 1
203
+ Q: 10 BN
204
+
205
+ <events><event type="MobileMailBoxChanged"><mail unread-count="1"/></event></events>SIPP
206
+ EOF
207
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=8", :body => response_body)
208
+ response_body =<<-EOF
209
+ SIP-C/4.0 200 OK
210
+ I: 5
211
+ Q: 1 S
212
+ L: 835
213
+
214
+ <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
215
+ EOF
216
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=9", :body => response_body)
217
+ response_body =<<-EOF
218
+ SIP-C/4.0 200 OK
219
+ I: 6
220
+ Q: 1 S
221
+ L: 61
222
+
223
+ <results><contacts version="326661305" ></contacts></results>SIPP
224
+ EOF
225
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=10", :body => response_body)
226
+ @fetion.get_contacts
227
+ @fetion.contacts.collect {|contact| contact.sid}.should == ["793401629", "737769829", "660250260", "926157269", "669700695", "760087520", "480867781", "572512981", "638993408"]
228
+ end
229
+ end
230
+
231
+ describe "send msg" do
232
+ before :each do
233
+ @fetion.instance_variable_set(:@seq, 10)
234
+ end
235
+
236
+ it "should send msg to receiver" do
237
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=11", :body => 'SIPP')
238
+ response_body =<<-EOF
239
+ SIP-C/4.0 200 OK
240
+ I: 7
241
+ Q: 3 M
242
+ D: Sat, 08 May 2010 14:51:55 GMT
243
+ XI: 925d6e3837b7410f9187ae66853e9a25
244
+ T: sip:638993408@fetion.com.cn;p=2242
245
+
246
+ SIPP
247
+ EOF
248
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=12", :body => response_body)
249
+ @fetion.send_msg('sip:638993408@fetion.com.cn;p=2242', 'test')
250
+ end
251
+ end
252
+
253
+ describe "send sms" do
254
+ before :each do
255
+ @fetion.instance_variable_set(:@seq, 10)
256
+ end
257
+
258
+ it "should send sms to receiver" do
259
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=11", :body => 'SIPP')
260
+ response_body =<<-EOF
261
+ SIP-C/4.0 280 Send SMS OK
262
+ T: sip:730020377@fetion.com.cn;p=6907
263
+ I: 9
264
+ Q: 1 M
265
+
266
+ SIPP
267
+ EOF
268
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=12", :body => response_body)
269
+ @fetion.send_sms('sip:638993408@fetion.com.cn;p=2242', 'test')
270
+ end
271
+ end
272
+
273
+ describe "set schedule sms" do
274
+ before :each do
275
+ @fetion.instance_variable_set(:@seq, 10)
276
+ end
277
+
278
+ it "should set schedule sms to receiver" do
279
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=11", :body => 'SIPP')
280
+ response_body =<<-EOF
281
+ SIP-C/4.0 200 OK
282
+ I: 11
283
+ Q: 1 S
284
+ L: 92
285
+
286
+ <results><schedule-sms-list version="36"/><schedule-sms id="2124923" version="1"/></results>SIPP
287
+ EOF
288
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=12", :body => response_body)
289
+ @fetion.set_schedule_sms('sip:638993408@fetion.com.cn;p=2242', 'test', Time.at(Time.now + 24*60*60))
290
+ end
291
+ end
292
+
293
+ describe "add buddy" do
294
+ before :each do
295
+ @fetion.instance_variable_set(:@seq, 11)
296
+ @fetion.instance_variable_set(:@nickname, 'flyerhzm')
297
+ end
298
+
299
+ it "should add buddy" do
300
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=12", :body => 'SIPP')
301
+ response_body =<<-EOF
302
+ SIP-C/4.0 200 OK
303
+ I: 16
304
+ Q: 1 S
305
+ L: 320
306
+
307
+ <results><contacts version="326679363"><buddies><buddy uri="sip:638993408@fetion.com.cn;p=2242" local-name="" buddy-lists="1" online-notify="0" desc="flyerhzm" relation-status="0" user-id="295098062" addbuddy-phrase-id="0" status-code="200" permission-values="" basic-service-status="1" /></buddies></contacts></results>BN 730020377 SIP-C/4.0
308
+ N: SyncUserInfoV4
309
+ I: 1
310
+ Q: 17 BN
311
+ L: 248
312
+
313
+ <events><event type="SyncUserInfo"><user-info><contact-list version="326679363"><buddies><buddy action="update" user-id="295098062" uri="sip:638993408@fetion.com.cn;p=2242" relation-status="1"/></buddies></contact-list></user-info></event></events>BN 730020377 SIP-C/4.0
314
+ N: PresenceV4
315
+ I: 1
316
+ L: 329
317
+ Q: 18 BN
318
+
319
+ <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
320
+ EOF
321
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=13", :body => response_body)
322
+ @fetion.add_buddy(:friend_mobile => '13634102006')
323
+ end
324
+ end
325
+
326
+ describe "get contact info" do
327
+ before :each do
328
+ @fetion.instance_variable_set(:@seq, 11)
329
+ end
330
+
331
+ it "should get contact info" do
332
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=12", :body => 'SIPP')
333
+ response_body =<<-EOF
334
+ SIP-C/4.0 200 OK
335
+ I: 11
336
+ Q: 1 S
337
+ L: 166
338
+
339
+ <results><contact uri="tel:15800681507" version="0" user-id="625007505" mobile-no="15800681507" basic-service-status="0" carrier="CMCC" carrier-status="0"/></results>SIPP
340
+ EOF
341
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=13", :body => response_body)
342
+ @fetion.get_contact_info(:friend_mobile => '15800681507')
343
+ end
344
+
345
+ it "should get exception when no such user" do
346
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=12", :body => 'SIPP')
347
+ response_body =<<-EOF
348
+ SIP-C/4.0 404 Not Found
349
+ I: 35
350
+ Q: 1 S
351
+
352
+ SIPP
353
+ EOF
354
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=13", :body => response_body)
355
+ lambda {@fetion.get_contact_info(:friend_mobile => '15800681505')}.should raise_exception(Fetion::NoUserException)
356
+ end
357
+ end
358
+
359
+ describe "logout" do
360
+ before :each do
361
+ @fetion.instance_variable_set(:@seq, 12)
362
+ end
363
+
364
+ it "should logout" do
365
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=13", :body => '')
366
+ FakeWeb.register_uri(:post, "http://221.176.31.39/ht/sd.aspx?t=s&i=14", :body => '')
367
+ end
368
+ end
369
+ end
@@ -0,0 +1,93 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe SipcMessage do
4
+ class Fetion
5
+ attr_accessor :mobile_no, :sid, :password, :status_code, :user_status, :user_id, :ssic, :nonce, :key, :signature, :response, :call
6
+ end
7
+
8
+ before :each do
9
+ @fetion = Fetion.new
10
+ @fetion.sid = "730020377"
11
+ @fetion.user_id = "390937727"
12
+ @fetion.mobile_no = "15800681509"
13
+ @fetion.response = "62E57A276EB9B7AAC233B8983A39941870CE74E3B2CD6480B5CA9DCF37C57DECEA250F261543CB4424EE9E72354C9F33C805EB9839BF96501D0261614E69BDF0DBDF484047750B3113DF8850FEF39428ADC17FE86E8800ED5A77AA7F6630F21AE8A24E6ECC2F003BF3B93E35051A7778D238F86D21581BC829679EBEAD36390F"
14
+ end
15
+
16
+ it "should get register first" do
17
+ guid = hexdigest = ""
18
+ Guid.stubs(:new).returns(guid)
19
+ guid.stubs(:hexdigest).returns(hexdigest)
20
+ 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
+ SipcMessage.register_first(@fetion).should == sipc_message
23
+ end
24
+
25
+ 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|
27
+ SipcMessage.register_second(@fetion).should == sipc_message
28
+ end
29
+
30
+ it "should get group list" do
31
+ @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|
33
+ SipcMessage.get_group_list(@fetion).should == sipc_message
34
+ end
35
+
36
+ it "should presence" do
37
+ @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|
39
+ SipcMessage.presence(@fetion).should == sipc_message
40
+ end
41
+
42
+ it "should get group topic" do
43
+ @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|
45
+ SipcMessage.get_group_topic(@fetion).should == sipc_message
46
+ end
47
+
48
+ it "should get address list" do
49
+ @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|
51
+ SipcMessage.get_address_list(@fetion).should == sipc_message
52
+ end
53
+
54
+ it "should send cat sms" do
55
+ @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|
57
+ SipcMessage.send_cat_sms(@fetion, 'sip:730020377@fetion.com.cn;p=6907', 'test').should == sipc_message
58
+ end
59
+
60
+ it "should send msg" do
61
+ @fetion.call = 8
62
+ sipc_message = %Q|M fetion.com.cn SIP-C/4.0\r\nF: 730020377\r\nI: 9\r\nQ: 3 M\r\nT: sip:638993408@fetion.com.cn;p=2242\r\nK: SaveHistory\r\nL: 4\r\n\r\ntestSIPP|
63
+ SipcMessage.send_msg(@fetion, 'sip:638993408@fetion.com.cn;p=2242', 'test').should == sipc_message
64
+ end
65
+
66
+ it "should set schedule sms" do
67
+ @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|
69
+ SipcMessage.set_schedule_sms(@fetion, ['sip:638993408@fetion.com.cn;p=2242'], 'test', '2010-05-08 15:50:00').should == sipc_message
70
+ end
71
+
72
+ it "should get contact info" do
73
+ @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|
75
+ SipcMessage.get_contact_info(@fetion, 15800681507).should == sipc_message
76
+ end
77
+
78
+ it "should add buddy" do
79
+ @fetion.call = 9
80
+ @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|
82
+ SipcMessage.add_buddy(@fetion, :friend_mobile => "13634102006").should == sipc_message
83
+
84
+ @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|
86
+ SipcMessage.add_buddy(@fetion, :friend_sip => "638993408").should == sipc_message
87
+ end
88
+
89
+ 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|
91
+ SipcMessage.logout(@fetion).should == sipc_message
92
+ end
93
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,8 @@
1
+ --colour
2
+ --format
3
+ specdoc
4
+ --reverse
5
+ --timeout
6
+ 20
7
+ --loadby
8
+ mtime