Module: Houdini::Model

Defined in:
lib/houdini-rails/model.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/houdini-rails/model.rb', line 3

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#call_after_submitObject



32
33
34
# File 'lib/houdini-rails/model.rb', line 32

def call_after_submit
  self.send(houdini_task.after_submit) if houdini_task.after_submit
end

#generate_form_html(template_path) ⇒ Object



36
37
38
39
# File 'lib/houdini-rails/model.rb', line 36

def generate_form_html(template_path)
  template = Tilt.new(File.join(RAILS_ROOT, template_path))
  template.render(self, self.class.name.downcase.to_sym => self)
end

#process_postback(answer) ⇒ Object



28
29
30
# File 'lib/houdini-rails/model.rb', line 28

def process_postback(answer)
  self.send(houdini_task.on_task_completion, answer)
end

#send_to_houdini(task_name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/houdini-rails/model.rb', line 15

def send_to_houdini(task_name)
  # TODO: look up task when multiple tasks per model are implemented
  result = Houdini::Base.request(houdini_task.api,
    :api_key => Houdini::KEY,
    :identifier => houdini_task.name,
    :price => houdini_task.price,
    :title => houdini_task.title,
    :form_html => generate_form_html(houdini_task.form_template),
    :postback_url => houdini_postbacks_url(self.class.name, self.id, self.houdini_task.name, :host => Houdini::RAILS_HOST))

  call_after_submit
end