Class: JobsActions::Actions

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/forcast/jobs/rule_engine/jobs_actions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.callback(object, rule, action_params) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/forcast/jobs/rule_engine/jobs_actions.rb', line 26

def self.callback(object,rule,action_params)
  puts "callback"
  action_params = JSON.parse(action_params)
  url = action_params["url"]
  attributes = action_params["attr"]
  servidor = Forcast::Utils::Server::Server.new do |config|
    config.dns = url
    config.connect = 1
    config.write = 1
    config.read = 1
    #config.ssl = true
    #config.headers.store("accept","application/json")
    config.before_ping = false
  end
  model_id = object.attributes.slice(*attributes) unless attributes.include?("all")
  json_send = {:data => model_id}
  servidor.conexion(:post,{},"",json_send)
end

.email(object, rule, action_params) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/forcast/jobs/rule_engine/jobs_actions.rb', line 53

def self.email(object, rule, action_params)
  puts "action_params"
  puts action_params
  # attributes = action_params["attributes"]
  # model_id_attributes = object.attributes.slice(*attributes) unless attributes.include?("all")
  # model_id_attributes ||= object.attributes

  obj_identifier = action_params['attr_id'] ? object.send(action_params['attr_id']) : object.id
  Forcast::Utils::Email::Layout.with(
    to: action_params['owner_email'], cc: action_params['target_email']
  ).default(
    object: object, rule: rule, obj_identifier: obj_identifier
  ).deliver_now
end

.notification(action_params) ⇒ Object



68
# File 'lib/forcast/jobs/rule_engine/jobs_actions.rb', line 68

def self.notification(action_params); end

.slack(object, rule, action_params) ⇒ Object



49
50
51
# File 'lib/forcast/jobs/rule_engine/jobs_actions.rb', line 49

def self.slack(object,rule,action_params)
  puts "slack"
end

.sms(action_params) ⇒ Object



70
# File 'lib/forcast/jobs/rule_engine/jobs_actions.rb', line 70

def self.sms(action_params); end

.telegram(object, rule, action_params) ⇒ Object



45
46
47
# File 'lib/forcast/jobs/rule_engine/jobs_actions.rb', line 45

def self.telegram(object,rule,action_params)
  puts "telegram"
end

Instance Method Details

#perform(object_id, rule_id) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/forcast/jobs/rule_engine/jobs_actions.rb', line 10

def perform (object_id,rule_id)   
  puts "SendAction"
  rule = Rule.find(rule_id)
  object = rule.rule_model.classify.constantize.find(object_id)
  actions = rule.action.where(:active? => true)
  actions.each do |action|
    action_type = action.action_type
    puts "Select Action #{action_type}"
    begin
      JobsActions::Actions.send(action_type,object,rule,action.action_params)
    rescue StandardError => e
      puts e
    end
  end
end