bouncie 0.1.0 → 0.7.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/.github/workflows/lint.yml +15 -0
- data/.github/workflows/matrix_testing.yml +24 -0
- data/.github/workflows/publish.yml +48 -0
- data/.rubocop.yml +8 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +55 -19
- data/README.md +9 -6
- data/Rakefile +4 -2
- data/bin/console +4 -3
- data/bouncie.gemspec +23 -18
- data/lib/bouncie.rb +12 -1
- data/lib/bouncie/client.rb +62 -15
- data/lib/bouncie/device_events/connect_event.rb +8 -0
- data/lib/bouncie/device_events/disconnect_event.rb +8 -0
- data/lib/bouncie/entity.rb +26 -11
- data/lib/bouncie/trip.rb +2 -0
- data/lib/bouncie/user.rb +6 -0
- data/lib/bouncie/vehicle.rb +2 -0
- data/lib/bouncie/vehicle_health_events/battery_event.rb +8 -0
- data/lib/bouncie/vehicle_health_events/mil_event.rb +8 -0
- data/lib/bouncie/vehicle_trip_events/trip_data_event.rb +8 -0
- data/lib/bouncie/vehicle_trip_events/trip_end_event.rb +8 -0
- data/lib/bouncie/vehicle_trip_events/trip_metrics_event.rb +8 -0
- data/lib/bouncie/vehicle_trip_events/trip_start_event.rb +8 -0
- data/lib/bouncie/version.rb +3 -1
- data/lib/bouncie/webhook.rb +32 -0
- metadata +72 -15
- data/.github/workflows/main.yml +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0202c63ed663c1ac4412667cdc72e6d6474150bafd4dfcfadd8e4a63c8d4ba2d
|
4
|
+
data.tar.gz: cc62cd47492c08d5ec017a2c1258b9c4c48b329b48a0478a7f8c32b0f491407e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 129ffd0ce66cd76d86b980529137ec2d0570305112c1bb4ece7cf0784aae69de38139ba0b5a90ed6e43f617338038e1f6b881dc3ca88fae294120ed7957587f7
|
7
|
+
data.tar.gz: 773c27196353fb8a3f840745f7ea78e369dc677745be41edc873530c1959a5ebbc939cfcba0b7a987182f2e64ef2a03ffb2c1d46059c0f5afa5d0f6686411c50
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: Matrix Testing
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ main ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ main ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ${{ matrix.os }}-latest
|
12
|
+
strategy:
|
13
|
+
fail-fast: false
|
14
|
+
matrix:
|
15
|
+
os: [ubuntu]
|
16
|
+
ruby: [2.5, 2.6, 2.7, head, debug, jruby, jruby-head, truffleruby, truffleruby-head]
|
17
|
+
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby }}
|
23
|
+
- run: bundle install
|
24
|
+
- run: rspec spec
|
@@ -0,0 +1,48 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
# Manually publish
|
5
|
+
workflow_dispatch:
|
6
|
+
# push:
|
7
|
+
# branches: [ main ]
|
8
|
+
# pull_request:
|
9
|
+
# branches: [ main ]
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
build:
|
13
|
+
name: Build + Publish
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
permissions:
|
16
|
+
packages: write
|
17
|
+
contents: read
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
- name: Set up Ruby 2.7
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: 2.7
|
25
|
+
- run: bundle install
|
26
|
+
|
27
|
+
- name: Publish to GPR
|
28
|
+
run: |
|
29
|
+
mkdir -p $HOME/.gem
|
30
|
+
touch $HOME/.gem/credentials
|
31
|
+
chmod 0600 $HOME/.gem/credentials
|
32
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
33
|
+
gem build *.gemspec
|
34
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
35
|
+
env:
|
36
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
37
|
+
OWNER: ${{ github.repository_owner }}
|
38
|
+
|
39
|
+
- name: Publish to RubyGems
|
40
|
+
run: |
|
41
|
+
mkdir -p $HOME/.gem
|
42
|
+
touch $HOME/.gem/credentials
|
43
|
+
chmod 0600 $HOME/.gem/credentials
|
44
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
45
|
+
gem build *.gemspec
|
46
|
+
gem push *.gem
|
47
|
+
env:
|
48
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,30 +1,49 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bouncie (0.
|
4
|
+
bouncie (0.7.0)
|
5
5
|
activesupport
|
6
6
|
faraday
|
7
|
-
|
7
|
+
json
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (6.
|
12
|
+
activesupport (6.1.3.1)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
-
i18n (>=
|
15
|
-
minitest (
|
16
|
-
tzinfo (~>
|
17
|
-
zeitwerk (~> 2.
|
18
|
-
|
14
|
+
i18n (>= 1.6, < 2)
|
15
|
+
minitest (>= 5.1)
|
16
|
+
tzinfo (~> 2.0)
|
17
|
+
zeitwerk (~> 2.3)
|
18
|
+
ast (2.4.0)
|
19
|
+
coderay (1.1.2)
|
20
|
+
concurrent-ruby (1.1.8)
|
19
21
|
diff-lcs (1.3)
|
20
|
-
faraday (1.
|
22
|
+
faraday (1.4.1)
|
23
|
+
faraday-excon (~> 1.1)
|
24
|
+
faraday-net_http (~> 1.0)
|
25
|
+
faraday-net_http_persistent (~> 1.1)
|
21
26
|
multipart-post (>= 1.2, < 3)
|
22
|
-
|
27
|
+
ruby2_keywords (>= 0.0.4)
|
28
|
+
faraday-excon (1.1.0)
|
29
|
+
faraday-net_http (1.0.1)
|
30
|
+
faraday-net_http_persistent (1.1.0)
|
31
|
+
i18n (1.8.10)
|
23
32
|
concurrent-ruby (~> 1.0)
|
24
|
-
|
33
|
+
json (2.5.1)
|
34
|
+
method_source (0.9.2)
|
35
|
+
minitest (5.14.4)
|
25
36
|
multipart-post (2.1.1)
|
26
|
-
|
27
|
-
|
37
|
+
parallel (1.19.1)
|
38
|
+
parser (2.7.1.3)
|
39
|
+
ast (~> 2.4.0)
|
40
|
+
pry (0.12.2)
|
41
|
+
coderay (~> 1.1.0)
|
42
|
+
method_source (~> 0.9.0)
|
43
|
+
rainbow (3.0.0)
|
44
|
+
rake (13.0.1)
|
45
|
+
regexp_parser (1.7.1)
|
46
|
+
rexml (3.2.4)
|
28
47
|
rspec (3.8.0)
|
29
48
|
rspec-core (~> 3.8.0)
|
30
49
|
rspec-expectations (~> 3.8.0)
|
@@ -38,10 +57,24 @@ GEM
|
|
38
57
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
58
|
rspec-support (~> 3.8.0)
|
40
59
|
rspec-support (3.8.2)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
60
|
+
rubocop (0.85.1)
|
61
|
+
parallel (~> 1.10)
|
62
|
+
parser (>= 2.7.0.1)
|
63
|
+
rainbow (>= 2.2.2, < 4.0)
|
64
|
+
regexp_parser (>= 1.7)
|
65
|
+
rexml
|
66
|
+
rubocop-ast (>= 0.0.3)
|
67
|
+
ruby-progressbar (~> 1.7)
|
68
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
69
|
+
rubocop-ast (0.0.3)
|
70
|
+
parser (>= 2.7.0.1)
|
71
|
+
ruby-progressbar (1.10.1)
|
72
|
+
ruby2_keywords (0.0.4)
|
73
|
+
tzinfo (2.0.4)
|
74
|
+
concurrent-ruby (~> 1.0)
|
75
|
+
unicode-display_width (1.7.0)
|
76
|
+
yard (0.9.25)
|
77
|
+
zeitwerk (2.4.2)
|
45
78
|
|
46
79
|
PLATFORMS
|
47
80
|
ruby
|
@@ -49,8 +82,11 @@ PLATFORMS
|
|
49
82
|
DEPENDENCIES
|
50
83
|
bouncie!
|
51
84
|
bundler (~> 2.0)
|
52
|
-
|
85
|
+
pry
|
86
|
+
rake (~> 13.0)
|
53
87
|
rspec (~> 3.2)
|
88
|
+
rubocop (~> 0.85.1)
|
89
|
+
yard (~> 0.9.25)
|
54
90
|
|
55
91
|
BUNDLED WITH
|
56
|
-
2.
|
92
|
+
2.1.4
|
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/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'bouncie'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "bouncie"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/bouncie.gemspec
CHANGED
@@ -1,37 +1,42 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require
|
5
|
+
require 'bouncie/version'
|
4
6
|
|
5
7
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
8
|
+
spec.name = 'bouncie'
|
7
9
|
spec.version = Bouncie::VERSION
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
10
|
+
spec.authors = ['Corey Psoinos']
|
11
|
+
spec.email = ['corey@streetsmarts.io']
|
10
12
|
|
11
|
-
spec.summary =
|
13
|
+
spec.summary = 'An API wrapper for Bouncie'
|
12
14
|
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
13
|
-
|
15
|
+
spec.homepage = 'https://github.com/streetsmartslabs/bouncie'
|
14
16
|
|
15
17
|
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
19
21
|
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
22
|
|
21
23
|
# Specify which files should be added to the gem when it is released.
|
22
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
-
spec.files
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
26
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
27
|
end
|
26
|
-
spec.bindir =
|
28
|
+
spec.bindir = 'exe'
|
27
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = [
|
30
|
+
spec.require_paths = ['lib']
|
29
31
|
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
32
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
33
|
+
spec.add_development_dependency 'pry'
|
34
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
36
|
+
spec.add_development_dependency 'rubocop', '~> 0.85.1'
|
37
|
+
spec.add_development_dependency 'yard', '~> 0.9.25'
|
33
38
|
|
34
|
-
spec.add_dependency
|
35
|
-
spec.add_dependency
|
36
|
-
spec.add_dependency
|
39
|
+
spec.add_dependency 'activesupport'
|
40
|
+
spec.add_dependency 'faraday'
|
41
|
+
spec.add_dependency 'json'
|
37
42
|
end
|
data/lib/bouncie.rb
CHANGED
@@ -1,10 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bouncie/version'
|
2
4
|
require 'bouncie/client'
|
3
5
|
require 'bouncie/entity'
|
4
6
|
require 'bouncie/vehicle'
|
5
7
|
require 'bouncie/trip'
|
8
|
+
require 'bouncie/webhook'
|
9
|
+
require 'bouncie/user'
|
10
|
+
require 'bouncie/device_events/connect_event'
|
11
|
+
require 'bouncie/device_events/disconnect_event'
|
12
|
+
require 'bouncie/vehicle_health_events/battery_event'
|
13
|
+
require 'bouncie/vehicle_health_events/mil_event'
|
14
|
+
require 'bouncie/vehicle_trip_events/trip_data_event'
|
15
|
+
require 'bouncie/vehicle_trip_events/trip_end_event'
|
16
|
+
require 'bouncie/vehicle_trip_events/trip_metrics_event'
|
17
|
+
require 'bouncie/vehicle_trip_events/trip_start_event'
|
6
18
|
|
7
19
|
module Bouncie
|
8
20
|
class Error < StandardError; end
|
9
|
-
# Your code goes here...
|
10
21
|
end
|
data/lib/bouncie/client.rb
CHANGED
@@ -1,52 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday'
|
2
|
-
require '
|
4
|
+
require 'json'
|
3
5
|
|
4
6
|
module Bouncie
|
7
|
+
# Class that wraps a Faraday connection in order to interact with the Bouncie API
|
5
8
|
class Client
|
6
|
-
API_ENDPOINT = 'https://api.bouncie.dev/v1'
|
9
|
+
API_ENDPOINT = 'https://api.bouncie.dev/v1'
|
7
10
|
|
8
11
|
attr_reader :options
|
9
12
|
|
13
|
+
# @param [Hash] options the options to create a `Bouncie::Client` with.
|
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.
|
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.
|
19
|
+
# @option opts [Hash] :headers hash of any additional headers to add to HTTP requests
|
10
20
|
def initialize(options)
|
11
21
|
@options = options
|
12
22
|
end
|
13
23
|
|
24
|
+
# @param imei [String] (Required) IMEI for the vehicle to retrieve trips for
|
25
|
+
# @param transaction_id [String] Unique Trip Identifier
|
26
|
+
# @param gps_format [String] (Required) One of: `polyline` or `geojson`
|
27
|
+
# @param starts_after [ISODate] Will match trips with a starting time after this parameter. The window between starts-after and ends-before must be no longer than a week. If not provided, the last week will be used by default
|
28
|
+
# @param ends_before [ISODate] Will match trips with an ending time before this parameter
|
29
|
+
# @return [Trip]
|
14
30
|
def trips(imei:, transaction_id: nil, gps_format: 'polyline', starts_after: nil, ends_before: nil)
|
15
31
|
request(
|
16
32
|
http_method: :get,
|
17
|
-
endpoint:
|
33
|
+
endpoint: 'trips',
|
18
34
|
params: {
|
19
|
-
imei:
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
35
|
+
imei: imei,
|
36
|
+
transactionId: transaction_id,
|
37
|
+
gpsFormat: gps_format,
|
38
|
+
startsAfter: starts_after,
|
39
|
+
endsBefore: ends_before
|
24
40
|
}.compact
|
25
41
|
).map { |data| Bouncie::Trip.new(data) }
|
26
42
|
end
|
27
43
|
|
44
|
+
# @param vin [String] (optional) Vehicles with vin matching given value
|
45
|
+
# @param imei [String] (optional) Vehicles with imei matching given value
|
46
|
+
# @return [Vehicle]
|
28
47
|
def vehicles(imei: nil, vin: nil)
|
29
48
|
request(
|
30
49
|
http_method: :get,
|
31
50
|
endpoint: 'vehicles',
|
32
51
|
params: {
|
33
52
|
imei: imei,
|
34
|
-
vin:
|
53
|
+
vin: vin
|
35
54
|
}.compact
|
36
55
|
).map { |data| Bouncie::Vehicle.new(data) }
|
37
56
|
end
|
38
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
|
+
# rubocop:disable Metrics/AbcSize
|
68
|
+
def refresh!
|
69
|
+
resp = Faraday.post('https://auth.bouncie.com/oauth/token', {
|
70
|
+
client_id: options[:client_id],
|
71
|
+
client_secret: options[:client_secret],
|
72
|
+
grant_type: 'authorization_code',
|
73
|
+
code: options[:authorization_code],
|
74
|
+
redirect_uri: options[:redirect_uri]
|
75
|
+
})
|
76
|
+
if resp.success?
|
77
|
+
parsed_resp = JSON.parse(resp.body)
|
78
|
+
@headers = headers.merge(Authorization: parsed_resp['access_token'])
|
79
|
+
@client = build_client
|
80
|
+
end
|
81
|
+
resp
|
82
|
+
end
|
83
|
+
# rubocop:enable Metrics/AbcSize
|
84
|
+
|
39
85
|
private
|
40
86
|
|
41
87
|
def headers
|
42
|
-
@
|
43
|
-
'AuthorizationCode' => options[:authorization_code],
|
44
|
-
'ApiKey' => options[:api_key],
|
45
|
-
}.merge(options[:headers] || {})
|
88
|
+
@headers = { Authorization: options[:access_token] }.merge(options[:headers] || {})
|
46
89
|
end
|
47
90
|
|
48
91
|
def client
|
49
|
-
@
|
92
|
+
@client ||= build_client
|
93
|
+
end
|
94
|
+
|
95
|
+
def build_client
|
96
|
+
Faraday.new(API_ENDPOINT, headers: headers) do |client|
|
50
97
|
client.request :url_encoded
|
51
98
|
client.adapter Faraday.default_adapter
|
52
99
|
end
|
@@ -55,7 +102,7 @@ module Bouncie
|
|
55
102
|
def request(http_method:, endpoint:, params: {})
|
56
103
|
params.transform_keys! { |k| k.to_s.dasherize }
|
57
104
|
resp = client.public_send(http_method, endpoint, params)
|
58
|
-
|
105
|
+
JSON.parse(resp.body)
|
59
106
|
end
|
60
107
|
end
|
61
108
|
end
|
data/lib/bouncie/entity.rb
CHANGED
@@ -1,18 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/inflector'
|
2
4
|
|
3
5
|
module Bouncie
|
6
|
+
# Abstract base class for objects returned from API requests. Parses dates, converts keys to underscore.
|
4
7
|
class Entity
|
5
8
|
def initialize(data)
|
6
|
-
|
7
|
-
@data
|
8
|
-
if val.is_a?(Hash)
|
9
|
-
@data[key] = Bouncie::Entity.new(val)
|
10
|
-
elsif val.is_a?(Array)
|
11
|
-
@data[key] = val.map { |v| Bouncie::Entity.new(v) }
|
12
|
-
elsif val.is_a?(String) && ['_updated', '_time'].any? { |v| key.to_s.end_with?(v) }
|
13
|
-
@data[key] = DateTime.parse(val)
|
14
|
-
end
|
15
|
-
end
|
9
|
+
transformed = data.transform_keys { |k| k.to_s.underscore.to_sym }
|
10
|
+
@data = massage_data(transformed)
|
16
11
|
end
|
17
12
|
|
18
13
|
def method_missing(method_name, *args, &block)
|
@@ -23,8 +18,28 @@ module Bouncie
|
|
23
18
|
end
|
24
19
|
end
|
25
20
|
|
26
|
-
def respond_to_missing?(method_name,
|
21
|
+
def respond_to_missing?(method_name, _include_private = false)
|
27
22
|
@data.key?(method_name)
|
28
23
|
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def massage_data(input)
|
28
|
+
input.each_with_object({}) do |(key, val), memo|
|
29
|
+
memo[key] = massage_value(val)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def massage_value(value)
|
34
|
+
if value.is_a?(Hash)
|
35
|
+
Bouncie::Entity.new(value)
|
36
|
+
elsif value.is_a?(Array)
|
37
|
+
value.map { |v| massage_value(v) }
|
38
|
+
elsif value.is_a?(String) && value.match?(/^(\d{4})-(\d{2})-(\d{2})(T|\s)(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)((-(\d{2}):(\d{2})|Z)?)$/)
|
39
|
+
DateTime.parse(value)
|
40
|
+
else
|
41
|
+
value
|
42
|
+
end
|
43
|
+
end
|
29
44
|
end
|
30
45
|
end
|
data/lib/bouncie/trip.rb
CHANGED
data/lib/bouncie/user.rb
ADDED
data/lib/bouncie/vehicle.rb
CHANGED
data/lib/bouncie/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bouncie/device_events/connect_event'
|
4
|
+
require 'bouncie/device_events/disconnect_event'
|
5
|
+
require 'bouncie/vehicle_health_events/battery_event'
|
6
|
+
require 'bouncie/vehicle_health_events/mil_event'
|
7
|
+
require 'bouncie/vehicle_trip_events/trip_data_event'
|
8
|
+
require 'bouncie/vehicle_trip_events/trip_end_event'
|
9
|
+
require 'bouncie/vehicle_trip_events/trip_metrics_event'
|
10
|
+
require 'bouncie/vehicle_trip_events/trip_start_event'
|
11
|
+
|
12
|
+
module Bouncie
|
13
|
+
# Class used for parsing webhooks into specific events.
|
14
|
+
class Webhook
|
15
|
+
WEBHOOK_EVENTS_MAP = {
|
16
|
+
'connect' => Bouncie::DeviceEvents::ConnectEvent,
|
17
|
+
'disconnect' => Bouncie::DeviceEvents::DisconnectEvent,
|
18
|
+
'battery' => Bouncie::VehicleHealthEvents::BatteryEvent,
|
19
|
+
'mil' => Bouncie::VehicleHealthEvents::MilEvent,
|
20
|
+
'trip_data' => Bouncie::VehicleTripEvents::TripDataEvent,
|
21
|
+
'trip_end' => Bouncie::VehicleTripEvents::TripEndEvent,
|
22
|
+
'trip_metrics' => Bouncie::VehicleTripEvents::TripMetricsEvent,
|
23
|
+
'trip_start' => Bouncie::VehicleTripEvents::TripStartEvent
|
24
|
+
}.freeze
|
25
|
+
|
26
|
+
def self.parse(data)
|
27
|
+
event_name = data[:event_type] || data[:eventType] || data['eventType'] || data['event_type']
|
28
|
+
event_klass = Bouncie::Webhook::WEBHOOK_EVENTS_MAP[event_name.underscore]
|
29
|
+
event_klass.new(data)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
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
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Psoinos
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,20 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '13.0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '13.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +67,35 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.2'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.85.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.85.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.9.25
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.9.25
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
58
100
|
requirements:
|
59
101
|
- - ">="
|
@@ -67,7 +109,7 @@ dependencies:
|
|
67
109
|
- !ruby/object:Gem::Version
|
68
110
|
version: '0'
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
112
|
+
name: faraday
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
72
114
|
requirements:
|
73
115
|
- - ">="
|
@@ -81,7 +123,7 @@ dependencies:
|
|
81
123
|
- !ruby/object:Gem::Version
|
82
124
|
version: '0'
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
126
|
+
name: json
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
86
128
|
requirements:
|
87
129
|
- - ">="
|
@@ -94,15 +136,18 @@ dependencies:
|
|
94
136
|
- - ">="
|
95
137
|
- !ruby/object:Gem::Version
|
96
138
|
version: '0'
|
97
|
-
description:
|
139
|
+
description:
|
98
140
|
email:
|
99
141
|
- corey@streetsmarts.io
|
100
142
|
executables: []
|
101
143
|
extensions: []
|
102
144
|
extra_rdoc_files: []
|
103
145
|
files:
|
104
|
-
- ".github/workflows/
|
146
|
+
- ".github/workflows/lint.yml"
|
147
|
+
- ".github/workflows/matrix_testing.yml"
|
148
|
+
- ".github/workflows/publish.yml"
|
105
149
|
- ".gitignore"
|
150
|
+
- ".rubocop.yml"
|
106
151
|
- Gemfile
|
107
152
|
- Gemfile.lock
|
108
153
|
- README.md
|
@@ -112,14 +157,26 @@ files:
|
|
112
157
|
- bouncie.gemspec
|
113
158
|
- lib/bouncie.rb
|
114
159
|
- lib/bouncie/client.rb
|
160
|
+
- lib/bouncie/device_events/connect_event.rb
|
161
|
+
- lib/bouncie/device_events/disconnect_event.rb
|
115
162
|
- lib/bouncie/entity.rb
|
116
163
|
- lib/bouncie/trip.rb
|
164
|
+
- lib/bouncie/user.rb
|
117
165
|
- lib/bouncie/vehicle.rb
|
166
|
+
- lib/bouncie/vehicle_health_events/battery_event.rb
|
167
|
+
- lib/bouncie/vehicle_health_events/mil_event.rb
|
168
|
+
- lib/bouncie/vehicle_trip_events/trip_data_event.rb
|
169
|
+
- lib/bouncie/vehicle_trip_events/trip_end_event.rb
|
170
|
+
- lib/bouncie/vehicle_trip_events/trip_metrics_event.rb
|
171
|
+
- lib/bouncie/vehicle_trip_events/trip_start_event.rb
|
118
172
|
- lib/bouncie/version.rb
|
119
|
-
|
173
|
+
- lib/bouncie/webhook.rb
|
174
|
+
homepage: https://github.com/streetsmartslabs/bouncie
|
120
175
|
licenses: []
|
121
|
-
metadata:
|
122
|
-
|
176
|
+
metadata:
|
177
|
+
homepage_uri: https://github.com/streetsmartslabs/bouncie
|
178
|
+
source_code_uri: https://github.com/streetsmartslabs/bouncie
|
179
|
+
post_install_message:
|
123
180
|
rdoc_options: []
|
124
181
|
require_paths:
|
125
182
|
- lib
|
@@ -134,8 +191,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
191
|
- !ruby/object:Gem::Version
|
135
192
|
version: '0'
|
136
193
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
138
|
-
signing_key:
|
194
|
+
rubygems_version: 3.1.6
|
195
|
+
signing_key:
|
139
196
|
specification_version: 4
|
140
197
|
summary: An API wrapper for Bouncie
|
141
198
|
test_files: []
|
data/.github/workflows/main.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
name: Ruby Gem
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches: [ master ]
|
6
|
-
|
7
|
-
jobs:
|
8
|
-
build:
|
9
|
-
|
10
|
-
runs-on: ubuntu-latest
|
11
|
-
|
12
|
-
steps:
|
13
|
-
- uses: actions/checkout@v1
|
14
|
-
- name: Build and publish gem
|
15
|
-
uses: jstastny/publish-gem-to-github@master
|
16
|
-
with:
|
17
|
-
token: ${{ secrets.GITHUB_TOKEN }}
|
18
|
-
owner: cpsoinos
|