Sha256: cb670c4a6c4754a1e6ff672939478328032387d846d720b1d8a4608b1a5b8811

Contents?: true

Size: 737 Bytes

Versions: 3

Compression:

Stored size: 737 Bytes

Contents

module TypedForm
  class Client
    attr_reader :api_key

    include HTTParty

    def initialize(api_key:)
      @api_key = api_key
    end

    def forms_by_id(form_id:, **query_params)
      url_params = query_params.map { |k, v| "#{k}=#{v}" }
      request_url = [form_id, authenticated_slug(url_params)].join("?")
      get(request_url).body
    end

    def find_form_by(form_id:, token:, **query_params)
      forms_by_id(form_id: form_id, token: token, **query_params)
    end

    private

    def get(slug)
      self.class.get(base_url + slug)
    end

    def base_url
      "https://api.typeform.com/v1/form/"
    end

    def authenticated_slug(url_params)
      ["key=#{api_key}", url_params].join("&")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
typed_form-0.0.4 lib/typed_form/client.rb
typed_form-0.0.3 lib/typed_form/client.rb
typed_form-0.0.2 lib/typed_form/client.rb