Class: Airrecord::Client
- Inherits:
-
Object
- Object
- Airrecord::Client
- Defined in:
- lib/airrecord/client.rb
Constant Summary collapse
- AIRTABLE_RPS_LIMIT =
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.
5
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
- #connection ⇒ Object
Instance Method Summary collapse
- #escape(*args) ⇒ Object
- #handle_error(status, error) ⇒ Object
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
- #parse(body) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
14 15 16 |
# File 'lib/airrecord/client.rb', line 14 def initialize(api_key) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/airrecord/client.rb', line 7 def api_key @api_key end |
#connection ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/airrecord/client.rb', line 18 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 }, ) { |conn| if Airrecord.throttle? conn.request :airrecord_rate_limiter, requests_per_second: AIRTABLE_RPS_LIMIT end conn.adapter :net_http_persistent } end |
Instance Method Details
#escape(*args) ⇒ Object
35 36 37 |
# File 'lib/airrecord/client.rb', line 35 def escape(*args) QueryString.escape(*args) end |
#handle_error(status, error) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/airrecord/client.rb', line 45 def handle_error(status, error) if error.is_a?(Hash) raise Error, "HTTP #{status}: #{error['error']["type"]}: #{error['error']['message']}" else raise Error, "HTTP #{status}: Communication error: #{error}" end end |
#parse(body) ⇒ Object
39 40 41 42 43 |
# File 'lib/airrecord/client.rb', line 39 def parse(body) JSON.parse(body) rescue JSON::ParserError nil end |