Sha256: 48df1e88abd99ad671d5f410ef75543531ac2a0fa0eff461cc6323659a209239
Contents?: true
Size: 1.37 KB
Versions: 3
Compression:
Stored size: 1.37 KB
Contents
require 'uri' require_relative 'query_string' require_relative 'faraday_rate_limiter' module Airrecord class Client attr_reader :api_key attr_writer :connection # Per Airtable's documentation you will get throttled for 30 seconds if you # issue more than 5 requests per second. Airrecord is a good citizen. AIRTABLE_RPS_LIMIT = 5 def initialize(api_key) @api_key = api_key end def connection @connection ||= Faraday.new( url: "https://api.airtable.com", headers: { "Authorization" => "Bearer #{api_key}", "User-Agent" => "Airrecord/#{Airrecord::VERSION}", "X-API-VERSION" => "0.1.0", }, request: { params_encoder: Airrecord::QueryString } ) do |conn| if Airrecord.throttle? conn.request :airrecord_rate_limiter, requests_per_second: AIRTABLE_RPS_LIMIT end conn.adapter :net_http_persistent end end def escape(*args) QueryString.escape(*args) end def parse(body) JSON.parse(body) rescue JSON::ParserError nil end def handle_error(status, error) if error.is_a?(Hash) && error['error'] raise Error, "HTTP #{status}: #{error['error']['type']}: #{error['error']['message']}" else raise Error, "HTTP #{status}: Communication error: #{error}" end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
airrecord-1.0.10 | lib/airrecord/client.rb |
airrecord-1.0.9 | lib/airrecord/client.rb |
airrecord-1.0.8 | lib/airrecord/client.rb |