class ProntoForms::Client

Allows you to retrieve resources from ProntoForms and perform other functions with the API.

Attributes

api_key_id[R]

@return [String] ProntoForms API key ID

api_key_secret[R]

@return [String] ProntoForms API key secret

Public Class Methods

new(api_key_id, api_key_secret) click to toggle source

Create a client and use provided API credentials @param api_key_id Your ProntoForms REST API key @param api_key_secret Your ProntoForms REST API secret

# File lib/prontoforms/client.rb, line 22
def initialize(api_key_id, api_key_secret)
  @api_key_id = api_key_id
  @api_key_secret = api_key_secret
end
resource_list(method, resource, url = resource.resource_name) click to toggle source

Defines a resource that can be retrieved in a list @return [nil] @api private @!macro [attach] resource_list

@method $1
Retrieve a list of $2 resources
@return [ResourceList] A ResourceList containing $2 results
# File lib/prontoforms/client.rb, line 34
def self.resource_list(method, resource, url = resource.resource_name)
  define_method(method) do |query: {}|
    res = connection.get do |req|
      req.url url
      query.each { |k, v| req.params[k] = v }
    end

    data = JSON.parse(res.body)

    return nil if data.fetch('pageData').size.zero?

    ResourceList.new(data, { 'p' => 0, 's' => 100 }.merge(query), method,
                     resource, self)
  end
end

Public Instance Methods

connection() click to toggle source

Create a connection that can be used to execute a request against the ProntoForms API. @return [Faraday::Connection] @api private

# File lib/prontoforms/client.rb, line 96
def connection
  Faraday.new(url: 'https://api.prontoforms.com/api/1.1') do |conn|
    conn.basic_auth(api_key_id, api_key_secret)
    conn.use Faraday::Response::RaiseError
  end
end
form_space(id) click to toggle source

Retrieve a form space by its identifier @param id [String] The form space identifier @return [FormSpace] A FormSpace object

# File lib/prontoforms/client.rb, line 69
def form_space(id)
  raise ArgumentError, 'id must be provided' if id.nil?

  res = connection.get do |req|
    req.url "formspaces/#{id}"
  end

  FormSpace.new(JSON.parse(res.body), self)
end
form_submission(id) click to toggle source

Retrieve a form submission by identifier @param id [String] The form submission identifier @return [FormSubmission] A FormSubmission object

# File lib/prontoforms/client.rb, line 82
def form_submission(id)
  return nil if id.nil?

  res = connection.get do |req|
    req.url "data/#{id}"
  end

  FormSubmission.new(JSON.parse(res.body), self)
end
user(id) click to toggle source

Retrieve a user by identifier @param id [String] The user identifier @return [User] A User object for the requested user

# File lib/prontoforms/client.rb, line 56
def user(id)
  raise ArgumentError, 'id must be provided' if id.nil?

  res = connection.get do |req|
    req.url "users/#{id}"
  end

  User.new(JSON.parse(res.body), self)
end