rfetion 0.4.0 → 0.4.1

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/README.textile CHANGED
@@ -21,22 +21,28 @@ gem install rfetion
21
21
 
22
22
  h2. Usage
23
23
 
24
- send sms to friends or yourself
24
+ * send sms to friends or yourself
25
+
25
26
  <pre><code>
26
27
  Fetion.send_sms(mobile_no, password, mobile_or_fetion_numbers, content)
27
28
  </code></pre>
28
29
 
29
- add friend with mobile
30
+ if mobile_or_fetion_numbers are nil, send sms to yourself.
31
+
32
+ * add friend with mobile
33
+
30
34
  <pre><code>
31
35
  Fetion.add_buddy_with_mobile(mobile_no, password, friend_mobile)
32
36
  </code></pre>
33
37
 
34
- add friend with sip
38
+ * add friend with sip
39
+
35
40
  <pre><code>
36
41
  Fetion.add_buddy_with_sip(mobile_no, password, friend_sip)
37
42
  </code></pre>
38
43
 
39
- send schedule sms to friends
44
+ * send schedule sms to friends
45
+
40
46
  <pre><code>
41
47
  Fetion.schedule_sms(mobile_no, password, mobile_or_fetion_number, content, time)
42
48
  </code></pre>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -86,6 +86,7 @@ class Fetion
86
86
  fetion.password = password
87
87
  fetion.login
88
88
  fetion.register
89
+ fetion.get_personal_info
89
90
  fetion.add_buddy_with_mobile(friend_mobile)
90
91
  fetion.logout
91
92
  end
@@ -97,6 +98,7 @@ class Fetion
97
98
  fetion.password = password
98
99
  fetion.login
99
100
  fetion.register
101
+ fetion.get_personal_info
100
102
  fetion.add_buddy_with_sip(friend_sip)
101
103
  fetion.logout
102
104
  end
@@ -141,7 +143,7 @@ class Fetion
141
143
  def register
142
144
  @logger.info "fetion http register"
143
145
  call = next_call
144
- arg = '<args><device type="PC" version="284488270" client-version="3.2.0540" /><caps value="simple-im;im-session;temp-group;personal-group;im-relay;xeno-im;direct-sms;sms2fetion" /><events value="contact;permission;system-message;personal-group;compact" /><user-info attributes="all" /><presence><basic value="400" desc="" /></presence></args>'
146
+ arg = '<args><device type="PC" version="284571220" client-version="3.3.0370" /><caps value="simple-im;im-session;temp-group;personal-group" /><events value="contact;permission;system-message;personal-group" /><user-info attributes="all" /><presence><basic value="400" desc="" /></presence></args>'
145
147
 
146
148
  register_first(call, arg)
147
149
 
@@ -260,20 +262,44 @@ class Fetion
260
262
  @logger.info "fetion schedule send sms to #{receivers.join(', ')} success"
261
263
  end
262
264
 
263
- def add_buddy_with_mobile(mobile, nickname = nil)
265
+ def get_personal_info
266
+ @logger.info "fetion get personal info"
267
+ arg = %Q{<args><personal attributes="all" /><services version="" attributes="all" /><config version="96" attributes="all" /><mobile-device attributes="all" /></args>}
268
+ msg = sip_create('S fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '1 S', 'N' => 'GetPersonalInfo'}, arg) + FETION_SIPP
269
+ curl_exec(next_url, @ssic, msg)
270
+ response = curl_exec(next_url, @ssic, FETION_SIPP)
271
+ raise FetionException.new("Fetion Error: Get personal info error") unless response.is_a? Net::HTTPSuccess
272
+
273
+ doc = REXML::Document.new(response.body.chomp(FETION_SIPP))
274
+ doc.elements.each('results/personal') do |person|
275
+ @person = person.attributes
276
+ end
277
+ @logger.info "fetion get personal info success"
278
+ end
279
+
280
+ def add_buddy_with_mobile(mobile)
264
281
  @logger.info "fetion send request to add mobile:#{mobile} as friend"
265
- arg = %Q{<args><contacts><buddies><buddy uri="tel:#{mobile}" local-name="#{nickname}" buddy-lists="1" expose-mobile-no="1" expose-name="1" /></buddies></contacts></args>}
282
+ arg = %Q{<args><contacts><buddies><buddy uri="tel:#{mobile}" local-name="" buddy-lists="1" desc="#{@person['nickname']}" expose-mobile-no="1" expose-name="1" /></buddies></contacts></args>}
266
283
  msg = sip_create('S fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '1 S', 'N' => 'AddBuddy'}, arg) + FETION_SIPP
267
284
  curl_exec(next_url, @ssic, msg)
268
285
  response = curl_exec(next_url, @ssic, FETION_SIPP)
269
-
270
286
  raise FetionException.new("Fetion Error: Add buddy error") unless response.is_a? Net::HTTPSuccess
287
+
288
+ if response.body =~ /No Subscription/
289
+ arg = %Q{<args><contacts><mobile-buddies><mobile-buddy uri="tel:#{mobile}" local-name="" buddy-lists="1" desc="#{@person['nickname']}" expose-mobile-no="1" expose-name="1" /></mobile-buddies></contacts></args>}
290
+ msg = sip_create('S fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '1 S', 'N' => 'AddMobileBuddy'}, arg) + FETION_SIPP
291
+ curl_exec(next_url, @ssic, msg)
292
+ response = curl_exec(next_url, @ssic, FETION_SIPP)
293
+ raise FetionException.new("Fetion Error: Add buddy error") unless response.is_a? Net::HTTPSuccess
294
+
295
+ raise FetionException.new("Fetion Error: No this mobile") if response.body =~ /Not Found/
296
+ end
271
297
  @logger.info "fetion send request to add mobile:#{mobile} as friend success"
272
298
  end
273
299
 
274
- def add_buddy_with_sip(sip, nickname = nil)
300
+ def add_buddy_with_sip(sip)
275
301
  @logger.info "fetion send request to add sip:#{sip} as friend"
276
- arg = %Q{<args><contacts><buddies><buddy uri="sip:#{sip}" local-name="#{nickname}" buddy-lists="1" expose-mobile-no="1" expose-name="1" /></buddies></contacts></args>}
302
+ arg = %Q{<args><contacts><buddies><buddy uri="sip:#{sip}" local-name="" buddy-lists="1" desc="#{@person['nickname']}" expose-mobile-no="1" expose-name="1" /></buddies></contacts></args>}
277
303
  msg = sip_create('S fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '1 S', 'N' => 'AddBuddy'}, arg) + FETION_SIPP
278
304
  curl_exec(next_url, @ssic, msg)
279
305
  response = curl_exec(next_url, @ssic, FETION_SIPP)
data/rfetion.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rfetion}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
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"]
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang