Sha256: 07fb181b27a4d8ced94d605a43b3c7d27b60bd30ea58904386322a193acd4da3

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

require_relative "./configuration"

module Jekyll
  module Airtable
    class API
      attr_accessor *Configuration::VALID_OPTIONS_KEYS

      # Creates a new API
      def initialize(options={})
        options = Airtable.options.merge(options)

        Configuration::VALID_OPTIONS_KEYS.each do |key|
          send("#{key}=", options[key])
        end
      end

      def config
        conf = {}

        Configuration::VALID_OPTIONS_KEYS.each do |key|
          conf[key] = send key
        end

        conf
      end

      def versioned_base_endpoint_url
        config[:endpoint] + config[:api_version] + '/' + config[:base_uid] + '/'
      end

      def processing_query_params(request_obj, params, params_key)
        keys = [
          :fields,
          :filter_by_formula,
          :max_records,
          :page_size,
          :sort,
          :view,
          :cell_format,
          :time_zone,
          :user_locale,
          :offset
        ]

        return nil unless keys.include?(params_key) || 
                          params[params_key].nil? || 
                          params[params_key] == ''

        key_string = params_key.to_s.split('_').each_with_index.map do |a, i| 
          if i == 0 then a else a.capitalize end 
        end.join

        request_obj.params[key_string] = params[params_key]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jekyll-airtable-0.4.1 lib/jekyll-airtable/api.rb
jekyll-airtable-0.3.0 lib/jekyll-airtable/api.rb
jekyll-airtable-0.2.0 lib/jekyll-airtable/api.rb