class Base::Endpoints::Forms

This endpoint contains methods for forms.

Public Class Methods

new(access_token:, url:) click to toggle source

Initializes this endpoint.

Calls superclass method Base::Endpoint::new
# File lib/base/endpoints/forms.rb, line 8
def initialize(access_token:, url:)
  @path = 'forms'
  super
end

Public Instance Methods

create(name:) click to toggle source

Creates a form with the given name

# File lib/base/endpoints/forms.rb, line 24
def create(name:)
  request do
    response =
      connection.post('', 'name' => name)

    parse(response.body)
  end
end
delete(id) click to toggle source

Deletes the form with the given ID.

# File lib/base/endpoints/forms.rb, line 44
def delete(id)
  request do
    response =
      connection.delete id

    parse(response.body)
  end
end
delete_submission(id, submission_id) click to toggle source

Deletes the submission with the given ID of the form with the given ID.

# File lib/base/endpoints/forms.rb, line 126
def delete_submission(id, submission_id)
  request do
    response =
      connection.delete "#{id}/submissions/#{submission_id}"

    parse(response.body)
  end
end
get(id) click to toggle source

Returns the form with the given ID.

# File lib/base/endpoints/forms.rb, line 34
def get(id)
  request do
    response =
      connection.get id

    parse(response.body)
  end
end
get_submission(id, submission_id) click to toggle source

Returns the submission with the given ID of the form with the given ID.

# File lib/base/endpoints/forms.rb, line 91
def get_submission(id, submission_id)
  request do
    response =
      connection.get "#{id}/submissions/#{submission_id}"

    parse(response.body)
  end
end
list(page: 1, per_page: 10) click to toggle source

Lists the forms of a project

# File lib/base/endpoints/forms.rb, line 14
def list(page: 1, per_page: 10)
  request do
    response =
      connection.get('', per_page: per_page, page: page)

    parse(response.body)
  end
end
submissions(id:, page: 1, per_page: 10) click to toggle source

Returns the submission for the form with the given ID.

# File lib/base/endpoints/forms.rb, line 79
def submissions(id:,
                page: 1,
                per_page: 10)
  request do
    response =
      connection.get("#{id}/submissions", per_page: per_page, page: page)

    parse(response.body)
  end
end
submit(id:, form:) click to toggle source

Submits a new submission for the form with the given ID.

# File lib/base/endpoints/forms.rb, line 54
def submit(id:, form:)
  request do
    payload =
      form.each_with_object({}) do |(key, value), memo|
        memo[key] =
          case value
          when File, Tempfile
            Faraday::UploadIO.new(
              value.path,
              File.mime_type?(value),
              File.basename(value)
            )
          else
            value
          end
      end

    response =
      connection.post("#{id}/submit", payload)

    parse(response.body)
  end
end
update_submission(id:, submission_id:, form:) click to toggle source

Submits a new submission for the form with the given ID.

# File lib/base/endpoints/forms.rb, line 101
def update_submission(id:, submission_id:, form:)
  request do
    payload =
      form.each_with_object({}) do |(key, value), memo|
        memo[key] =
          case value
          when File, Tempfile
            Faraday::UploadIO.new(
              value.path,
              File.mime_type?(value),
              File.basename(value)
            )
          else
            value
          end
      end

    response =
      connection.put("#{id}/submit/#{submission_id}", payload)

    parse(response.body)
  end
end