class Hubspot::Form

HubSpot Form API

{developers.hubspot.com/docs/methods/forms/forms_overview}

Constants

FIELDS_PATH
FIELD_PATH
FORMS_PATH
FORM_PATH
SUBMIT_DATA_PATH

Attributes

fields[R]
guid[R]
properties[R]

Public Class Methods

all() click to toggle source
# File lib/hubspot/form.rb, line 21
def all
  response = Hubspot::Connection.get_json(FORMS_PATH, {})
  response.map { |f| new(f) }
end
create!(opts={}) click to toggle source

{developers.hubspot.com/docs/methods/forms/create_form}

# 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) click to toggle source

{developers.hubspot.com/docs/methods/forms/get_form}

# File lib/hubspot/form.rb, line 27
def find(guid)
  response = Hubspot::Connection.get_json(FORM_PATH, { form_guid: guid })
  new(response)
end
new(hash) click to toggle source
# File lib/hubspot/form.rb, line 42
def initialize(hash)
  self.send(:assign_properties, hash)
end
upload_file(uri) click to toggle source
# File lib/hubspot/form.rb, line 32
def upload_file(uri)
  path = URI::parse(uri).request_uri
  Hubspot::FilesConnection.get(path, {})
end

Public Instance Methods

destroy!() click to toggle source

{developers.hubspot.com/docs/methods/forms/delete_form}

# 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?() click to toggle source
# File lib/hubspot/form.rb, line 88
def destroyed?
  !!@destroyed
end
submit(opts={}) click to toggle source

{developers.hubspot.com/docs/methods/forms/submit_form}

# 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={}) click to toggle source

{developers.hubspot.com/docs/methods/forms/update_form}

# 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

Private Instance Methods

assign_properties(hash) click to toggle source
# File lib/hubspot/form.rb, line 94
def assign_properties(hash)
  @guid = hash['guid']
  @fields = (hash['formFieldGroups'] || []).inject([]) { |result, fg| result | fg['fields'] }
  @properties = hash
end