rfetion 0.4.7 → 0.4.8

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,10 +21,11 @@ gem install rfetion
21
21
 
22
22
  h2. Usage
23
23
 
24
- * send sms to friends or yourself
24
+ * send sms or msg to friends or yourself
25
25
 
26
26
  <pre><code>
27
27
  Fetion.send_sms(options)
28
+ Fetion.send_msg(options)
28
29
  </code></pre>
29
30
 
30
31
  options can be:
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ Jeweler::Tasks.new do |gemspec|
10
10
  gemspec.authors = ['Richard Huang']
11
11
  gemspec.files.exclude '.gitignore'
12
12
  gemspec.add_dependency 'guid', '>= 0.1.1'
13
+ gemspec.add_dependency 'nokogiri'
13
14
  gemspec.executables << 'rfetion'
14
15
  end
15
16
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.7
1
+ 0.4.8
@@ -3,7 +3,7 @@ require 'guid'
3
3
  require 'time'
4
4
  require 'net/http'
5
5
  require 'net/https'
6
- require 'rexml/document'
6
+ require 'nokogiri'
7
7
  require 'digest/sha1'
8
8
  require 'digest/md5'
9
9
  require 'logger'
@@ -69,6 +69,40 @@ class Fetion
69
69
  end
70
70
  fetion.logout
71
71
  end
72
+
73
+ # options
74
+ # mobile_no
75
+ # sid
76
+ # password
77
+ # receivers
78
+ # content
79
+ # logger_level
80
+ def Fetion.send_msg(options)
81
+ fetion = Fetion.new
82
+ fetion.logger_level = options[:logger_level] || Logger::INFO
83
+ fetion.mobile_no = options[:mobile_no]
84
+ fetion.sid = options[:sid]
85
+ fetion.password = options[:password]
86
+ fetion.login
87
+ fetion.register
88
+ receivers = options[:receivers]
89
+ content = options[:content]
90
+ if receivers
91
+ receivers = Array(receivers)
92
+ receivers.collect! {|receiver| receiver.to_s}
93
+ fetion.get_buddy_list
94
+ fetion.get_contacts_info
95
+ fetion.contacts.each do |contact|
96
+ if receivers.include? contact.mobile_no.to_s or receivers.any? { |receiver| contact.uri.index(receiver) }
97
+ fetion.send_msg(contact.uri, content)
98
+ end
99
+ end
100
+ fetion.send_msg(fetion.uri, content) if receivers.any? { |receiver| fetion.self? receiver }
101
+ else
102
+ fetion.send_msg(fetion.uri, content)
103
+ end
104
+ fetion.logout
105
+ end
72
106
 
73
107
  # options
74
108
  # mobile_no
@@ -145,14 +179,14 @@ class Fetion
145
179
 
146
180
  @ssic = $1
147
181
  @logger.debug response.body
148
- doc = REXML::Document.new(response.body)
182
+ doc = Nokogiri::XML(response.body)
149
183
  results = doc.root
150
- @status_code = results.attributes["status-code"]
184
+ @status_code = results["status-code"]
151
185
  user = results.children.first
152
- @user_status = user.attributes['user-status']
153
- @uri = user.attributes['uri']
154
- @mobile_no = user.attributes['mobile-no']
155
- @user_id = user.attributes['user-id']
186
+ @user_status = user['user-status']
187
+ @uri = user['uri']
188
+ @mobile_no = user['mobile-no']
189
+ @user_id = user['user-id']
156
190
  if @uri =~ /sip:(\d+)@(.+);/
157
191
  @sid = $1
158
192
  @domain = $2
@@ -233,9 +267,9 @@ class Fetion
233
267
  raise FetionException.new("Fetion Error: Get buddy list error") unless response.is_a? Net::HTTPSuccess
234
268
 
235
269
  response.body.scan(%r{<results>.*?</results>}).each do |results|
236
- doc = REXML::Document.new(results)
237
- doc.elements.each("results/contacts/allow-list/contact") do |contact|
238
- @buddies << {:uri => contact.attributes["uri"]}
270
+ doc = Nokogiri::XML(results)
271
+ doc.root.xpath("/results/contacts/allow-list/contact").each do |contact|
272
+ @buddies << {:uri => contact["uri"]}
239
273
  end
240
274
  end
241
275
  @logger.debug "buddies: #{@buddies.inspect}"
@@ -260,16 +294,26 @@ class Fetion
260
294
  end
261
295
 
262
296
  response.body.scan(%r{<results>.*?</results>}).each do |results|
263
- doc = REXML::Document.new(results)
264
- doc.elements.each("results/contacts/contact") do |contact|
265
- attrs = contact.children.size == 0 ? {} : contact.children.first.attributes
266
- @contacts << Contact.new(contact.attributes["uri"], attrs)
297
+ doc = Nokogiri::XML(results)
298
+ doc.root.xpath("/results/contacts/contact").each do |contact|
299
+ attrs = contact.children.size == 0 ? {} : contact.children.first
300
+ @contacts << Contact.new(contact["uri"], attrs)
267
301
  end
268
302
  end
269
303
  @logger.debug @contacts.inspect
270
304
  @logger.info "fetion get contacts info success"
271
305
  end
272
306
 
307
+ def send_msg(receiver, content)
308
+ @logger.info "fetion SendMsg to #{receiver}"
309
+ msg = sip_create('M fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '3 M', 'T' => receiver, 'C' => 'text/html-fragment', 'K' => 'SaveHistory'}, content) + FETION_SIPP
310
+ curl_exec(next_url, @ssic, msg)
311
+ response = curl_exec(next_url, @ssic, FETION_SIPP)
312
+
313
+ raise FetionException.new("Fetion Error: Send sms error") unless response.is_a? Net::HTTPSuccess
314
+ @logger.info "fetion SendMsg to #{receiver} success"
315
+ end
316
+
273
317
  def send_sms(receiver, content)
274
318
  @logger.info "fetion #{send_command} to #{receiver}"
275
319
  msg = sip_create('M fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '1 M', 'T' => receiver, 'N' => send_command}, content) + FETION_SIPP
@@ -307,10 +351,8 @@ class Fetion
307
351
  response = curl_exec(next_url, @ssic, FETION_SIPP)
308
352
  raise FetionException.new("Fetion Error: Get personal info error") unless response.is_a? Net::HTTPSuccess
309
353
 
310
- doc = REXML::Document.new(response.body.chomp(FETION_SIPP))
311
- doc.elements.each('results/personal') do |person|
312
- @person = person.attributes
313
- end
354
+ doc = Nokogiri::XML(response.body.chomp(FETION_SIPP))
355
+ @person = doc.root.xpath('/results/personal').first
314
356
  @logger.info "fetion get personal info success"
315
357
  end
316
358
 
data/lib/rfetion.rb CHANGED
@@ -1,2 +1,2 @@
1
- require 'rfetion/fetion'
2
- require 'rfetion/contact'
1
+ require File.dirname(__FILE__) + '/rfetion/fetion'
2
+ require File.dirname(__FILE__) + '/rfetion/contact'
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.7"
8
+ s.version = "0.4.8"
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-01-25}
12
+ s.date = %q{2010-04-27}
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"]
@@ -39,11 +39,14 @@ Gem::Specification.new do |s|
39
39
 
40
40
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
41
41
  s.add_runtime_dependency(%q<guid>, [">= 0.1.1"])
42
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
42
43
  else
43
44
  s.add_dependency(%q<guid>, [">= 0.1.1"])
45
+ s.add_dependency(%q<nokogiri>, [">= 0"])
44
46
  end
45
47
  else
46
48
  s.add_dependency(%q<guid>, [">= 0.1.1"])
49
+ s.add_dependency(%q<nokogiri>, [">= 0"])
47
50
  end
48
51
  end
49
52
 
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.7
4
+ version: 0.4.8
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-01-25 00:00:00 +08:00
12
+ date: 2010-04-27 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.1.1
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
25
35
  description: rfetion is a ruby gem for China Mobile fetion service that you can send SMS free.
26
36
  email: flyerhzm@gmail.com
27
37
  executables: