Class: Fetion::Contact
- Inherits:
-
Object
- Object
- Fetion::Contact
- Defined in:
- lib/rfetion/contact.rb
Constant Summary collapse
- STATUS =
{ "400" => "在线", "300" => "离开", "600" => "繁忙", "0" => "脱机" }
Instance Attribute Summary collapse
-
#bid ⇒ Object
Returns the value of attribute bid.
-
#impresa ⇒ Object
Returns the value of attribute impresa.
-
#mobile_no ⇒ Object
Returns the value of attribute mobile_no.
-
#nickname ⇒ Object
Returns the value of attribute nickname.
-
#sid ⇒ Object
Returns the value of attribute sid.
-
#status ⇒ Object
Returns the value of attribute status.
-
#uid ⇒ Object
Returns the value of attribute uid.
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #display ⇒ Object
-
#initialize(options = {}) ⇒ Contact
constructor
A new instance of Contact.
- #to_json(*args) ⇒ Object
- #update(p, pr) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Contact
Returns a new instance of Contact.
30 31 32 33 34 35 |
# File 'lib/rfetion/contact.rb', line 30 def initialize(={}) @status = "0" .each do |key, value| send("#{key}=", value) end end |
Instance Attribute Details
#bid ⇒ Object
Returns the value of attribute bid.
4 5 6 |
# File 'lib/rfetion/contact.rb', line 4 def bid @bid end |
#impresa ⇒ Object
Returns the value of attribute impresa.
4 5 6 |
# File 'lib/rfetion/contact.rb', line 4 def impresa @impresa end |
#mobile_no ⇒ Object
Returns the value of attribute mobile_no.
4 5 6 |
# File 'lib/rfetion/contact.rb', line 4 def mobile_no @mobile_no end |
#nickname ⇒ Object
Returns the value of attribute nickname.
4 5 6 |
# File 'lib/rfetion/contact.rb', line 4 def nickname @nickname end |
#sid ⇒ Object
Returns the value of attribute sid.
4 5 6 |
# File 'lib/rfetion/contact.rb', line 4 def sid @sid end |
#status ⇒ Object
Returns the value of attribute status.
4 5 6 |
# File 'lib/rfetion/contact.rb', line 4 def status @status end |
#uid ⇒ Object
Returns the value of attribute uid.
4 5 6 |
# File 'lib/rfetion/contact.rb', line 4 def uid @uid end |
#uri ⇒ Object
Returns the value of attribute uri.
4 5 6 |
# File 'lib/rfetion/contact.rb', line 4 def uri @uri end |
Class Method Details
.parse(c) ⇒ Object
21 22 23 24 |
# File 'lib/rfetion/contact.rb', line 21 def self.parse(c) p = c.children.first self.new(:uid => c['id'], :sid => p['sid'], :uri => p['su'], :mobile_no => p['m'], :nickname => p['n'], :impresa => p['i'], :status => p['b'], :bid => p['l']) end |
.parse_buddy(b) ⇒ Object
17 18 19 |
# File 'lib/rfetion/contact.rb', line 17 def self.parse_buddy(b) self.new(:uid => b['i'], :uri => b['u'], :nickname => b['n'], :bid => b['l'].empty? ? "0" : b['l']) end |
.parse_request(c) ⇒ Object
26 27 28 |
# File 'lib/rfetion/contact.rb', line 26 def self.parse_request(c) self.new(:uri => c['uri'], :uid => c['user-id'], :sid => c['sid'], :mobile_no => c['mobile-no'], :nickname => c['nickname']) end |
Instance Method Details
#display ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rfetion/contact.rb', line 46 def display if self.impresa and !self.impresa.empty? "#{self.nickname}(#{self.impresa})" elsif self.nickname and !self.nickname.empty? self.nickname else if self.uri =~ /^(tel|sip):(\d+)/ $2 end end end |
#to_json(*args) ⇒ Object
13 14 15 |
# File 'lib/rfetion/contact.rb', line 13 def to_json(*args) {:uid => @uid, :sid => @sid, :bid => @bid, :uri => @uri, :mobile_no => @mobile_no, :nickname => @nickname, :impresa => @impresa, :status => @status, :display => display}.to_json(*args) end |
#update(p, pr) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/rfetion/contact.rb', line 37 def update(p, pr) self.sid = p["sid"] if p["sid"] and !p["sid"].empty? self.uri = p["su"] if p["su"] and !p["su"].empty? self.mobile_no = p["m"] if p["m"] and !p["m"].empty? self.nickname = p["n"] if p["n"] and !p["n"].empty? self.impresa = p["i"] if p["i"] and !p["i"].empty? self.status = pr["b"] if pr["b"] and !pr["b"].empty? end |