Sha256: 6ae61f9e41e8660db82eabb111ee06e27e1080b0a1f13ddfa3e9db2ae742b661

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

module GoogleClient

  class Contact

    attr_reader   :id
    attr_accessor :name
    attr_accessor :email
    attr_accessor :phone_number
    attr_accessor :user

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

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


    def save

    end

    class << self
      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
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
google_client-0.2.1 lib/google_client/contact.rb
google_client-0.2.0 lib/google_client/contact.rb
google_client-0.1.0 lib/google_client/contact.rb