Class: Airrecord::Client
- Inherits:
-
Object
- Object
- Airrecord::Client
- Defined in:
- lib/airrecord/client.rb
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.
6 7 8 |
# File 'lib/airrecord/client.rb', line 6 def initialize(api_key) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
3 4 5 |
# File 'lib/airrecord/client.rb', line 3 def api_key @api_key end |
#connection ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/airrecord/client.rb', line 10 def connection @connection ||= Faraday.new(url: "https://api.airtable.com", headers: { "Authorization" => "Bearer #{api_key}", "X-API-VERSION" => "0.1.0", }) { |conn| conn.adapter :net_http_persistent } end |
Instance Method Details
#escape(*args) ⇒ Object
19 20 21 |
# File 'lib/airrecord/client.rb', line 19 def escape(*args) URI.escape(*args) end |
#handle_error(status, error) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/airrecord/client.rb', line 29 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
23 24 25 26 27 |
# File 'lib/airrecord/client.rb', line 23 def parse(body) JSON.parse(body) rescue JSON::ParserError nil end |