Class: GoogleClient::Contact

Inherits:
Object
  • Object
show all
Defined in:
lib/google_client/contact.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Contact

Returns a new instance of Contact.



11
12
13
14
15
16
17
# File 'lib/google_client/contact.rb', line 11

def initialize(params = {})
  @id = params[:id]
  @name = params[:name]
  @email = params[:email]
  @phone_number = params[:phone_number]
  @user = params[:user]
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



7
8
9
# File 'lib/google_client/contact.rb', line 7

def email
  @email
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/google_client/contact.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/google_client/contact.rb', line 6

def name
  @name
end

#phone_numberObject

Returns the value of attribute phone_number.



8
9
10
# File 'lib/google_client/contact.rb', line 8

def phone_number
  @phone_number
end

#userObject

Returns the value of attribute user.



9
10
11
# File 'lib/google_client/contact.rb', line 9

def user
  @user
end

Class Method Details

.build_contact(data, user = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/google_client/contact.rb', line 29

def build_contact(data, user = nil)
  id = begin
    data["id"]["$t"].split("base/").last
  rescue
    nil
  end
  name = begin
    data["title"]["$t"].split("full/").last
  rescue
    ""
  end
  email = begin
    data["gd$email"].collect { |address| address.select { |item| item["address"] }.values }.flatten
  rescue
    []
  end
  phone_number = begin
    data["gd$phoneNumber"].collect { |number| number.select { |item| item["$t"] }.values }.flatten
  rescue
    []
  end
  Contact.new({:name => name, :email => email, :phone_number => phone_number, :user => user})
end

Instance Method Details

#saveObject



24
25
26
# File 'lib/google_client/contact.rb', line 24

def save

end

#to_sObject



19
20
21
# File 'lib/google_client/contact.rb', line 19

def to_s
  "#{self.class.name} => { name: #{@name}, email: #{@email}, :phone_number => #{@phone_number} }"
end