Sha256: 8ea5a55a53b4f5cf371d9356e4437018c5c828d954c3493fff65665147ce9b5e

Contents?: true

Size: 1.32 KB

Versions: 14

Compression:

Stored size: 1.32 KB

Contents

require 'hashie'

module GoogleContactsApi
  # Base class for Group and Contact
  class Result < Hashie::Mash
    # Note that the title is really just the (full) name
    # ":" replaced with $, element content is keyed with $t
    
    # These are the accessors we can write
    # :id, :title, :updated, :content
    
    attr_reader :api
    # Populate from a single result Hash/Hashie
    def initialize(source_hash = nil, default = nil, api = nil, &blk)
      @api = api if api
      super(source_hash, default, &blk)
    end

    # TODO: Conditional retrieval? There might not be an etag in the
    # JSON representation, there is in the XML representation
    def etag
    end

    def id
      _id = self["id"]
      _id ? _id["$t"] : nil
    end
    
    def title
      _title = self["title"]
      _title ? _title["$t"] : nil
    end
    
    def content
      _content = self["content"]
      _content ? _content["$t"] : nil
    end
    
    def updated
      _updated = self["updated"]
      _updated ? DateTime.parse(_updated["$t"]) : nil
    end
    
    # Returns the array of categories, as category is an array for Hashie.
    # There is a scheme and a term.
    def categories
      category
    end
    
    def deleted?
      raise NotImplementedError
    end
    
    def inspect
      "<#{self.class}: #{title}>"
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
google_contacts_api-0.4.1 lib/google_contacts_api/result.rb
google_contacts_api-0.4.0 lib/google_contacts_api/result.rb
google_contacts_api-0.3.3 lib/google_contacts_api/result.rb
google_contacts_api-0.3.2 lib/google_contacts_api/result.rb
google_contacts_api-0.3.1 lib/google_contacts_api/result.rb
google_contacts_api-0.3.0 lib/google_contacts_api/result.rb
google_contacts_api-0.2.7 lib/google_contacts_api/result.rb
google_contacts_api-0.2.6 lib/google_contacts_api/result.rb
google_contacts_api-0.2.5 lib/google_contacts_api/result.rb
google_contacts_api-0.2.4 lib/google_contacts_api/result.rb
google_contacts_api-0.2.3 lib/google_contacts_api/result.rb
google_contacts_api-0.2.2 lib/google_contacts_api/result.rb
google_contacts_api-0.2.1 lib/google_contacts_api/result.rb
google_contacts_api-0.2.0 lib/google_contacts_api/result.rb