Class: Hubspot::Form
- Inherits:
-
Object
- Object
- Hubspot::Form
- Defined in:
- lib/hubspot/form.rb
Overview
HubSpot Form API
https://developers.hubspot.com/docs/methods/forms/forms_overview
Constant Summary collapse
- FORMS_PATH =
‘/contacts/v1/forms’
'/forms/v2/forms'- FORM_PATH =
‘/contacts/v1/forms/:form_guid’
'/forms/v2/forms/:form_guid'- FIELDS_PATH =
‘/contacts/v1/fields/:form_guid’
'/forms/v2/fields/:form_guid'- FIELD_PATH =
FIELDS_PATH + '/:field_name'
- SUBMIT_DATA_PATH =
'/uploads/form/v2/:portal_id/:form_guid'
Instance Attribute Summary collapse
- #fields(opts = {}) ⇒ Object readonly
-
#guid ⇒ Object
readonly
Returns the value of attribute guid.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Class Method Summary collapse
Instance Method Summary collapse
- #destroy! ⇒ Object
- #destroyed? ⇒ Boolean
-
#initialize(hash) ⇒ Form
constructor
A new instance of Form.
- #submit(opts = {}) ⇒ Object
- #update!(opts = {}) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Form
Returns a new instance of Form.
39 40 41 |
# File 'lib/hubspot/form.rb', line 39 def initialize(hash) self.send(:assign_properties, hash) end |
Instance Attribute Details
#fields(opts = {}) ⇒ Object (readonly)
45 46 47 |
# File 'lib/hubspot/form.rb', line 45 def fields @fields end |
#guid ⇒ Object (readonly)
Returns the value of attribute guid.
35 36 37 |
# File 'lib/hubspot/form.rb', line 35 def guid @guid end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
37 38 39 |
# File 'lib/hubspot/form.rb', line 37 def properties @properties end |
Class Method Details
.all ⇒ Object
23 24 25 26 |
# File 'lib/hubspot/form.rb', line 23 def all response = Hubspot::Connection.get_json(FORMS_PATH, {}) response.map { |f| new(f) } end |
.create!(opts = {}) ⇒ Object
18 19 20 21 |
# File 'lib/hubspot/form.rb', line 18 def create!(opts={}) response = Hubspot::Connection.post_json(FORMS_PATH, params: {}, body: opts) new(response) end |
.find(guid) ⇒ Object
29 30 31 32 |
# File 'lib/hubspot/form.rb', line 29 def find(guid) response = Hubspot::Connection.get_json(FORM_PATH, { form_guid: guid }) new(response) end |
Instance Method Details
#destroy! ⇒ Object
80 81 82 83 |
# File 'lib/hubspot/form.rb', line 80 def destroy! response = Hubspot::Connection.delete_json(FORM_PATH, { form_guid: @guid }) @destroyed = (response.code == 204) end |
#destroyed? ⇒ Boolean
85 86 87 |
# File 'lib/hubspot/form.rb', line 85 def destroyed? !!@destroyed end |
#submit(opts = {}) ⇒ Object
67 68 69 70 |
# File 'lib/hubspot/form.rb', line 67 def submit(opts={}) response = Hubspot::FormsConnection.submit(SUBMIT_DATA_PATH, params: { form_guid: @guid }, body: opts) [204, 302, 200].include?(response.code) end |
#update!(opts = {}) ⇒ Object
73 74 75 76 77 |
# File 'lib/hubspot/form.rb', line 73 def update!(opts={}) response = Hubspot::Connection.post_json(FORM_PATH, params: { form_guid: @guid }, body: opts) self.send(:assign_properties, response) self end |