class GoodDataMarketo::Client

developers.marketo.com/documentation/soap/gettags/

Constants

DEFAULT_CONFIG

Attributes

activity_types[RW]
api_limit[RW]
client[R]
load[RW]
webdav[RW]

Public Class Methods

new(config = {}) click to toggle source
# File lib/gooddata_marketo/client.rb, line 79
def initialize(config = {})

  GoodDataMarketo.logging = true if config[:log]

  @api_limit = config[:api_limit] || MARKETO_API_LIMIT

  @loads = nil # Default is no jobs will be active.
  @load = nil # No job is currently set.
  @leads = nil

  config = DEFAULT_CONFIG.merge(config)

  @api_version = config.delete(:api_version).freeze
  @subdomain = config.delete(:api_subdomain).freeze
  @webdav = config.delete(:webdav)
  @logger = config.delete(:logger)

  @activity_types = ActivityTypes.new.values

  user_id = config.delete(:user_id)
  encryption_key = config.delete(:encryption_key)

  @auth = AuthHeader.new(user_id, encryption_key)

  @wsdl = "http://app.marketo.com/soap/mktows/#{@api_version}?WSDL".freeze
  @endpoint = "https://#{@subdomain}.mktoapi.com/soap/mktows/#{@api_version}".freeze

  #Create SOAP Header
  @savon = Savon.client(config.merge(endpoint: @endpoint))

  if GoodDataMarketo.logging
    puts use = self.usage
    puts "#{Time.now} => Marketo:SOAP/REST:Used of #{MARKETO_API_LIMIT}"

  end

end

Public Instance Methods

campaigns() click to toggle source
# File lib/gooddata_marketo/client.rb, line 348
def campaigns # http://developers.marketo.com/documentation/soap/campaigns/
  GoodDataMarketo::Campaigns.new :client => self
end
channels(config = {}) click to toggle source
# File lib/gooddata_marketo/models/channels.rb, line 3
def channels config = {} # http://developers.marketo.com/documentation/soap/getchannels/

  values = config[:values] || config[:channels]
  if values.is_a? String
    values = [values]
  end

  request = {
      :tag => {
          :values => {
              :string_item => []
          }
      }
  }

  if values
    request[:tag][:values][:string_item] = values
  end


  self.call(:get_campaigns_for_source, request)

end
configuration() click to toggle source
# File lib/gooddata_marketo/client.rb, line 137
def configuration
  DEFAULT_CONFIG
end
died(json = nil) click to toggle source
# File lib/gooddata_marketo/client.rb, line 236
def died(json = nil)

  if json
    file = File.open('marketo_connector_log.json','wb')
    file.write(json.to_json)
    exit
  else
    json = File.open('marketo_connector_log.json', 'r')
    json.to_h
  end

end
get_all_leads(config = {}) click to toggle source
# File lib/gooddata_marketo/client.rb, line 328
def get_all_leads config = {}
  rest = GoodDataMarketo::RESTAdapter.new :webdav => @webdav
  rest.get_all_leads
end
Also aliased as: write_all_lead_ids_to_csv
lead()
Alias for: leads
leads() click to toggle source
# File lib/gooddata_marketo/client.rb, line 339
def leads # http://developers.marketo.com/documentation/soap/getleadchanges/
  GoodDataMarketo::Leads.new :client => self
end
Also aliased as: lead
load=(load) click to toggle source
# File lib/gooddata_marketo/client.rb, line 365
def load=(load)
  @load = load
end
loads(config = {}) click to toggle source
# File lib/gooddata_marketo/client.rb, line 360
def loads(config = {})
  self.load = true
  @loads = GoodDataMarketo::Loads.new config
end
mobjects() click to toggle source
# File lib/gooddata_marketo/client.rb, line 352
def mobjects # http://developers.marketo.com/documentation/soap/getmobjects/
  GoodDataMarketo::MObjects.new :client => self
end
Also aliased as: objects
move_forward_30_days(original_time, days) click to toggle source
# File lib/gooddata_marketo/client.rb, line 193
def move_forward_30_days original_time, days
  smart_time = Date.parse(original_time) + days
  Time.parse(smart_time.to_s).to_s
end
objects()
Alias for: mobjects
operations() click to toggle source
# File lib/gooddata_marketo/client.rb, line 356
def operations
  @savon.operations
end
rest() click to toggle source
# File lib/gooddata_marketo/client.rb, line 324
def rest
  GoodDataMarketo::RESTAdapter.new :webdav => @webdav
end
safe_stream(web_method, params, config) click to toggle source
# File lib/gooddata_marketo/client.rb, line 262
def safe_stream web_method, params, config
  begin
    #Timeout.timeout(config[:timeout] || 18000) do
    GoodDataMarketo::Stream.new web_method, params, :client => self
    #end
  rescue Timeout::Error => e
    @timeouts += 1
    puts e if GoodDataMarketo.logging
    params[:timeouts] = @timeouts
    self.load.log('TIMEOUT') if self.load
    self.died params
  end

end
set_load(load) click to toggle source
# File lib/gooddata_marketo/client.rb, line 335
def set_load load
  @load = load
end
stream(web_method, params, config = {}) click to toggle source
# File lib/gooddata_marketo/client.rb, line 249
def stream(web_method, params, config = {})

  # If the stream is part of a load.

  if self.load
    "#{Time.now} => Load:#{self.load.json[:type]}:#{self.load.json[:method]}" if GoodDataMarketo.logging
  end

  puts "#{Time.now} => Stream: #{web_method}: #{params.to_s}" if GoodDataMarketo.logging

  safe = config[:safe] || true
  @timeouts = 0

  def safe_stream web_method, params, config
    begin
      #Timeout.timeout(config[:timeout] || 18000) do
      GoodDataMarketo::Stream.new web_method, params, :client => self
      #end
    rescue Timeout::Error => e
      @timeouts += 1
      puts e if GoodDataMarketo.logging
      params[:timeouts] = @timeouts
      self.load.log('TIMEOUT') if self.load
      self.died params
    end

  end

  if safe
    safe_stream web_method, params, config
  else
    GoodDataMarketo::Stream.new web_method, params, :client => self
  end


end
tags(config = {}) click to toggle source
# File lib/gooddata_marketo/models/tags.rb, line 9
def tags config = {} # http://developers.marketo.com/documentation/soap/gettags/

  values = config[:values] || config[:value] || config[:lead]
  values = [values] if values.is_a? String

  if config[:type]
    request = {
        :tag_list => {
            :tag => {
                :type => config[:type],
                :values => {
                    :string_item => values
                }
            }
        }
    }
  else
    request = {}
  end

  response = self.call(:get_tags, request)

end
test_rest() click to toggle source
# File lib/gooddata_marketo/client.rb, line 117
def test_rest
  puts "#{Time.now} => SETUP: Connected to Marketo REST API:#{@subdomain}" if GoodDataMarketo.logging
  begin
    self.usage
    true
  rescue
    false
  end
end
test_soap() click to toggle source
# File lib/gooddata_marketo/client.rb, line 127
def test_soap
  puts "#{Time.now} => SETUP: Connected to Marketo SOAP API:#{@subdomain}" if GoodDataMarketo.logging
  begin
    self.leads.get_by_email('test@test.com')
    true
  rescue
    false
  end
end
timed_call(web_method, params, config = {}) click to toggle source
# File lib/gooddata_marketo/client.rb, line 162
def timed_call web_method, params, config = {}

  puts "#{Time.now} => API Limit: #{@api_limit}" if GoodDataMarketo.logging
  puts "#{Time.now} => Call: #{web_method}: #{@params.to_s}" if GoodDataMarketo.logging

  Timeout.timeout(config[:timeout] || 4999) do

    response = @savon.call(
        web_method,
        message: params,
        soap_header: { 'ns1:AuthenticationHeader' => @auth.signature }
    ).to_hash

    # Add control flow to the root call because Marketo API changes for structure for just getLeadActivities
    if response[:success_get_lead_activity]
      response[:success_get_lead_activity][:lead_activity_list]
    else
      response[response.keys.first][:result]
    end

  end

end
usage(config = {}) click to toggle source
# File lib/gooddata_marketo/client.rb, line 343
def usage(config = {})
  rest = GoodDataMarketo::RESTAdapter.new :webdav => @webdav
  rest.usage
end
write_all_lead_ids_to_csv(config = {})
Alias for: get_all_leads