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'

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


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cf/custom_task_form.rb', line 26

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

Instance Attribute Details

#errorsObject

Contains Error message if any



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

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_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

#stationObject

station attribute is required for association with custom_from object



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

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'

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


48
49
50
# File 'lib/cf/custom_task_form.rb', line 48

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

.update(line_title, station_index, form_content) ⇒ Object

update the station form form_content = => “Enter text from a business card image”, :instruction => “Describe”, :html => html CF::CustomTaskForm.update(@line.title, station_index, form_content)



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cf/custom_task_form.rb', line 55

def self.update(line_title, station_index, form_content)
  form_content.stringify_keys!
  request =
  {
    :body =>
    {
      :api_key => CF.api_key,
      :form =>  {:title => form_content["title"], :instruction => form_content["instruction"], :_type => "CustomTaskForm", :raw_html => form_content["raw_html"]},
      :station_index => station_index
    }
  }
  resp = HTTParty.put("#{CF.api_url}#{CF.api_version}/lines/#{CF.}/#{line_title.downcase}/stations/#{station_index}/form.json", request)
end

Instance Method Details

#to_sObject

:nodoc:



69
70
71
# File 'lib/cf/custom_task_form.rb', line 69

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