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.
37 38 39 |
# File 'lib/hubspot/form.rb', line 37 def initialize(hash) self.send(:assign_properties, hash) end |
Instance Attribute Details
#fields(opts = {}) ⇒ Object (readonly)
43 44 45 |
# File 'lib/hubspot/form.rb', line 43 def fields @fields end |
#guid ⇒ Object (readonly)
Returns the value of attribute guid.
33 34 35 |
# File 'lib/hubspot/form.rb', line 33 def guid @guid end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
35 36 37 |
# File 'lib/hubspot/form.rb', line 35 def properties @properties end |
Class Method Details
.all ⇒ Object
21 22 23 24 |
# File 'lib/hubspot/form.rb', line 21 def all response = Hubspot::Connection.get_json(FORMS_PATH, {}) response.map { |f| new(f) } end |
.create!(opts = {}) ⇒ Object
16 17 18 19 |
# File 'lib/hubspot/form.rb', line 16 def create!(opts={}) response = Hubspot::Connection.post_json(FORMS_PATH, params: {}, body: opts) new(response) end |
.find(guid) ⇒ Object
27 28 29 30 |
# File 'lib/hubspot/form.rb', line 27 def find(guid) response = Hubspot::Connection.get_json(FORM_PATH, { form_guid: guid }) new(response) end |
Instance Method Details
#destroy! ⇒ Object
78 79 80 81 |
# File 'lib/hubspot/form.rb', line 78 def destroy! response = Hubspot::Connection.delete_json(FORM_PATH, { form_guid: @guid }) @destroyed = (response.code == 204) end |
#destroyed? ⇒ Boolean
83 84 85 |
# File 'lib/hubspot/form.rb', line 83 def destroyed? !!@destroyed end |
#submit(opts = {}) ⇒ Object
65 66 67 68 |
# File 'lib/hubspot/form.rb', line 65 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
71 72 73 74 75 |
# File 'lib/hubspot/form.rb', line 71 def update!(opts={}) response = Hubspot::Connection.post_json(FORM_PATH, params: { form_guid: @guid }, body: opts) self.send(:assign_properties, response) self end |