bouncie 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8e84f121b61b6c5a5e68d1feb194f4d8bda7bf3f7140acea247c1a5eb902ddc8
4
+ data.tar.gz: 0c01030fcd484fa5fec1287c50def1f24da174e4d1a252c794c90cabc5ab81d0
5
+ SHA512:
6
+ metadata.gz: 1fc30949fc6b0022762863df503c87f402fbfd96a34cbabc4a4a66f73db027fec41b866fbcfe5053fcf6542333e5d72c59b550e877e0015e70a42c489157c2fd
7
+ data.tar.gz: 5269d2dc832ed2e18b38e25b1d32d72aa9a77b68ac06e99c441d4175aa1454e8d39417d68e8098d3d9349c8ff39ed4f1b2f8952ce3c81188ac661fabb8eb0e17
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bouncie.gemspec
4
+ gemspec
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bouncie (0.1.0)
5
+ activesupport
6
+ faraday
7
+ oj
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (6.0.2)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ zeitwerk (~> 2.2)
18
+ concurrent-ruby (1.1.6)
19
+ diff-lcs (1.3)
20
+ faraday (1.0.1)
21
+ multipart-post (>= 1.2, < 3)
22
+ i18n (1.8.2)
23
+ concurrent-ruby (~> 1.0)
24
+ minitest (5.14.0)
25
+ multipart-post (2.1.1)
26
+ oj (3.10.6)
27
+ rake (10.5.0)
28
+ rspec (3.8.0)
29
+ rspec-core (~> 3.8.0)
30
+ rspec-expectations (~> 3.8.0)
31
+ rspec-mocks (~> 3.8.0)
32
+ rspec-core (3.8.2)
33
+ rspec-support (~> 3.8.0)
34
+ rspec-expectations (3.8.4)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.8.0)
37
+ rspec-mocks (3.8.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.8.0)
40
+ rspec-support (3.8.2)
41
+ thread_safe (0.3.6)
42
+ tzinfo (1.2.6)
43
+ thread_safe (~> 0.1)
44
+ zeitwerk (2.2.2)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ bouncie!
51
+ bundler (~> 2.0)
52
+ rake (~> 10.0)
53
+ rspec (~> 3.2)
54
+
55
+ BUNDLED WITH
56
+ 2.0.2
@@ -0,0 +1,37 @@
1
+ # Bouncie
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
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'bouncie'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install bouncie
22
+
23
+ ## Usage
24
+
25
+ Instantiate a client by passing an `options` hash with at least your app's `api_key` and your user account's `authorization_code'.
26
+
27
+ API documentation is available at [docs.bouncie.dev](https://docs.bouncie.dev).
28
+
29
+ ## Development
30
+
31
+ 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
+
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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bouncie.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bouncie"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "bouncie/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bouncie"
7
+ spec.version = Bouncie::VERSION
8
+ spec.authors = ["Corey Psoinos"]
9
+ spec.email = ["corey@streetsmarts.io"]
10
+
11
+ spec.summary = %q{An API wrapper for Bouncie}
12
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
13
+ # spec.homepage = "TODO: Put your gem's website or public repo URL here."
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ # spec.metadata["homepage_uri"] = spec.homepage
18
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
19
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 2.0"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.2"
33
+
34
+ spec.add_dependency "faraday"
35
+ spec.add_dependency "oj"
36
+ spec.add_dependency "activesupport"
37
+ end
@@ -0,0 +1,10 @@
1
+ require 'bouncie/version'
2
+ require 'bouncie/client'
3
+ require 'bouncie/entity'
4
+ require 'bouncie/vehicle'
5
+ require 'bouncie/trip'
6
+
7
+ module Bouncie
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,61 @@
1
+ require 'faraday'
2
+ require 'oj'
3
+
4
+ module Bouncie
5
+ class Client
6
+ API_ENDPOINT = 'https://api.bouncie.dev/v1'.freeze
7
+
8
+ attr_reader :options
9
+
10
+ def initialize(options)
11
+ @options = options
12
+ end
13
+
14
+ def trips(imei:, transaction_id: nil, gps_format: 'polyline', starts_after: nil, ends_before: nil)
15
+ request(
16
+ http_method: :get,
17
+ endpoint: 'trips',
18
+ params: {
19
+ imei: imei,
20
+ transaction_id: transaction_id,
21
+ gps_format: gps_format,
22
+ starts_after: starts_after,
23
+ ends_before: ends_before
24
+ }.compact
25
+ ).map { |data| Bouncie::Trip.new(data) }
26
+ end
27
+
28
+ def vehicles(imei: nil, vin: nil)
29
+ request(
30
+ http_method: :get,
31
+ endpoint: 'vehicles',
32
+ params: {
33
+ imei: imei,
34
+ vin: vin
35
+ }.compact
36
+ ).map { |data| Bouncie::Vehicle.new(data) }
37
+ end
38
+
39
+ private
40
+
41
+ def headers
42
+ @_headers ||= {
43
+ 'AuthorizationCode' => options[:authorization_code],
44
+ 'ApiKey' => options[:api_key],
45
+ }.merge(options[:headers] || {})
46
+ end
47
+
48
+ def client
49
+ @_client ||= Faraday.new(API_ENDPOINT, headers: headers) do |client|
50
+ client.request :url_encoded
51
+ client.adapter Faraday.default_adapter
52
+ end
53
+ end
54
+
55
+ def request(http_method:, endpoint:, params: {})
56
+ params.transform_keys! { |k| k.to_s.dasherize }
57
+ resp = client.public_send(http_method, endpoint, params)
58
+ Oj.load(resp.body)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,30 @@
1
+ require 'active_support/inflector'
2
+
3
+ module Bouncie
4
+ class Entity
5
+ def initialize(data)
6
+ @data = data.transform_keys { |k| k.underscore.to_sym }
7
+ @data.each do |key, val|
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
16
+ end
17
+
18
+ def method_missing(method_name, *args, &block)
19
+ if @data.key?(method_name)
20
+ @data[method_name]
21
+ else
22
+ super
23
+ end
24
+ end
25
+
26
+ def respond_to_missing?(method_name, include_private = false)
27
+ @data.key?(method_name)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ module Bouncie
2
+ class Trip < Entity
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Bouncie
2
+ class Vehicle < Entity
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Bouncie
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bouncie
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Corey Psoinos
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: oj
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - corey@streetsmarts.io
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".github/workflows/main.yml"
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - README.md
109
+ - Rakefile
110
+ - bin/console
111
+ - bin/setup
112
+ - bouncie.gemspec
113
+ - lib/bouncie.rb
114
+ - lib/bouncie/client.rb
115
+ - lib/bouncie/entity.rb
116
+ - lib/bouncie/trip.rb
117
+ - lib/bouncie/vehicle.rb
118
+ - lib/bouncie/version.rb
119
+ homepage:
120
+ licenses: []
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubygems_version: 3.0.4
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: An API wrapper for Bouncie
141
+ test_files: []