bouncie 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4a21bb80e2739155f9d5e90b254d45fe7083659f11802ad79d2981a7773bd9f
4
- data.tar.gz: 92a9a86b053858e14c5c675feeb278b32381d9065c7d9d74328e79ff8db82dd2
3
+ metadata.gz: 88709352c65b73b8d0309b7e568b3fbb2cba215c4110770289971ff033b507d4
4
+ data.tar.gz: 1205a6c8f02271170b47a39994ccd25c0fd46ddf437e9ee46ae0960c0acd31fa
5
5
  SHA512:
6
- metadata.gz: b1cd8e4e7bf3b355d360ebc2749f13c44946dfe4ff13edf51c81a7520302bcc4fcd1670c51c16512347072235ca51755ef799690bd59d9b480af05607a97b4aa
7
- data.tar.gz: 2674f9a466d5e8a2af6f983ef001fe351cf8697b190d44401463d7e0082820167b051fd5d1ba3bfa681168d47ab41c0842bec49b123e3677c3faa7e54ad52f37
6
+ metadata.gz: a2d6cecd4277f7564ea8e96c8c9dbd1e5e7c0330e00591a7bc90bd3fa3c411f24b68c57a7de5b179e04d90ce17c2dc902a701831e08cc7c406048fcac847c81a
7
+ data.tar.gz: 92cfe4d41f800b4ad705fa7a1ea5e26f5c0bfbc9ced0606ea40878e1fc76bb7a2400f9955ce90e56eb47b1fa7f7a0747eb6e3c1025aea92a6bdaa6db9e987300
data/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # Bouncie
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bouncie`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
3
  ## Installation
8
4
 
9
5
  Add this line to your application's Gemfile:
@@ -23,6 +19,13 @@ Or install it yourself as:
23
19
  ## Usage
24
20
 
25
21
  Instantiate a client by passing an `options` hash with at least your app's `api_key` and your user account's `authorization_code'.
22
+ ```ruby
23
+ client = Bouncie::Client.new(api_key: [MY_KEY], authorization_code: [MY_CODE])
24
+
25
+ vehicles = client.vehicles
26
+
27
+ trips = client.trips(imei: [MY_VEHICLE_IMEI])
28
+ ```
26
29
 
27
30
  API documentation is available at [docs.bouncie.dev](https://docs.bouncie.dev).
28
31
 
@@ -30,8 +33,8 @@ API documentation is available at [docs.bouncie.dev](https://docs.bouncie.dev).
30
33
 
31
34
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
35
 
33
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+ To install this gem onto your local machine, run `bundle exec rake install`.
34
37
 
35
38
  ## Contributing
36
39
 
37
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bouncie.
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/streetsmartslabs/bouncie.
@@ -6,6 +6,7 @@ require 'bouncie/entity'
6
6
  require 'bouncie/vehicle'
7
7
  require 'bouncie/trip'
8
8
  require 'bouncie/webhook'
9
+ require 'bouncie/user'
9
10
  require 'bouncie/device_events/connect_event'
10
11
  require 'bouncie/device_events/disconnect_event'
11
12
  require 'bouncie/vehicle_health_events/battery_event'
@@ -11,8 +11,11 @@ module Bouncie
11
11
  attr_reader :options
12
12
 
13
13
  # @param [Hash] options the options to create a `Bouncie::Client` with.
14
- # @option opts [String] :api_key your Bouncie app's API key. Retrieve this from https://www.bouncie.dev/apps. Required.
14
+ # @option opts [String] :client_id your Bouncie app's client_id. Retrieve this from https://www.bouncie.dev/apps. Required.
15
+ # @option opts [String] :client_id your Bouncie app's client_secret. Retrieve this from https://www.bouncie.dev/apps. Required.
16
+ # @option opts [String] :redirect_uri the same redirect uri used to retrieve the token initially. Used for verification only. Required.
15
17
  # @option opts [String] :authorization_code code from a user who grants access to their information via OAuth. Required.
18
+ # @option opts [String] :access_token token from a user who grants access to their information via OAuth. Required.
16
19
  # @option opts [Hash] :headers hash of any additional headers to add to HTTP requests
17
20
  def initialize(options)
18
21
  @options = options
@@ -30,10 +33,10 @@ module Bouncie
30
33
  endpoint: 'trips',
31
34
  params: {
32
35
  imei: imei,
33
- transaction_id: transaction_id,
34
- gps_format: gps_format,
35
- starts_after: starts_after,
36
- ends_before: ends_before
36
+ transactionId: transaction_id,
37
+ gpsFormat: gps_format,
38
+ startsAfter: starts_after,
39
+ endsBefore: ends_before
37
40
  }.compact
38
41
  ).map { |data| Bouncie::Trip.new(data) }
39
42
  end
@@ -44,25 +47,51 @@ module Bouncie
44
47
  def vehicles(imei: nil, vin: nil)
45
48
  request(
46
49
  http_method: :get,
47
- endpoint: 'vehicles',
48
- params: {
50
+ endpoint: 'vehicles',
51
+ params: {
49
52
  imei: imei,
50
- vin: vin
53
+ vin: vin
51
54
  }.compact
52
55
  ).map { |data| Bouncie::Vehicle.new(data) }
53
56
  end
54
57
 
58
+ # @return [User]
59
+ def user
60
+ data = request(
61
+ http_method: :get,
62
+ endpoint: 'user'
63
+ )
64
+ Bouncie::User.new(data)
65
+ end
66
+
67
+ def refresh!
68
+ resp = Faraday.post('https://auth.bouncie.com/oauth/token', {
69
+ client_id: options[:client_id],
70
+ client_secret: options[:client_secret],
71
+ grant_type: 'authorization_code',
72
+ code: options[:authorization_code],
73
+ redirect_uri: options[:redirect_uri]
74
+ })
75
+ if resp.success?
76
+ parsed_resp = Oj.load(resp.body)
77
+ @headers = headers.merge(Authorization: parsed_resp['access_token'])
78
+ @client = build_client
79
+ end
80
+ resp
81
+ end
82
+
55
83
  private
56
84
 
57
85
  def headers
58
- @headers ||= {
59
- 'AuthorizationCode' => options[:authorization_code],
60
- 'ApiKey' => options[:api_key]
61
- }.merge(options[:headers] || {})
86
+ @headers = { Authorization: options[:access_token] }.merge(options[:headers] || {})
62
87
  end
63
88
 
64
89
  def client
65
- @client ||= Faraday.new(API_ENDPOINT, headers: headers) do |client|
90
+ @client ||= build_client
91
+ end
92
+
93
+ def build_client
94
+ Faraday.new(API_ENDPOINT, headers: headers) do |client|
66
95
  client.request :url_encoded
67
96
  client.adapter Faraday.default_adapter
68
97
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bouncie
4
+ class User < Entity
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bouncie
4
- VERSION = '0.4.0'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bouncie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Psoinos
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-07 00:00:00.000000000 Z
11
+ date: 2020-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -160,6 +160,7 @@ files:
160
160
  - lib/bouncie/device_events/disconnect_event.rb
161
161
  - lib/bouncie/entity.rb
162
162
  - lib/bouncie/trip.rb
163
+ - lib/bouncie/user.rb
163
164
  - lib/bouncie/vehicle.rb
164
165
  - lib/bouncie/vehicle_health_events/battery_event.rb
165
166
  - lib/bouncie/vehicle_health_events/mil_event.rb
@@ -189,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
190
  - !ruby/object:Gem::Version
190
191
  version: '0'
191
192
  requirements: []
192
- rubygems_version: 3.0.4
193
+ rubygems_version: 3.0.6
193
194
  signing_key:
194
195
  specification_version: 4
195
196
  summary: An API wrapper for Bouncie