Sha256: 03dbac65753ade8b9453a05056a15fdda5cb3931f670104afbe1d3bf18858112

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require 'soap/header/simplehandler'

module AdWords

  class HeaderHandler < SOAP::Header::SimpleHandler
    def initialize(tag, value)
      super(XSD::QName.new(nil, tag))
      @tag = tag
      @value = value
    end

    #the initial handler from the sample was wrong, it generated 2 level of tags
    def on_simple_outbound
      @value
    end
  end

  class AdWordsCredentials
    attr_reader :handlers, :alternateUrl

    def getDefaults()
      cred = Hash.new
      IO.foreach("#{ENV['HOME']}/adwords.properties") {|line| addCredential(cred, line.split('=')) if !(line =~ /^#/)}
      return cred
    end

    def addCredential(cred, arr)
      cred[arr[0]] = arr[1].strip
    end

    def initialize(*parm)
      @handlers = []
      @alternateUrl = nil
      if parm[0] 
        credentials = parm[0]
      else
        credentials = getDefaults()
      end
      credentials.each {|key, value| @handlers << HeaderHandler.new(key, value) if !(key =~ /^alternateUrl/)}
      @alternateUrl = credentials['alternateUrl']
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adwords4r-11.0.2 lib/adwords4r/credentials.rb
adwords4r-11.0.3 lib/adwords4r/credentials.rb
adwords4r-11.1.0 lib/adwords4r/credentials.rb