Class: CF::CustomTaskForm

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/cf/custom_task_form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CustomTaskForm

Initializes a new CustomForm

Usage custom_instruction.new(hash):

html = 'html_content'
css = 'css_content'
javascript = 'javascript_content'

instruction = CF::CustomTaskForm.new({:title => "Enter text from a business card image", :instruction => "Describe", :raw_html => html, :raw_css => css, :raw_javascript => javascript})


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cf/custom_task_form.rb', line 34

def initialize(options={})
  @station     = options[:station]
  @title       = options[:title]
  @instruction = options[:instruction]
  @raw_html = options[:raw_html]
  @raw_css = options[:raw_css]
  @raw_javascript = options[:raw_javascript]
  if @station
    resp = self.class.post("/lines/#{CF.account_name}/#{@station.line_title.downcase}/stations/#{@station.index}/form.json", :form => {:title => @title, :instruction => @instruction, :_type => "CustomTaskForm", :raw_html => @raw_html, :raw_css => @raw_css, :raw_javascript => @raw_javascript})
    resp.to_hash.each_pair do |k,v|
      self.send("#{k}=",v) if self.respond_to?(k)
    end
    if resp.code != 200
      self.errors = resp.error.message
    end
    @station.form = self
    return self
  end
end

Instance Attribute Details

#errorsObject

Contains Error message if any



24
25
26
# File 'lib/cf/custom_task_form.rb', line 24

def errors
  @errors
end

#instructionObject

Description of “custom_instruction” object, e.g. :description => “description for title of custom_instruction”



9
10
11
# File 'lib/cf/custom_task_form.rb', line 9

def instruction
  @instruction
end

#raw_cssObject

raw_css is an attribute to store the custom css contents



15
16
17
# File 'lib/cf/custom_task_form.rb', line 15

def raw_css
  @raw_css
end

#raw_htmlObject

raw_html is an attribute to store the custom html contents



12
13
14
# File 'lib/cf/custom_task_form.rb', line 12

def raw_html
  @raw_html
end

#raw_javascriptObject

raw_javascript is an attribute to store the custom javascript contents



18
19
20
# File 'lib/cf/custom_task_form.rb', line 18

def raw_javascript
  @raw_javascript
end

#stationObject

station attribute is required for association with custom_from object



21
22
23
# File 'lib/cf/custom_task_form.rb', line 21

def station
  @station
end

#titleObject

Title of “custom_instruction” object, e.g. :title => “title_name of custom_instruction”



6
7
8
# File 'lib/cf/custom_task_form.rb', line 6

def title
  @title
end

Class Method Details

.create(form) ⇒ Object

Initializes a new CustomForm within block using Variable

Usage custom_instruction.create(hash):

html = 'html_content'
css = 'css_content'
javascript = 'javascript_content'

instruction = CF::CustomTaskForm.create({:title => "Enter text from a business card image", :instruction => "Describe", :raw_html => html, :raw_css => css, :raw_javascript => javascript})


62
63
64
# File 'lib/cf/custom_task_form.rb', line 62

def self.create(form)
  instruction = CustomTaskForm.new(form)
end

Instance Method Details

#to_sObject

:nodoc:



66
67
68
# File 'lib/cf/custom_task_form.rb', line 66

def to_s # :nodoc:
  "{:title => #{self.title}, :instruction => #{self.instruction}, :raw_html => #{self.raw_html}, :raw_css => #{self.raw_css}, :raw_javascript => #{self.raw_javascript}, :errors => #{self.errors}}"
end