Skip to content

Instantly share code, notes, and snippets.

@reagent
Created March 6, 2009 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reagent/74784 to your computer and use it in GitHub Desktop.
Save reagent/74784 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'graft'
require 'time'
class AccountList
include Graft::Model
attribute :id
attribute :author, :from => 'author/name'
attribute :count, :from => 'openSearch:totalResults'
attribute :per_page, :from => 'openSearch:itemsPerPage'
def accounts
@accounts ||= (self.document / 'entry').map {|e| Account.new(e) }
end
end
class Account
include Graft::Model
attribute :table_id, :from => 'dxp:tableId'
attribute :updated
def id
table_id.sub(/^ga:/, '')
end
def updated_at
Time.parse(updated)
end
end
al = AccountList.new(File.read('google.xml'))
puts "Account list:"
puts " id: #{al.id}"
puts " author: #{al.author}"
puts " count: #{al.count}"
puts "records per page: #{al.per_page}"
account = al.accounts.first
puts ''
puts "First entry"
puts "id: #{account.id}"
puts "updated_at: #{account.updated_at.strftime('%Y-%m-%d %H:%I:%S')}"
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:dxp='http://schemas.google.com/analytics/2009'>
<id>http://www.google.com/analytics/feeds/accounts/ga@viget.com</id>
<updated>2009-03-03T07:22:11.000-08:00</updated>
<title type='text'>Profile list for ga@viget.com</title>
<link rel='self' type='application/atom+xml' href='http://www.google.com/analytics/feeds/accounts/ga@viget.com'/>
<author>
<name>Google Analytics</name>
</author>
<generator version='1.0'>Google Analytics</generator>
<openSearch:totalResults>106</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>106</openSearch:itemsPerPage>
<entry>
<id>http://www.google.com/analytics/feeds/accounts/ga:250721</id>
<updated>2008-07-21T14:05:57.000-07:00</updated>
<title type='text'>z. Historical - www.squidoo.com</title>
<dxp:tableId>ga:250721</dxp:tableId>
<dxp:property name='ga:accountId' value='185209'/>
<dxp:property name='ga:accountName' value='Squidoo Beta'/>
<dxp:property name='ga:profileId' value='250721'/>
<dxp:property name='ga:webPropertyId' value='UA-185209-2'/>
</entry>
</feed>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment