Class: MoreappAPI::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/moreapp_api/form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(moreapp_api, customer_or_id, folder_or_id, form_id, form_name = "") ⇒ Form

Returns a new instance of Form.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/moreapp_api/form.rb', line 10

def initialize(moreapp_api, customer_or_id, folder_or_id, form_id, form_name = "")
  @moreapp_api = moreapp_api

  if customer_or_id.is_a?(MoreappAPI::Customer)
    @customer = customer_or_id
    @customer_id = @customer.id
  else
    @customer_id = customer_or_id
  end
  if folder_or_id.is_a?(MoreappAPI::Folder)
    @folder = folder_or_id
    @folder_id = @folder.id
  else
    @folder_id = folder_or_id
  end
  @id = form_id
  @name = form_name
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/moreapp_api/form.rb', line 7

def id
  @id
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/moreapp_api/form.rb', line 7

def name
  @name
end

#raw_dataObject

Returns the value of attribute raw_data.



7
8
9
# File 'lib/moreapp_api/form.rb', line 7

def raw_data
  @raw_data
end

Class Method Details

.create_in_folder(folder, long_id) ⇒ Object



30
31
32
33
# File 'lib/moreapp_api/form.rb', line 30

def self.create_in_folder(folder, long_id)
  customer = folder.customer
  MoreappAPI::Form.new(customer.moreapp_api, customer, folder, long_id[0..31], long_id[32..-1])
end

Instance Method Details

#post_instruction(recipients, message, data, options = {}) ⇒ Object



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

def post_instruction(recipients, message, data, options={})
  recipients = recipients.is_a?(String) ? [recipients] : recipients
  
  response = @moreapp_api.request(:post, "/api/v1.0/customers/#{@customer_id}/#{self.id}/instructions",
                              {
                                  publishInfo: {type: "IMMEDIATE"},
                                  recipients: recipients,
                                  data: data,
                                  message: message
                              }.to_json,
                              { 'Content-Type' => 'application/json' } )
  JSON.parse(response.body)
end

#registrations(page = 0, options = {}) ⇒ Object



50
51
52
# File 'lib/moreapp_api/form.rb', line 50

def registrations(page=0, options={})
  submissions page, options
end

#submissions(page = 0, options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/moreapp_api/form.rb', line 37

def submissions(page=0, options = {})
  options[:pageSize] ||= 100
  options[:sort] ||= []
  options[:query] ||= []
  response = @moreapp_api.request(:post, "/api/v1.0/customers/#{@customer_id}/forms/#{self.id}/submissions/filter/#{page}",
                              { pageSize: options[:pageSize], sort: options[:sort], query: options[:query] }.to_json,
                              { 'Content-Type' => 'application/json' } )

  registrations = JSON.parse(response.body)
  registrations.map{|data| MoreappAPI::Submission.new(self, data)}
end