lib/legato/management/profile.rb in legato-0.3.3 vs lib/legato/management/profile.rb in legato-0.4.0
- old
+ new
@@ -11,28 +11,43 @@
def path
"/accounts/#{account_id}/webproperties/#{web_property_id}/profiles/#{id}"
end
- attr_accessor :id, :name, :web_property_id, :account_id, :user, :attributes
+ GA_ATTRIBUTES = {
+ :id => 'id',
+ :name => 'name',
+ :account_id => 'accountId',
+ :web_property_id => 'webPropertyId'
+ }
+ attr_accessor *GA_ATTRIBUTES.keys
+ attr_accessor :user, :attributes
+
def initialize(attributes, user)
self.user = user
- self.id = attributes['id']
- self.name = attributes['name']
- self.account_id = attributes['accountId']
- self.web_property_id = attributes['webPropertyId']
- ['id', 'name', 'accountId', 'webPropertyId'].each { |key| attributes.delete(key) }
+ GA_ATTRIBUTES.each do |key,string_key|
+ self.send("#{key}=", attributes.delete(string_key) || attributes.delete(key))
+ end
+
self.attributes = attributes
end
def self.for_account(account)
all(account.user, account.path+'/webproperties/~all/profiles')
end
def self.for_web_property(web_property)
all(web_property.user, web_property.path+'/profiles')
+ end
+
+ def account
+ @account ||= Account.from_child(self)
+ end
+
+ def web_property
+ @web_property ||= WebProperty.from_child(self)
end
def goals
Goal.for_profile(self)
end