require 'hawk/http'

module GSA

  class Client < Hawk::HTTP
    def initialize(hostname:, username:, password:)
      super(hostname)

      @username = username
      @password = password

      authenticate!
    end

    def authenticate!
      body = request('POST', '/accounts/ClientLogin', auth: false, Email: @username, Passwd: @password)
      if body =~ /^Auth=(\w+)/
        @token = $1
      else
        raise Error, "Authentication failed: #{body}"
      end
    end

    def inspect
      super.sub(/>$/, ", auth: #@token>")
    end

    def logs
      get '/feeds/searchLog'
    end

    protected
      def parse(body)
        Nokogiri.parse(body)
      end

      def build_request_options_from(method, options)
        unless options.delete(:auth) === false
          options[:headers] ||= {}
          options[:headers]['Authorization'] = "GoogleLogin auth=#@token"
          options[:headers]['Content-Type']  = 'application/atom+xml'
        end

        super
      end
  end

end

# GSA Admin API Docs: http://www.google.com/support/enterprise/static/gsa/docs/admin/74/gsa_doc_set/acapi_protocol/acapi_protocol.html
#
require 'hawk/http'

module GSA

  class Client < Hawk::HTTP
    def initialize(hostname:, username:, password:)
      super(hostname)

      @username = username
      @password = password

      authenticate!
    end

    def authenticate!
      body = request('POST', '/accounts/ClientLogin', auth: false, Email: @username, Passwd: @password)
      if body =~ /^Auth=(\w+)/
        @token = $1
      else
        raise Error, "Authentication failed: #{body}"
      end
    end

    def inspect
      super.sub(/>$/, ", auth: #@token>")
    end

    def logs
      get '/feeds/searchLog'
    end

    protected
      def parse(body)
        Nokogiri.parse(body)
      end

      def build_request_options_from(method, options)
        unless options.delete(:auth) === false
          options[:headers] ||= {}
          options[:headers]['Authorization'] = "GoogleLogin auth=#@token"
          options[:headers]['Content-Type']  = 'application/atom+xml'
        end

        super
      end
  end

end

Add pointer to GSA docs
Add pointer to GSA docs