class Apiotics::Extract
Public Class Methods
fire(object, interfaces, a, time0= nil, time1= nil)
click to toggle source
# File lib/apiotics/extract.rb, line 62 def self.fire(object, interfaces, a, time0= nil, time1= nil) if Apiotics.configuration.targets[object.class.parent.name] != nil k = "#{object.class.parent.name}::#{object.class.parent.name}".constantize i = "#{object.class.parent.name}".underscore.gsub(" ","_").downcase + "_id" msg = { "action" => a, "instance" => k.find(object.send(i)).apiotics_instance, "driver" => object.class.name.to_s, "interface" => interfaces, } if time0 != nil msg["time0"] = time0 msg["time1"] = time1 end c = Apiotics::Client.new c.send(msg.to_json) object.skip_extract = true interfaces.each do |key, value| object.send(("#{key}_ack=").to_sym, false) object.send(("#{key}_complete=").to_sym, false) object.send(("#{key}_action=").to_sym, a) end object.save object.skip_extract = false unless Apiotics.configuration.local_logging == false Extract.save_log(object, interfaces, a) end end end
get(object, time0= nil, time1= nil)
click to toggle source
# File lib/apiotics/extract.rb, line 51 def self.get(object, time0= nil, time1= nil) object.accessed_fields.each do |field| v = Array.new if time0 != nil Extract.fire(object, field, object.send(field), "get", time0, time1) else Extract.fire(object, field, object.send(field), "get") end end end
is_target(object, k)
click to toggle source
# File lib/apiotics/extract.rb, line 43 def self.is_target(object, k) if Apiotics.configuration.targets[object.class.parent.name][object.class.name.demodulize.to_s].include?(k) || Apiotics.configuration.targets[object.class.parent.name][object.class.name.demodulize.to_s].include?(k.titleize) return true else return false end end
save_log(object, interfaces, a)
click to toggle source
# File lib/apiotics/extract.rb, line 94 def self.save_log(object, interfaces, a) interfaces.each do |key, value| klass = "#{object.class.name.underscore}_#{key}_log".classify.constantize r = klass.new r.send(("#{key}_action=").to_sym, a) r.send(("#{key}=".to_sym), value) r.send(("#{key}_ack=").to_sym, false) r.send(("#{key}_complete=").to_sym, false) r.send(("#{object.class.name.demodulize.underscore.gsub("/","_")}_id=").to_sym, object.id) puts r.inspect r.save end end
send(object)
click to toggle source
# File lib/apiotics/extract.rb, line 7 def self.send(object) interfaces = Hash.new puts object.previous_changes object.previous_changes.each do |k,v| if Apiotics::Extract.is_target(object, k) interfaces[k] = v[1].to_s end end if interfaces != {} Extract.fire(object, interfaces, "set-request") if Apiotics.configuration.portal == "https://test.apiotics.com" #not a permanent solution. if Apiotics.configuration.parents != {} interfaces.each do |k,v| if Apiotics.configuration.parents[object.class.parent.name][object.class.name.demodulize][k.to_s] != nil m = "#{object.class.parent}".underscore.gsub(" ","_").downcase target_class = Apiotics.configuration.parents[object.class.parent.name][object.class.name.demodulize][k.to_s]["driver"].downcase.constantize target = object.m.target_class i = Apiotics.configuration.parents[object.class.parent.name][object.class.name.demodulize][k.to_s]["interface"].downcase.constantize if Apiotics.configuration.parents[object.class.parent.name][object.class.name.demodulize][k.to_s].keys < 3 target.i = v target.skip_extract = true target.save target.skip_extract = false else target.i = Apiotics.configuration.parents[object.class.parent.name][object.class.name.demodulize][k.to_s][v.to_s] target.skip_extract = true target.save target.skip_extract = false end end end end end end end