rfetion 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -28,7 +28,7 @@ Fetion.send_sms_to_self(mobile_no, password, content)
28
28
 
29
29
  send sms to friends
30
30
  <pre><code>
31
- Fetion.send_sms_to_friends(mobile_no, password, friend_mobile_no or array of friends_mobile_no, content)
31
+ Fetion.send_sms_to_friends(mobile_no, password, friends_mobile_or_fetion_number, content)
32
32
  </code></pre>
33
33
 
34
34
  add friend
@@ -43,14 +43,19 @@ h2. Shell command
43
43
  you can use it in shell command directly
44
44
 
45
45
  <pre><code>
46
- rfetion -h
46
+ Usage: rfetion [options]
47
+ Example: rfetion -m mobile -p password -f friends_mobile_or_fetion_number -c sms_content
48
+
49
+ rfetion -m mobile -p password -a friend_mobile
47
50
 
48
- Usage: rfetion [options]
49
- Example: rfetion -m mobile -p password -f friend_mobile -c sms_content
50
- rfetion -m mobile -p password -a friend_mobile
51
51
  -m, --mobile MOBILE Fetion mobile number
52
52
  -p, --password PASSWORD Fetion password
53
53
  -c, --content CONTENT Fetion message content
54
- -f, --friends MOBILE1,MOBILE2 (optional) Fetion friends mobile number, if no friends mobile number, send message to yourself
54
+ -f, --friends MOBILE,FETION (optional) Fetion friends mobile number or fetion number, if no friends mobile number and fetion number, send message to yourself
55
55
  -a, --add_buddy MOBILE Add friend mobile as fetion friend
56
+ different mode:
57
+ --debug debug mode
58
+ --silence silence mode
59
+ Common options:
60
+ -h, --help Show this message
56
61
  </code></pre>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -8,7 +8,7 @@ OptionParser.new do |opts|
8
8
 
9
9
  opts.separator ""
10
10
  opts.separator <<EOF
11
- Example: rfetion -m mobile -p password -f friend_mobile -c sms_content
11
+ Example: rfetion -m mobile -p password -f friends_mobile_or_fetion_number -c sms_content
12
12
  rfetion -m mobile -p password -a friend_mobile
13
13
  EOF
14
14
 
@@ -24,9 +24,9 @@ EOF
24
24
  options[:content] = f
25
25
  end
26
26
 
27
- options[:friends_mobile] = []
28
- opts.on('-f', '--friends MOBILE1,MOBILE2', Array, '(optional) Fetion friends mobile number, if no friends mobile number, send message to yourself') do |f|
29
- options[:friends_mobile] = f
27
+ options[:friends] = []
28
+ opts.on('-f', '--friends MOBILE,FETION', Array, '(optional) Fetion friends mobile number or fetion number, if no friends mobile number and fetion number, send message to yourself') do |f|
29
+ options[:friends] = f
30
30
  end
31
31
 
32
32
  opts.on('-a', '--add_buddy MOBILE', 'Add friend mobile as fetion friend') do |f|
@@ -69,10 +69,10 @@ begin
69
69
  end
70
70
 
71
71
  raise FetionException.new('You must input your mobile number, password and content') unless options[:mobile_no] and options[:password] and options[:content]
72
- if options[:friends_mobile].empty?
72
+ if options[:friends].empty?
73
73
  Fetion.send_sms_to_self(options[:mobile_no], options[:password], options[:content], level(options))
74
74
  else
75
- Fetion.send_sms_to_friends(options[:mobile_no], options[:password], options[:friends_mobile], options[:content], level(options))
75
+ Fetion.send_sms_to_friends(options[:mobile_no], options[:password], options[:friends], options[:content], level(options))
76
76
  end
77
77
  rescue FetionException => e
78
78
  puts e.message
@@ -36,9 +36,9 @@ class Fetion
36
36
  fetion.logout
37
37
  end
38
38
 
39
- def Fetion.send_sms_to_friends(mobile_no, password, friend_mobiles, content, level = Logger::INFO)
40
- friend_mobiles = Array(friend_mobiles)
41
- friend_mobiles.collect! {|mobile| mobile.to_i}
39
+ def Fetion.send_sms_to_friends(mobile_no, password, friends, content, level = Logger::INFO)
40
+ friends = Array(friends)
41
+ friends.collect! {|friend| friend.to_i}
42
42
  fetion = Fetion.new
43
43
  fetion.logger_level = level
44
44
  fetion.mobile_no = mobile_no
@@ -48,8 +48,10 @@ class Fetion
48
48
  fetion.get_buddy_list
49
49
  fetion.get_contacts_info
50
50
  fetion.contacts.each do |contact|
51
- if friend_mobiles.include? contact[:mobile_no].to_i
51
+ if friends.include? contact[:mobile_no].to_i
52
52
  fetion.send_sms(contact[:sip], content)
53
+ elsif friends.any? { |friend| contact[:sip].index(friend) }
54
+ fetion.send_sms
53
55
  end
54
56
  end
55
57
  fetion.logout
@@ -129,8 +131,8 @@ class Fetion
129
131
  curl_exec(next_url, @ssic, msg)
130
132
  response = curl_exec(next_url, @ssic, FETION_SIPP)
131
133
 
134
+ raise FetionException.new('Fetion Error: Register failed.') unless response.is_a? Net::HTTPSuccess
132
135
  @logger.info "fetion http register success"
133
- response.is_a? Net::HTTPSuccess
134
136
  end
135
137
 
136
138
  def get_buddy_list
@@ -139,12 +141,12 @@ class Fetion
139
141
  msg = sip_create('S fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '1 S', 'N' => 'GetContactList'}, arg) + FETION_SIPP
140
142
  curl_exec(next_url, @ssic, msg)
141
143
  response = curl_exec(next_url, @ssic, FETION_SIPP)
142
- raise FetionException.new("Fetion Error: No buddy list found") unless response.body =~ /.*?\r\n\r\n(.*)#{FETION_SIPP}\s*$/i
144
+ raise FetionException.new("Fetion Error: Get buddy list error") unless response.is_a? Net::HTTPSuccess
143
145
 
144
146
  response.body.scan(/uri="([^"]+)"/).each do |buddy|
145
147
  @buddies << {:uri => buddy[0]}
146
148
  end
147
- @logger.debug @buddies.inspect
149
+ @logger.debug "buddies: #{@buddies.inspect}"
148
150
  @logger.info "fetion get buddy list success"
149
151
  end
150
152
 
@@ -159,6 +161,8 @@ class Fetion
159
161
  msg = sip_create('S fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '1 S', 'N' => 'GetContactsInfo'}, arg) + FETION_SIPP
160
162
  curl_exec(next_url, @ssic, msg)
161
163
  response = curl_exec(next_url, @ssic, FETION_SIPP)
164
+ raise FetionException.new("Fetion Error: Get contacts info error") unless response.is_a? Net::HTTPSuccess
165
+
162
166
  response.body.scan(/uri="([^"]+)".*?mobile-no="([^"]+)"/).each do |contact|
163
167
  @contacts << {:sip => contact[0], :mobile_no => contact[1]}
164
168
  end
@@ -169,20 +173,22 @@ class Fetion
169
173
  def send_sms(to, content)
170
174
  @logger.info "fetion send sms to #{to}"
171
175
  msg = sip_create('M fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '1 M', 'T' => to, 'N' => 'SendSMS'}, content) + FETION_SIPP
172
- response = curl_exec(next_url, @ssic, msg)
176
+ curl_exec(next_url, @ssic, msg)
177
+ response = curl_exec(next_url, @ssic, FETION_SIPP)
173
178
 
179
+ raise FetionException.new("Fetion Error: Send sms error") unless response.is_a? Net::HTTPSuccess
174
180
  @logger.info "fetion send sms to #{to} success"
175
- response.is_a? Net::HTTPSuccess
176
181
  end
177
182
 
178
183
  def add_buddy(mobile, nickname = nil)
179
184
  @logger.info "fetion send request to add #{mobile} as friend"
180
185
  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>}
181
186
  msg = sip_create('S fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '1 S', 'N' => 'AddBuddy'}, arg) + FETION_SIPP
182
- response = curl_exec(next_url, @ssic, msg)
187
+ curl_exec(next_url, @ssic, msg)
188
+ response = curl_exec(next_url, @ssic, FETION_SIPP)
183
189
 
190
+ raise FetionException.new("Fetion Error: Add buddy error") unless response.is_a? Net::HTTPSuccess
184
191
  @logger.info "fetion send request to add #{mobile} as friend success"
185
- response.is_a? Net::HTTPSuccess
186
192
  end
187
193
 
188
194
  def logout
@@ -190,6 +196,8 @@ class Fetion
190
196
  msg = sip_create('R fetion.com.cn SIP-C/2.0', {'F' => @sid, 'I' => next_call, 'Q' => '2 R', 'X' => 0}, '') + FETION_SIPP
191
197
  curl_exec(next_url, @ssic, msg)
192
198
  response = curl_exec(next_url, @ssic, FETION_SIPP)
199
+
200
+ raise FetionException.new("Fetion Error: Logout error") unless response.is_a? Net::HTTPSuccess
193
201
  @logger.info "fetion logout success"
194
202
  end
195
203
 
@@ -244,7 +252,6 @@ class Fetion
244
252
 
245
253
  def next_call
246
254
  @next_call += 1
247
- @next_call
248
255
  end
249
256
  end
250
257
 
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.3.3"
8
+ s.version = "0.3.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"]
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.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang