Class: MoreappAPI::Form
- Inherits:
-
Object
- Object
- MoreappAPI::Form
- Defined in:
- lib/moreapp_api/form.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#raw_data ⇒ Object
Returns the value of attribute raw_data.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(moreapp_api, customer_or_id, form_id, form_name = "", raw_data = nil) ⇒ Form
constructor
A new instance of Form.
- #post_instruction(recipients, message, data, options = {}) ⇒ Object
- #submissions(page = 0, options = {}) ⇒ Object
Constructor Details
#initialize(moreapp_api, customer_or_id, form_id, form_name = "", raw_data = nil) ⇒ Form
Returns a new instance of Form.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/moreapp_api/form.rb', line 10 def initialize(moreapp_api, customer_or_id, form_id, form_name = "", raw_data = nil) @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 @id = form_id @name = form_name @raw_data = raw_data end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/moreapp_api/form.rb', line 7 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/moreapp_api/form.rb', line 7 def name @name end |
#raw_data ⇒ Object
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_from_folder(folder, long_id_or_hash) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/moreapp_api/form.rb', line 25 def self.create_from_folder(folder, long_id_or_hash) customer = folder.customer if long_id_or_hash.is_a?(Hash) form_id = long_id_or_hash["id"] form_name = long_id_or_hash["meta"]["name"] raw_data = long_id_or_hash else form_id = long_id[0..31] form_name = long_id[32..-1] raw_data = nil end MoreappAPI::Form.new(customer.moreapp_api, customer, form_id, form_name, raw_data) end |
.create_from_id(customer, id) ⇒ Object
40 41 42 43 44 |
# File 'lib/moreapp_api/form.rb', line 40 def self.create_from_id(customer, id) response = customer.moreapp_api.request(:get, "/api/v1.0/forms/customer/#{customer.id}/forms/#{id}") form_data = JSON.parse(response.body) MoreappAPI::Form.new(customer.moreapp_api, customer, nil, form_data["id"], form_data["meta"]["name"], form_data) end |
Instance Method Details
#post_instruction(recipients, message, data, options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/moreapp_api/form.rb', line 62 def post_instruction(recipients, , data, ={}) 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: }.to_json, { 'Content-Type' => 'application/json' } ) JSON.parse(response.body) end |
#submissions(page = 0, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/moreapp_api/form.rb', line 48 def submissions(page=0, = {}) [:pageSize] ||= 100 [:sort] ||= [] [:query] ||= [] response = @moreapp_api.request(:post, "/api/v1.0/customers/#{@customer_id}/forms/#{self.id}/submissions/filter/#{page}", { pageSize: [:pageSize], sort: [:sort], query: [:query] }.to_json, { 'Content-Type' => 'application/json' } ) registrations = JSON.parse(response.body) registrations.map{|data| MoreappAPI::Submission.new(self, data)} end |