module GoogleAdsSavon::Model

GoogleAdsSavon::Model

Model for SOAP service oriented applications.

Public Class Methods

extended(base) click to toggle source
# File lib/ads_savon/model.rb, line 8
def self.extended(base)
  base.setup
end

Public Instance Methods

actions(*actions) click to toggle source

Accepts one or more SOAP actions and generates both class and instance methods named after the given actions. Each generated method accepts an optional SOAP body Hash and a block to be passed to GoogleAdsSavon::Client#request and executes a SOAP request.

# File lib/ads_savon/model.rb, line 20
def actions(*actions)
  actions.each do |action|
    define_class_action(action)
    define_instance_action(action)
  end
end
setup() click to toggle source
# File lib/ads_savon/model.rb, line 12
def setup
  class_action_module
  instance_action_module
end

Private Instance Methods

basic_auth(login, password) click to toggle source

Sets basic auth login and password.

# File lib/ads_savon/model.rb, line 77
def basic_auth(login, password)
  client.http.auth.basic(login, password)
end
class_action_module() click to toggle source

Class methods.

# File lib/ads_savon/model.rb, line 48
def class_action_module
  @class_action_module ||= Module.new do

    # Returns the memoized <tt>GoogleAdsSavon::Client</tt>.
    def client(&block)
      @client ||= GoogleAdsSavon::Client.new(&block)
    end

    # Sets the SOAP endpoint to the given +uri+.
    def endpoint(uri)
      client.wsdl.endpoint = uri
    end

    # Sets the target namespace.
    def namespace(uri)
      client.wsdl.namespace = uri
    end

    # Sets the WSDL document to the given +uri+.
    def document(uri)
      client.wsdl.document = uri
    end

    # Sets the HTTP headers.
    def headers(headers)
      client.http.headers = headers
    end

    # Sets basic auth +login+ and +password+.
    def basic_auth(login, password)
      client.http.auth.basic(login, password)
    end

    # Sets WSSE auth credentials.
    def wsse_auth(*args)
      client.wsse.credentials(*args)
    end

  end.tap { |mod| extend(mod) }
end
client(&block) click to toggle source

Returns the memoized GoogleAdsSavon::Client.

# File lib/ads_savon/model.rb, line 52
def client(&block)
  @client ||= GoogleAdsSavon::Client.new(&block)
end
define_class_action(action) click to toggle source

Defines a class-level SOAP action method.

# File lib/ads_savon/model.rb, line 30
def define_class_action(action)
  class_action_module.module_eval %{
    def #{action.to_s.snakecase}(body = nil, &block)
      client.request :wsdl, #{action.inspect}, :body => body, &block
    end
  }
end
define_instance_action(action) click to toggle source

Defines an instance-level SOAP action method.

# File lib/ads_savon/model.rb, line 39
def define_instance_action(action)
  instance_action_module.module_eval %{
    def #{action.to_s.snakecase}(body = nil, &block)
      self.class.#{action.to_s.snakecase} body, &block
    end
  }
end
document(uri) click to toggle source

Sets the WSDL document to the given uri.

# File lib/ads_savon/model.rb, line 67
def document(uri)
  client.wsdl.document = uri
end
endpoint(uri) click to toggle source

Sets the SOAP endpoint to the given uri.

# File lib/ads_savon/model.rb, line 57
def endpoint(uri)
  client.wsdl.endpoint = uri
end
headers(headers) click to toggle source

Sets the HTTP headers.

# File lib/ads_savon/model.rb, line 72
def headers(headers)
  client.http.headers = headers
end
instance_action_module() click to toggle source

Instance methods.

# File lib/ads_savon/model.rb, line 90
def instance_action_module
  @instance_action_module ||= Module.new do

    # Returns the <tt>GoogleAdsSavon::Client</tt> from the class instance.
    def client(&block)
      self.class.client(&block)
    end

  end.tap { |mod| include(mod) }
end
namespace(uri) click to toggle source

Sets the target namespace.

# File lib/ads_savon/model.rb, line 62
def namespace(uri)
  client.wsdl.namespace = uri
end
wsse_auth(*args) click to toggle source

Sets WSSE auth credentials.

# File lib/ads_savon/model.rb, line 82
def wsse_auth(*args)
  client.wsse.credentials(*args)
end