Class: Fetion
- Inherits:
-
Object
- Object
- Fetion
- Defined in:
- lib/rfetion/fetion.rb,
lib/rfetion/contact.rb,
lib/rfetion/message.rb,
lib/rfetion/buddy_list.rb
Defined Under Namespace
Classes: AddBuddyException, BuddyList, Contact, GetContactsException, LoginException, Message, NoNonceException, NoUserException, PasswordError, PasswordMaxError, RegisterException, SendMsgException, SendSmsException, SetScheduleSmsException, SipcException
Constant Summary collapse
- FETION_URL =
'http://221.176.31.39/ht/sd.aspx'
- FETION_LOGIN_URL =
'https://uid.fetion.com.cn/ssiportal/SSIAppSignInV4.aspx?mobileno=%mobileno%sid=%sid%&domains=fetion.com.cn;m161.com.cn;www.ikuwa.cn&v4digest-type=1&v4digest=%digest%'
- FETION_PIC_URL =
'http://nav.fetion.com.cn/nav/GetPicCodeV4.aspx?algorithm=%algorithm'
- SIPP =
'SIPP'
- USER_AGENT =
"IIC2.0/PC 3.6.2020"
- VERSION =
"3.6.2020"
- DOMAIN =
"fetion.com.cn"
Instance Attribute Summary collapse
-
#add_requests ⇒ Object
readonly
Returns the value of attribute add_requests.
-
#algorithm ⇒ Object
Returns the value of attribute algorithm.
-
#alive ⇒ Object
Returns the value of attribute alive.
-
#buddy_lists ⇒ Object
readonly
Returns the value of attribute buddy_lists.
-
#call ⇒ Object
Returns the value of attribute call.
-
#guid ⇒ Object
Returns the value of attribute guid.
-
#impresa ⇒ Object
readonly
Returns the value of attribute impresa.
-
#machine_code ⇒ Object
Returns the value of attribute machine_code.
-
#mobile_no ⇒ Object
Returns the value of attribute mobile_no.
-
#nickname ⇒ Object
readonly
Returns the value of attribute nickname.
-
#password ⇒ Object
Returns the value of attribute password.
-
#pic ⇒ Object
Returns the value of attribute pic.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#receives ⇒ Object
readonly
Returns the value of attribute receives.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#seq ⇒ Object
Returns the value of attribute seq.
-
#sid ⇒ Object
Returns the value of attribute sid.
-
#ssic ⇒ Object
Returns the value of attribute ssic.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
-
.add_buddy(options) ⇒ Object
options mobile_no sid password friend_mobile friend_sip logger_level.
- .keep_alive(options) ⇒ Object
- .open(options, &block) ⇒ Object
-
.send_msg(options) ⇒ Object
options mobile_no sid password receivers content logger_level.
-
.send_sms(options) ⇒ Object
options mobile_no sid password receivers content logger_level.
-
.set_schedule_sms(options) ⇒ Object
options mobile_no sid password receivers content time logger_level.
Instance Method Summary collapse
-
#add_buddy(options) ⇒ Object
options friend_mobile friend_sip.
- #calc_response ⇒ Object
- #close_session ⇒ Object
- #contacts ⇒ Object
- #create_session(sipc_response) ⇒ Object
- #curl_exec(body = '', url = next_url, expected = SipcMessage::OK) ⇒ Object
-
#get_contact_info(options) ⇒ Object
options mobile_no sip.
- #get_contacts ⇒ Object
- #get_pic_certificate(algorithm) ⇒ Object
- #handle_contact_request(uid, options) ⇒ Object
-
#initialize ⇒ Fetion
constructor
A new instance of Fetion.
- #keep_alive ⇒ Object
- #logger_level=(level) ⇒ Object
- #login ⇒ Object
- #logout ⇒ Object
- #msg_received(message_response) ⇒ Object
- #next_alive ⇒ Object
- #next_call ⇒ Object
- #next_seq ⇒ Object
- #next_url(t = 's') ⇒ Object
- #parse_pic_certificate(response, algorithm) ⇒ Object
- #parse_ssic(response) ⇒ Object
- #pulse(expected = SipcMessage::OK) ⇒ Object
- #register ⇒ Object
- #register_first ⇒ Object
- #register_second ⇒ Object
- #self?(mobile_or_sid) ⇒ Boolean
- #send_msg(receiver, content) ⇒ Object
- #send_sms(receiver, content) ⇒ Object
- #session_connected(sipc_response) ⇒ Object
- #set_schedule_sms(receivers, content, time) ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize ⇒ Fetion
Returns a new instance of Fetion.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rfetion/fetion.rb', line 27 def initialize @call = @alive = @seq = 0 @buddy_lists = [Fetion::BuddyList.new("0", "未分组")] @contacts = [] @receives = [] @add_requests = [] @logger = Logger.new(STDOUT) @logger.level = Logger::INFO @guid = Guid.new.to_s end |
Instance Attribute Details
#add_requests ⇒ Object (readonly)
Returns the value of attribute add_requests.
16 17 18 |
# File 'lib/rfetion/fetion.rb', line 16 def add_requests @add_requests end |
#algorithm ⇒ Object
Returns the value of attribute algorithm.
15 16 17 |
# File 'lib/rfetion/fetion.rb', line 15 def algorithm @algorithm end |
#alive ⇒ Object
Returns the value of attribute alive.
15 16 17 |
# File 'lib/rfetion/fetion.rb', line 15 def alive @alive end |
#buddy_lists ⇒ Object (readonly)
Returns the value of attribute buddy_lists.
16 17 18 |
# File 'lib/rfetion/fetion.rb', line 16 def buddy_lists @buddy_lists end |
#call ⇒ Object
Returns the value of attribute call.
15 16 17 |
# File 'lib/rfetion/fetion.rb', line 15 def call @call end |
#guid ⇒ Object
Returns the value of attribute guid.
15 16 17 |
# File 'lib/rfetion/fetion.rb', line 15 def guid @guid end |
#impresa ⇒ Object (readonly)
Returns the value of attribute impresa.
16 17 18 |
# File 'lib/rfetion/fetion.rb', line 16 def impresa @impresa end |
#machine_code ⇒ Object
Returns the value of attribute machine_code.
15 16 17 |
# File 'lib/rfetion/fetion.rb', line 15 def machine_code @machine_code end |
#mobile_no ⇒ Object
Returns the value of attribute mobile_no.
15 16 17 |
# File 'lib/rfetion/fetion.rb', line 15 def mobile_no @mobile_no end |
#nickname ⇒ Object (readonly)
Returns the value of attribute nickname.
16 17 18 |
# File 'lib/rfetion/fetion.rb', line 16 def nickname @nickname end |
#password ⇒ Object
Returns the value of attribute password.
15 16 17 |
# File 'lib/rfetion/fetion.rb', line 15 def password @password end |
#pic ⇒ Object
Returns the value of attribute pic.
15 16 17 |
# File 'lib/rfetion/fetion.rb', line 15 def pic @pic end |
#pid ⇒ Object
Returns the value of attribute pid.
15 16 17 |
# File 'lib/rfetion/fetion.rb', line 15 def pid @pid end |
#receives ⇒ Object (readonly)
Returns the value of attribute receives.
16 17 18 |
# File 'lib/rfetion/fetion.rb', line 16 def receives @receives end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
16 17 18 |
# File 'lib/rfetion/fetion.rb', line 16 def response @response end |
#seq ⇒ Object
Returns the value of attribute seq.
15 16 17 |
# File 'lib/rfetion/fetion.rb', line 15 def seq @seq end |
#sid ⇒ Object
Returns the value of attribute sid.
15 16 17 |
# File 'lib/rfetion/fetion.rb', line 15 def sid @sid end |
#ssic ⇒ Object
Returns the value of attribute ssic.
15 16 17 |
# File 'lib/rfetion/fetion.rb', line 15 def ssic @ssic end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
16 17 18 |
# File 'lib/rfetion/fetion.rb', line 16 def uid @uid end |
#uri ⇒ Object
Returns the value of attribute uri.
15 16 17 |
# File 'lib/rfetion/fetion.rb', line 15 def uri @uri end |
Class Method Details
.add_buddy(options) ⇒ Object
options
mobile_no
sid
password
friend_mobile
friend_sip
logger_level
161 162 163 164 165 |
# File 'lib/rfetion/fetion.rb', line 161 def Fetion.add_buddy() Fetion.open() do add_buddy() end end |
.keep_alive(options) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/rfetion/fetion.rb', line 60 def Fetion.keep_alive() Fetion.open() do get_contacts pulse sleep(15) pulse p receives end end |
.open(options, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rfetion/fetion.rb', line 46 def Fetion.open(, &block) fetion = Fetion.new fetion.logger_level = .delete(:logger_level) || Logger::INFO fetion.mobile_no = .delete(:mobile_no) fetion.sid = .delete(:sid) fetion.password = .delete(:password) fetion.login fetion.register fetion.instance_eval &block fetion.logout end |
.send_msg(options) ⇒ Object
options
mobile_no
sid
password
receivers
content
logger_level
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rfetion/fetion.rb', line 104 def Fetion.send_msg() Fetion.open() do receivers = .delete(:receivers) content = .delete(:content) if receivers receivers = Array(receivers) receivers.collect! {|receiver| receiver.to_s} get_contacts contacts.flatten.each do |contact| if receivers.include? contact.mobile_no.to_s or receivers.any? { |receiver| contact.uri.index(receiver) } send_msg(contact.uri, content) end end send_msg(uri, content) if receivers.any? { |receiver| self? receiver } else send_msg(uri, content) end end end |
.send_sms(options) ⇒ Object
options
mobile_no
sid
password
receivers
content
logger_level
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rfetion/fetion.rb', line 77 def Fetion.send_sms() Fetion.open() do receivers = .delete(:receivers) content = .delete(:content) if receivers receivers = Array(receivers) receivers.collect! {|receiver| receiver.to_s} get_contacts contacts.flatten.each do |contact| if receivers.include? contact.mobile_no.to_s or receivers.any? { |receiver| contact.uri.index(receiver) } send_sms(contact.uri, content) end end send_sms(uri, content) if receivers.any? { |receiver| self? receiver } else send_sms(uri, content) end end end |
.set_schedule_sms(options) ⇒ Object
options
mobile_no
sid
password
receivers
content
time
logger_level
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/rfetion/fetion.rb', line 132 def Fetion.set_schedule_sms() Fetion.open() do receivers = .delete(:receivers) content = .delete(:content) time = .delete(:time) get_contacts if receivers receivers = Array(receivers) receivers.collect! {|receiver| receiver.to_s} new_receivers = contacts.flatten.collect do |contact| if receivers.include? contact.mobile_no.to_s or receivers.any? { |receiver| contact.uri.index(receiver) } contact.uri end end.compact! new_receivers << uri if receivers.any? { |receiver| self? receiver } set_schedule_sms(new_receivers, content, time) else set_schedule_sms([fetion.uri], content, time) end end end |
Instance Method Details
#add_buddy(options) ⇒ Object
options
friend_mobile
friend_sip
266 267 268 269 270 271 272 273 274 |
# File 'lib/rfetion/fetion.rb', line 266 def add_buddy() uri = [:friend_mobile] ? "tel:#{[:friend_mobile]}" : "sip:#{[:friend_sip]}" @logger.info "fetion send request to add #{uri} as friend" curl_exec(SipcMessage.add_buddy(self, )) pulse @logger.info "fetion send request to add #{uri} as friend success" end |
#calc_response ⇒ Object
527 528 529 530 531 532 533 534 535 536 537 538 |
# File 'lib/rfetion/fetion.rb', line 527 def calc_response encrypted_password = Digest::SHA1.hexdigest([@uid.to_i].pack("V*") + [Digest::SHA1.hexdigest("#{DOMAIN}:#{@password}")].pack("H*")) rsa_result = "4A026855890197CFDF768597D07200B346F3D676411C6F87368B5C2276DCEDD2" str = @nonce + [encrypted_password].pack("H*") + [rsa_result].pack("H*") rsa_key = OpenSSL::PKey::RSA.new exponent = OpenSSL::BN.new @key[-6..-1].hex.to_s modulus = OpenSSL::BN.new @key[0...-6].hex.to_s rsa_key.e = exponent rsa_key.n = modulus rsa_key.public_encrypt(str).unpack("H*").first.upcase end |
#close_session ⇒ Object
351 352 353 354 355 356 357 |
# File 'lib/rfetion/fetion.rb', line 351 def close_session @logger.info "fetion close session" curl_exec(SipcMessage.close_session(self)) @logger.info "fetion close session success" end |
#contacts ⇒ Object
548 549 550 551 552 553 554 |
# File 'lib/rfetion/fetion.rb', line 548 def contacts if @buddy_lists.size > 1 @buddy_lists.collect {|buddy_list| buddy_list.contacts}.flatten else @contacts end end |
#create_session(sipc_response) ⇒ Object
326 327 328 329 330 331 332 333 |
# File 'lib/rfetion/fetion.rb', line 326 def create_session(sipc_response) @logger.info "fetion create session" sipc_response = curl_exec(SipcMessage.create_session(self, sipc_response)) pulse unless sipc_response @logger.info "fetion create session success" end |
#curl_exec(body = '', url = next_url, expected = SipcMessage::OK) ⇒ Object
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/rfetion/fetion.rb', line 418 def curl_exec(body='', url=next_url, expected=SipcMessage::OK) @logger.debug "fetion curl exec" @logger.debug "url: #{url}" @logger.debug "body: #{body}" uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) headers = {'Content-Type' => 'application/oct-stream', 'Pragma' => "xz4BBcV#{@guid}", 'User-Agent' => USER_AGENT, 'Cookie' => "ssic=#{@ssic}", 'Content-Length' => body.length.to_s} response = http.request_post(uri.request_uri, body, headers) @logger.debug "response: #{response.inspect}" @logger.debug "response body: #{response.body}" @logger.debug "fetion curl exec complete" raise FetionException.new("request_url: #{url}, request_body: #{body}, response: #{response.code}, response_body: #{response.body}") unless Net::HTTPSuccess === response sipc_response = SipcMessage.sipc_response(response.body, self) if sipc_response raise Fetion::SipcException.new(sipc_response, "request_url: #{url}, request_body: #{body}, sipc_response: #{sipc_response}") unless sipc_response.class == expected if sipc_response.first_line =~ /401/ # unauthorized, get nonce, key and signature raise Fetion::NoNonceException.new("No nonce found") unless response.body =~ /nonce="(.*?)",key="(.*?)",signature="(.*?)"/ @nonce = $1 @key = $2 @signature = $3 @response = calc_response @logger.debug "nonce: #{@nonce}" @logger.debug "key: #{@key}" @logger.debug "signature: #{@signature}" @logger.debug "response: #{@response}" end create_session(sipc_response) if sipc_response.contain?('I') session_connected(sipc_response) if sipc_response.contain?('O') if sipc_response.contain?('M') = sipc_response.sections.select {|section| section =~ /^M/} .each do || , = .split(/\r\n\r\n/) sip = sent_at = length = nil .split(/\r\n/).each do |line| case line when /^F: sip:(.+)/ then sip = $1 when /^D: (.+)/ then sent_at = Time.parse($1) when /^L: (\d+)/ then length = $1.to_i end end text = .slice(0, length) @receives << Fetion::Message.new(sip, sent_at, text) msg_received() end end response.body.scan(%r{<results>.*?</results>}).each do |results| doc = Nokogiri::XML(results) doc.root.xpath("/results/user-info/personal").each do |personal_element| @nickname = personal_element['nickname'] @impresa = personal_element['impresa'] end doc.root.xpath("/results/user-info/contact-list/buddy-lists/buddy-list").each do |buddy_list| @buddy_lists << Fetion::BuddyList.parse(buddy_list) end doc.root.xpath("/results/user-info/contact-list/buddies/b").each do |buddy| contact = Fetion::Contact.parse_buddy(buddy) @buddy_lists.find {|buddy_list| buddy_list.bid == contact.bid}.add_contact(contact) end end response.body.scan(%r{<events>.*?</events>}).each do |events| doc = Nokogiri::XML(events) doc.root.xpath("/events/event[@type='PresenceChanged']/contacts/c").each do |c| unless self.uid == c['id'] contact = contacts.find {|contact| contact.uid == c['id']} if contact contact.update(c.children.first, c.children.last) else contact = Fetion::Contact.parse(c) if @buddy_lists.size > 1 @buddy_lists.find {|buddy_list| buddy_list.bid == contact.bid}.add_contact(contact) else @contacts << contact end end end end doc.root.xpath("/events/event[@type='AddBuddyApplication']/application").each do |application| @add_requests << get_contact_info(:uri => application['uri']) end end end sipc_response end |
#get_contact_info(options) ⇒ Object
options
mobile_no
sip
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/rfetion/fetion.rb', line 279 def get_contact_info() uri = if [:mobile_no] "tel:#{[:mobile_no]}" elsif [:sip] "sip:#{[:sip]}" else "uri:#{[:uri]}" end @logger.info "fetion get contact info of #{uri}" curl_exec(SipcMessage.get_contact_info(self, uri)) sipc_response = pulse results = sipc_response.sections.first.scan(%r{<results>.*?</results>}).first doc = Nokogiri::XML(results) c = doc.root.xpath("/results/contact").first contact = Contact.parse_request(c) @logger.info "fetion get contact info of #{uri} success" contact end |
#get_contacts ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/rfetion/fetion.rb', line 218 def get_contacts @logger.info "fetion get contacts" curl_exec(SipcMessage.get_group_list(self)) curl_exec(SipcMessage.presence(self)) curl_exec(SipcMessage.get_group_topic(self)) curl_exec(SipcMessage.get_address_list(self)) pulse @logger.info "fetion get contacts success" end |
#get_pic_certificate(algorithm) ⇒ Object
369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/rfetion/fetion.rb', line 369 def get_pic_certificate(algorithm) @logger.info "fetion get pic" uri = URI.parse(FETION_PIC_URL.sub('%algorithm', algorithm)) http = Net::HTTP.new(uri.host, uri.port) headers = {'User-Agent' => USER_AGENT} response = http.request_get(uri.request_uri, headers) pic_certificate = parse_pic_certificate(response, algorithm) @logger.info "fetion get pic success" pic_certificate end |
#handle_contact_request(uid, options) ⇒ Object
359 360 361 362 363 364 365 366 367 |
# File 'lib/rfetion/fetion.rb', line 359 def handle_contact_request(uid, ) @logger.info "fetion handle contact request" contact = @add_requests.find {|contact| contact.uid == uid} curl_exec(SipcMessage.handle_contact_request(self, contact, )) pulse @logger.info "fetion handle contact request success" end |
#keep_alive ⇒ Object
300 301 302 303 304 305 306 |
# File 'lib/rfetion/fetion.rb', line 300 def keep_alive @logger.info "fetion keep alive" curl_exec(SipcMessage.keep_alive(self)) @logger.info "fetion keep alive success" end |
#logger_level=(level) ⇒ Object
42 43 44 |
# File 'lib/rfetion/fetion.rb', line 42 def logger_level=(level) @logger.level = level end |
#login ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/rfetion/fetion.rb', line 167 def login @logger.info "fetion login" if @mobile_no url = FETION_LOGIN_URL.sub('%mobileno%', @mobile_no).sub('sid=%sid%', '') else url = FETION_LOGIN_URL.sub('%sid%', @sid).sub('mobileno=%mobileno%', '') end url.sub!('%digest%', Digest::SHA1.hexdigest("#{DOMAIN}:#{@password}")) url += "&pid=#@pid&pic=#@pic&algorithm=#@algorithm" if @pic uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE headers = {'User-Agent' => USER_AGENT} response = http.request_get(uri.request_uri, headers) parse_ssic(response) @logger.info "fetion login success" end |
#logout ⇒ Object
317 318 319 320 321 322 323 324 |
# File 'lib/rfetion/fetion.rb', line 317 def logout @logger.info "fetion logout" curl_exec(SipcMessage.logout(self)) pulse @logger.info "fetion logout success" end |
#msg_received(message_response) ⇒ Object
343 344 345 346 347 348 349 |
# File 'lib/rfetion/fetion.rb', line 343 def msg_received() @logger.info "fetion msg received" curl_exec(SipcMessage.msg_received(self, )) @logger.info "fetion msg received success" end |
#next_alive ⇒ Object
523 524 525 |
# File 'lib/rfetion/fetion.rb', line 523 def next_alive @alive += 1 end |
#next_call ⇒ Object
515 516 517 |
# File 'lib/rfetion/fetion.rb', line 515 def next_call @call += 1 end |
#next_seq ⇒ Object
519 520 521 |
# File 'lib/rfetion/fetion.rb', line 519 def next_seq @seq += 1 end |
#next_url(t = 's') ⇒ Object
511 512 513 |
# File 'lib/rfetion/fetion.rb', line 511 def next_url(t = 's') FETION_URL + "?t=#{t}&i=#{next_seq}" end |
#parse_pic_certificate(response, algorithm) ⇒ Object
411 412 413 414 415 416 |
# File 'lib/rfetion/fetion.rb', line 411 def parse_pic_certificate(response, algorithm) raise FetionException.new('Get verification code failed.') unless Net::HTTPSuccess === response doc = Nokogiri::XML(response.body) certificate = doc.root.xpath('/results/pic-certificate').first PicCertificate.parse(certificate, algorithm) end |
#parse_ssic(response) ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/rfetion/fetion.rb', line 382 def parse_ssic(response) raise Fetion::PasswordError.new('帐号或密码不正确') if Net::HTTPUnauthorized === response raise Fetion::PasswordMaxError.new('您已连续输入错误密码,为了保障您的帐户安全,请输入图形验证码:') if Net::HTTPClientError === response raise Fetion::LoginException.new('Login failed.') unless Net::HTTPSuccess === response raise Fetion::LoginException.new('No ssic found in cookie.') unless response['set-cookie'] =~ /ssic=(.*);/ @ssic = $1 @logger.debug response.body doc = Nokogiri::XML(response.body) results = doc.root @status_code = results["status-code"] user = results.children.first @user_status = user['user-status'] @uri = user['uri'] @mobile_no = user['mobile-no'] @uid = user['user-id'] if @uri =~ /sip:(\d+)@(.+);/ @sid = $1 end @logger.debug "ssic: " + @ssic @logger.debug "status_code: " + @status_code @logger.debug "user_status: " + @user_status @logger.debug "uri: " + @uri @logger.debug "mobile_no: " + @mobile_no @logger.debug "uid: " + @uid @logger.debug "sid: " + @sid end |
#pulse(expected = SipcMessage::OK) ⇒ Object
308 309 310 311 312 313 314 315 |
# File 'lib/rfetion/fetion.rb', line 308 def pulse(expected=SipcMessage::OK) @logger.info "fetion pulse" sipc_response = curl_exec(SIPP, next_url, expected) @logger.info "fetion pulse success" sipc_response end |
#register ⇒ Object
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/rfetion/fetion.rb', line 188 def register @logger.info "fetion register" call = next_call register_first register_second call = next_call @logger.info "fetion register success" end |
#register_first ⇒ Object
199 200 201 202 203 204 205 206 207 |
# File 'lib/rfetion/fetion.rb', line 199 def register_first @logger.debug "fetion register first" curl_exec(SIPP, next_url('i')) curl_exec(SipcMessage.register_first(self)) pulse(SipcMessage::Unauthoried) @logger.debug "fetion register first success" end |
#register_second ⇒ Object
209 210 211 212 213 214 215 216 |
# File 'lib/rfetion/fetion.rb', line 209 def register_second @logger.debug "fetion register second" curl_exec(SipcMessage.register_second(self)) pulse @logger.debug "fetion register second success" end |
#self?(mobile_or_sid) ⇒ Boolean
544 545 546 |
# File 'lib/rfetion/fetion.rb', line 544 def self?(mobile_or_sid) mobile_or_sid == @mobile_no or mobile_or_sid == @sid end |
#send_msg(receiver, content) ⇒ Object
230 231 232 233 234 235 236 237 |
# File 'lib/rfetion/fetion.rb', line 230 def send_msg(receiver, content) @logger.info "fetion send cat msg to #{receiver}" curl_exec(SipcMessage.send_cat_msg(self, receiver, content)) pulse @logger.info "fetion send cat msg to #{receiver} success" end |
#send_sms(receiver, content) ⇒ Object
239 240 241 242 243 244 245 246 |
# File 'lib/rfetion/fetion.rb', line 239 def send_sms(receiver, content) @logger.info "fetion send cat sms to #{receiver}" curl_exec(SipcMessage.send_cat_sms(self, receiver, content)) pulse(SipcMessage::Send) @logger.info "fetion send cat sms to #{receiver} success" end |
#session_connected(sipc_response) ⇒ Object
335 336 337 338 339 340 341 |
# File 'lib/rfetion/fetion.rb', line 335 def session_connected(sipc_response) @logger.info "fetion session connected" curl_exec(SipcMessage.session_connected(self, sipc_response)) @logger.info "fetion session connected success" end |
#set_schedule_sms(receivers, content, time) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/rfetion/fetion.rb', line 248 def set_schedule_sms(receivers, content, time) receivers = Array(receivers) time = time.is_a?(Time) ? time : Time.parse(time) now = Time.now one_year = Time.local(now.year + 1, now.month, now.day, now.hour, now.min, now.sec) raise SetScheduleSmsException.new("Can't schedule send sms to more than 64 receivers") if receivers.size > 64 raise SetScheduleSmsException.new("Schedule time must between #{(now + 600).strftime('%Y-%m-%d %H:%M:%S')} and #{one_year.strftime('%Y-%m-%d %H:%M:%S')}") if time < (now + 600) or time > one_year @logger.info "fetion schedule send sms to #{receivers.join(', ')}" curl_exec(SipcMessage.set_schedule_sms(self, receivers, content, time.strftime('%Y-%m-%d %H:%M:%S'))) pulse @logger.info "fetion schedule send sms to #{receivers.join(', ')} success" end |
#to_json(*args) ⇒ Object
38 39 40 |
# File 'lib/rfetion/fetion.rb', line 38 def to_json(*args) {:mobile_no => @mobile_no, :sid => @sid, :uid => @uid, :uri => @uri, :status_code => @status_code, :buddy_lists => @buddy_lists, :receives => @receives, :add_requests => @add_requests, :nickname => @nickname, :impresa => @impresa, :ssic => @ssic, :guid => @guid, :call => @call, :seq => @seq, :alive => @alive}.to_json(*args) end |