Sha256: 408dc6a0e40ccd252187015a4fd76a96dfb44f103e35ccbb1a4a2715c2bc2287

Contents?: true

Size: 839 Bytes

Versions: 3

Compression:

Stored size: 839 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)
    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

3 entries across 3 versions & 1 rubygems

Version Path
legato-0.0.6 lib/legato/user.rb
legato-0.0.5 lib/legato/user.rb
legato-0.0.4 lib/legato/user.rb