Sha256: 3722e6b91e62763342c2309be848634d20c92122a721a0758c77d3e0a335b938

Contents?: true

Size: 861 Bytes

Versions: 7

Compression:

Stored size: 861 Bytes

Contents

module Legato
  class User
    attr_accessor :access_token, :api_key

    def initialize(token, api_key = nil)
      self.access_token = token
      self.api_key = api_key
    end

    URL = "https://www.googleapis.com/analytics/v3/data/ga"

    def request(query)
      raw_response = if api_key
        # oauth 1 + api key
        query_string = URI.escape(query.to_query_string, '<>') # may need to add !~@

        access_token.get(URL + query_string + "&key=#{api_key}")
      else
        # oauth 2
        access_token.get(URL, :params => query.to_params)
      end

      Response.new(raw_response, query.instance_klass)
    end

    # Management
    def accounts
      Management::Account.all(self)
    end

    def web_properties
      Management::WebProperty.all(self)
    end

    def profiles
      Management::Profile.all(self)
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
legato-0.3.0 lib/legato/user.rb
legato-0.2.0 lib/legato/user.rb
legato-0.1.0 lib/legato/user.rb
legato-0.0.10 lib/legato/user.rb
legato-0.0.9 lib/legato/user.rb
legato-0.0.8 lib/legato/user.rb
legato-0.0.7 lib/legato/user.rb