Class: Bouncie::Client
- Inherits:
-
Object
- Object
- Bouncie::Client
- Defined in:
- lib/bouncie/client.rb
Overview
Class that wraps a Faraday connection in order to interact with the Bouncie API
Constant Summary collapse
- API_ENDPOINT =
'https://api.bouncie.dev/v1'
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
-
#refresh! ⇒ Object
rubocop:disable Metrics/AbcSize.
- #trips(imei:, transaction_id: nil, gps_format: 'polyline', starts_after: nil, ends_before: nil) ⇒ Trip
- #user ⇒ User
- #vehicles(imei: nil, vin: nil) ⇒ Vehicle
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
20 21 22 |
# File 'lib/bouncie/client.rb', line 20 def initialize() @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/bouncie/client.rb', line 11 def @options end |
Instance Method Details
#refresh! ⇒ Object
rubocop:disable Metrics/AbcSize
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/bouncie/client.rb', line 68 def refresh! resp = Faraday.post('https://auth.bouncie.com/oauth/token', { client_id: [:client_id], client_secret: [:client_secret], grant_type: 'authorization_code', code: [:authorization_code], redirect_uri: [:redirect_uri] }) if resp.success? parsed_resp = JSON.parse(resp.body) @headers = headers.merge(Authorization: parsed_resp['access_token']) @client = build_client end resp end |
#trips(imei:, transaction_id: nil, gps_format: 'polyline', starts_after: nil, ends_before: nil) ⇒ Trip
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bouncie/client.rb', line 30 def trips(imei:, transaction_id: nil, gps_format: 'polyline', starts_after: nil, ends_before: nil) request( http_method: :get, endpoint: 'trips', params: { imei: imei, transactionId: transaction_id, gpsFormat: gps_format, startsAfter: starts_after, endsBefore: ends_before }.compact ).map { |data| Bouncie::Trip.new(data) } end |