Sha256: 305be32522e1bf73a7b1fa447e8e43e3470647fa1ad7ebf0111320a4239a7915

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Garb
  class Profile
    
    attr_reader :table_id, :title, :account_name, :email
    
    class Property
      include HappyMapper
      
      tag 'property'
      namespace 'dxp'
      
      attribute :name, String
      attribute :value, String
    end

    class Entry
      include HappyMapper
      
      tag 'entry'
      
      element :id, Integer
      element :title, String
      element :tableId, String, :namespace => 'dxp'
      
      # has_one :table_id, TableId
      has_many :properties, Property
    end

    def initialize(entry, email=nil)
      @email = Session.email(email)
      @title = entry.title
      @table_id = entry.tableId
      @account_name = entry.properties.detect{|p| p.name == 'ga:accountName'}.value
    end

    def id
      @table_id.sub(/^ga:/, '')
    end

    def self.all(email=nil)
      email = Session.email(email)
      url = "https://www.google.com/analytics/feeds/accounts/#{email}"
      response = DataRequest.new(url).send_request(email)
      Entry.parse(response.body).map {|e| Garb::Profile.new(e, email)}
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jonuts-garb-0.2.3 lib/garb/profile.rb