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.
42 43 44 |
# File 'lib/hubspot/form.rb', line 42 def initialize(hash) self.send(:assign_properties, hash) end |
Instance Attribute Details
#fields(opts = {}) ⇒ Object (readonly)
48 49 50 |
# File 'lib/hubspot/form.rb', line 48 def fields @fields end |
#guid ⇒ Object (readonly)
Returns the value of attribute guid.
38 39 40 |
# File 'lib/hubspot/form.rb', line 38 def guid @guid end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
40 41 42 |
# File 'lib/hubspot/form.rb', line 40 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 |
.upload_file(uri) ⇒ Object
32 33 34 35 |
# File 'lib/hubspot/form.rb', line 32 def upload_file(uri) path = URI::parse(uri).request_uri Hubspot::FilesConnection.get(path, {}) end |
Instance Method Details
#destroy! ⇒ Object
83 84 85 86 |
# File 'lib/hubspot/form.rb', line 83 def destroy! response = Hubspot::Connection.delete_json(FORM_PATH, { form_guid: @guid }) @destroyed = (response.code == 204) end |
#destroyed? ⇒ Boolean
88 89 90 |
# File 'lib/hubspot/form.rb', line 88 def destroyed? !!@destroyed end |
#submit(opts = {}) ⇒ Object
70 71 72 73 |
# File 'lib/hubspot/form.rb', line 70 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
76 77 78 79 80 |
# File 'lib/hubspot/form.rb', line 76 def update!(opts={}) response = Hubspot::Connection.post_json(FORM_PATH, params: { form_guid: @guid }, body: opts) self.send(:assign_properties, response) self end |