lib/gattica/engine.rb
# Returns the list of accounts the user has access to. A user may have
# multiple accounts on Google Analytics and each account may have multiple
# profiles. You need the profile_id in order to get info from GA. If you
# don't know the profile_id then use this method to get a list of all them.
# Then set the profile_id of your instance and you can make regular calls
# from then on.
#
#   ga = Gattica.new({token: 'oauth2_token'})
#   ga.accounts
#   # you parse through the accounts to find the profile_id you need
#   ga.profile_id = 12345678
#   # now you can perform a regular search, see Gattica::Engine#get
#
# If you pass in a profile id when you instantiate Gattica::Search then you won't need to
# get the accounts and find a profile_id - you apparently already know it!
#
# See Gattica::Engine#get to see how to get some data.
Returns the list of accounts the user has access to. A user may have
multiple accounts on Google Analytics and each account may have multiple
profiles. You need the profile_id in order to get info from GA. If you
don't know the profile_id then use this method to get a list of all them.
Then set the profile_id of your instance and you can make regular calls
from then on.

ga = Gattica.new({token: 'oauth2_token'})
ga.accounts
you parse through the accounts to find the profile_id you need
ga.profile_id = 12345678
now you can perform a regular search, see Gattica::Engine#get

If you pass in a profile id when you instantiate Gattica::Search then you won't need to
get the accounts and find a profile_id - you apparently already know it!

See Gattica::Engine#get to see how to get some data.
Returns the list of accounts the user has access to . A user may have multiple accounts on Google Analytics and each account may have multiple profiles . You need the profile_id in order to get info from GA . If you don ' t know the profile_id then use this method to get a list of all them . Then set the profile_id of your instance and you can make regular calls from then on . ga = Gattica . new ( { token : ' oauth2_token ' } ) ga . accounts you parse through the accounts to find the profile_id you need ga . profile_id = 12345678 now you can perform a regular search see Gattica :: Engine#get If you pass in a profile id when you instantiate Gattica :: Search then you won ' t need to get the accounts and find a profile_id - you apparently already know it! See Gattica :: Engine#get to see how to get some data .
def accounts
      if @user_accounts.nil?
        create_http_connection('www.googleapis.com')
        response = do_http_get("/analytics/v3/management/accounts/~all/webproperties/~all/profiles?max-results=10000&fields=items(id,name,updated,accountId,webPropertyId,eCommerceTracking,currency,timezone,siteSearchQueryParameters)")
        json = decompress_gzip(response)
        @user_accounts = json['items'].collect { |profile_json| Account.new(profile_json) }
        response = do_http_get("/analytics/v3/management/accounts/~all/webproperties/~all/profiles/~all/goals?max-results=10000&fields=items(profileId,name,value,active,type,updated)")
        json = decompress_gzip(response)
        @user_accounts.each do |ua|
          json['items'].each { |e| ua.set_goals(e) }
        end unless (json.blank?)
        response = do_http_get("/analytics/v3/management/accounts?max-results=10000&fields=items(id,name)")
        json = decompress_gzip(response)
        @user_accounts.each do |ua|
          json['items'].each { |e| ua.set_account_name(e) }
        end
      end
      @user_accounts
    end
def accounts if @user_accounts . nil? create_http_connection ( 'www.googleapis.com' ) response = do_http_get ( "/analytics/v3/management/accounts/~all/webproperties/~all/profiles?max-results=10000&fields=items(id,name,updated,accountId,webPropertyId,eCommerceTracking,currency,timezone,siteSearchQueryParameters)" ) json = decompress_gzip ( response ) @user_accounts = json [ 'items' ] . collect { | profile_json | Account . new ( profile_json ) } response = do_http_get ( "/analytics/v3/management/accounts/~all/webproperties/~all/profiles/~all/goals?max-results=10000&fields=items(profileId,name,value,active,type,updated)" ) json = decompress_gzip ( response ) @user_accounts . each do | ua | json [ 'items' ] . each { | e | ua . set_goals ( e ) } end unless ( json . blank? ) response = do_http_get ( "/analytics/v3/management/accounts?max-results=10000&fields=items(id,name)" ) json = decompress_gzip ( response ) @user_accounts . each do | ua | json [ 'items' ] . each { | e | ua . set_account_name ( e ) } end end @user_accounts end
Returns the list of accounts the user has access to.
Returns the list of accounts the user has access to .
# Get profiles # Fill in the goals # Fill in the account name