class Load
Attributes
arguments[RW]
client[RW]
id[R]
json[R]
storage[RW]
Public Class Methods
new(config = {})
click to toggle source
# File lib/gooddata_marketo/loads.rb, line 66 def initialize config = {} @id = Digest::SHA1.hexdigest(Time.now.to_s) def ensure_filetype_json string s = string.to_s if s.include? '.json' s else s+'_load.json' end end file = config[:file] || config[:name] @file = ensure_filetype_json(file) @webdav = config[:webdav] @client = config[:client] # So we don't make the JSON file a mess if we merge with config. config.delete(:webdav) config.delete(:client) # Check to see if the file exists locally first. if File.exists? @file @json = JSON.parse(IO.read(@file), :symbolize_names => true) # If not is the file on WebDAV, if so, download it. elsif self.on_webdav? self.refresh # Otherwise create a new load file locally. else config[:id] = self.id File.open(@file,'w'){ |f| JSON.dump(config, f) } @json = config end @saved = true @type = @json[:type] # "leads" @method = @json[:method] # "get_changes" @arguments = @json[:arguments] || @json[:parameters] # ARGS = ":oldest_created_at => 'March 26th 2014', :filters => ['Merge Leads']" end
Public Instance Methods
ensure_filetype_json(string)
click to toggle source
# File lib/gooddata_marketo/loads.rb, line 70 def ensure_filetype_json string s = string.to_s if s.include? '.json' s else s+'_load.json' end end
execute(config = {})
click to toggle source
# File lib/gooddata_marketo/loads.rb, line 114 def execute config = {} # Assign the current load to the client. client = config[:client] || @client client.set_load(self) # EXAMPLE LOADS FOR TYPE "LEADS" # get_lead_changes_from_march = { # :name => 'get_lead_changes_from_march', # :type => 'leads', # :method => 'get_changes', # :arguments => { # :oldest_created_at => 'March 26th 2014', # :latest_created_at => 'March 27th 2014', # :filters => ['Merge Leads'] # } # } # # get_multiple_from_january = { # :name => 'get_all_leads_january', # :type => 'leads', # :method => 'get_multiple', # :arguments => { # :oldest_created_at => 'January 1st 2014', # :latest_created_at => 'January 2nd 2014', # :filters => [''] # } # } case @type when "leads" self.log('REQUEST') client.leads.send(@method, @arguments) else raise 'Unable to load JOB type (Ex. "leads").' end end
get_argument_value(key)
click to toggle source
# File lib/gooddata_marketo/loads.rb, line 184 def get_argument_value key @arguments[key] end
Also aliased as: get_argument
log(type)
click to toggle source
Upload the updated log to WebDAV
# File lib/gooddata_marketo/loads.rb, line 157 def log type file_name = 'marketo_load_log.txt' log_file = File.open(file_name,'a') log_file.puts("#{self.id} --TYPE #{self.json[:type]} --METHOD #{self.json[:method]} --TIMESTAMP #{Time.now} --STATE #{type}") self.upload(file_name) end
merge_with_load(load)
click to toggle source
# File lib/gooddata_marketo/loads.rb, line 194 def merge_with_load load @json = load end
on_webdav?(f = false)
click to toggle source
Check if the current object “@file” is on WebDAV
# File lib/gooddata_marketo/loads.rb, line 168 def on_webdav? f = false if f file = f else file = @file end if @webdav.exists? file true else false end end
refresh()
click to toggle source
# File lib/gooddata_marketo/loads.rb, line 206 def refresh if File.exist? (@file) File.delete(@file) end json = @webdav.download @file File.open(@file,'w'){ |f| JSON.dump(json, f) } end
save()
click to toggle source
# File lib/gooddata_marketo/loads.rb, line 226 def save File.open(@file,'w'){ |f| JSON.dump(@json, f) } @saved = true self.upload end
set_argument_value(key, value)
click to toggle source
# File lib/gooddata_marketo/loads.rb, line 188 def set_argument_value key, value @arguments[key] = value end
terminate()
click to toggle source
# File lib/gooddata_marketo/loads.rb, line 214 def terminate # Delete on local File.delete(@file) if File.exists? @file if @webdav.exists? @file # Delete on remote @webdav.delete(@file) end end
Also aliased as: kill
upload(file=nil)
click to toggle source
# File lib/gooddata_marketo/loads.rb, line 198 def upload file=nil if file @webdav.upload file else @webdav.upload @file end end