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 +4 -4
- data/README.md +9 -6
- data/lib/bouncie.rb +1 -0
- data/lib/bouncie/client.rb +42 -13
- data/lib/bouncie/user.rb +6 -0
- data/lib/bouncie/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88709352c65b73b8d0309b7e568b3fbb2cba215c4110770289971ff033b507d4
|
4
|
+
data.tar.gz: 1205a6c8f02271170b47a39994ccd25c0fd46ddf437e9ee46ae0960c0acd31fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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`.
|
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/
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/streetsmartslabs/bouncie.
|
data/lib/bouncie.rb
CHANGED
@@ -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'
|
data/lib/bouncie/client.rb
CHANGED
@@ -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] :
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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:
|
48
|
-
params:
|
50
|
+
endpoint: 'vehicles',
|
51
|
+
params: {
|
49
52
|
imei: imei,
|
50
|
-
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 ||=
|
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
|
data/lib/bouncie/user.rb
ADDED
data/lib/bouncie/version.rb
CHANGED
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
|
+
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-
|
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.
|
193
|
+
rubygems_version: 3.0.6
|
193
194
|
signing_key:
|
194
195
|
specification_version: 4
|
195
196
|
summary: An API wrapper for Bouncie
|