Sha256: 266baad9a69ba3db36737db2cab55d2b44ac9b912a5f3532484457399e8e4060

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

module Garb
  class Profile
    
    attr_reader :table_id, :title, :account_name, :account_id, :web_property_id
    
    class Property
      include HappyMapper
      
      tag 'property'
      namespace 'http://schemas.google.com/analytics/2009'
      
      attribute :name, String
      attribute :value, String

      def instance_name
        Garb.from_google_analytics(name)
      end
    end

    class Entry
      include HappyMapper
      
      tag 'entry'

      element :title, String
      element :tableId, String, :namespace => 'http://schemas.google.com/analytics/2009'

      has_many :properties, Property
    end

    def initialize(entry)
      @title = entry.title
      @table_id = entry.tableId

      entry.properties.each do |p|
        instance_variable_set :"@#{p.instance_name}", p.value
      end
    end

    def id
      Garb.from_google_analytics(@table_id)
    end

    def self.all
      url = "https://www.google.com/analytics/feeds/accounts/default"
      response = DataRequest.new(url).send_request      
      profiles = Entry.parse(response.body).map {|entry| new(entry)}
      ProfileArray.new(profiles)
    end

    def self.first(id)
      all.detect {|profile| profile.id == id || profile.web_property_id == id }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
garb-0.5.1 lib/garb/profile.rb
garb-0.5.0 lib/garb/profile.rb