Class: MarketoAPI::ClientProxy

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/marketo_api/client_proxy.rb

Overview

The ClientProxy is the base class for implementing Marketo APIs in a fluent manner. When a descendant class is implemented, a method will be added to MarketoAPI::Client based on the descendant class name that will provide an initialized instance of the descendant class using the MarketoAPI::Client instance.

This base class does not provide any useful functionality for consumers of MarketoAPI, and is primarily provided for common functionality.

As an example, MarketoAPI::Client#campaigns was generated when MarketoAPI::Campaigns was inherited from MarketoAPI::ClientProxy. It returns an instance of MarketoAPI::Campaigns intialized with the MarketoAPI::Client that generated it.

Direct Known Subclasses

Campaigns, Leads, Lists, MObjects

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ClientProxy

Returns a new instance of ClientProxy.



33
34
35
# File 'lib/marketo_api/client_proxy.rb', line 33

def initialize(client)
  @client = client
end

Class Method Details

.inherited(klass) ⇒ Object

Generates a new method on MarketoAPI::Client based on the inherited class name.



22
23
24
25
26
27
28
29
30
# File 'lib/marketo_api/client_proxy.rb', line 22

def inherited(klass)
  name = klass.name.split(/::/).last.downcase.to_sym

  MarketoAPI::Client.class_eval <<-EOS
    def #{name}
      @#{name} ||= #{klass}.new(self)
    end
  EOS
end