Class: Brandmaker::Job

Inherits:
Object
  • Object
show all
Extended by:
Savon::Model
Defined in:
lib/brandmaker/job.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Job

Returns a new instance of Job.



21
22
23
24
# File 'lib/brandmaker/job.rb', line 21

def initialize data
  @data = data
  @plain_variables ||= Brandmaker::VariableCollection.new @data[:desriptions][:variable]
end

Class Method Details

.clientObject



11
12
13
# File 'lib/brandmaker/job.rb', line 11

def self.client
  Brandmaker.configuration.dse_client
end

.find(id) ⇒ Object

”desriptions“ is a brandmaker typo in API



17
18
19
# File 'lib/brandmaker/job.rb', line 17

def self.find id
  Job.new find_by_id({:id => id}).body[:find_by_id_response][:return]
end

Instance Method Details

#configObject



34
35
36
# File 'lib/brandmaker/job.rb', line 34

def config
  Brandmaker.configuration.job_configs[self.technical_name.to_sym] or raise "Job #{self.id} is not configured, no config for #{self.technical_name}"
end

#idObject



26
27
28
# File 'lib/brandmaker/job.rb', line 26

def id
  @data[:desriptions][:id]
end

#recipientsObject



51
52
53
54
55
# File 'lib/brandmaker/job.rb', line 51

def recipients
  val = variables.find_by_purpose(VariablePurpose::EMAIL_RECIPIENT).value
  val = [val] unless val.is_a? Array
  val
end

#technical_nameObject



30
31
32
# File 'lib/brandmaker/job.rb', line 30

def technical_name
  @data[:desriptions][:type_name]
end

#variablesObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/brandmaker/job.rb', line 38

def variables
  available_variable_names = @plain_variables.map(&:technical_name)
  @variables ||= Brandmaker::VariableCollection.new(
    config.variables.select do |variable_config|
      available_variable_names.include? variable_config.name.to_s
    end.collect do |variable_config|
      variable = @plain_variables.find_by_technical_name(variable_config.name.to_s)
      configured_variable = variable_config.to_typed_instance(variable.data)
      configured_variable.config = variable_config
      configured_variable
    end, false)
end