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.
8 9 10 |
# File 'lib/airrecord/client.rb', line 8 def initialize(api_key) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
5 6 7 |
# File 'lib/airrecord/client.rb', line 5 def api_key @api_key end |
#connection ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/airrecord/client.rb', line 12 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
21 22 23 |
# File 'lib/airrecord/client.rb', line 21 def escape(*args) URI.escape(*args) end |
#handle_error(status, error) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/airrecord/client.rb', line 31 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
25 26 27 28 29 |
# File 'lib/airrecord/client.rb', line 25 def parse(body) JSON.parse(body) rescue JSON::ParserError nil end |