onlia 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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +60 -0
- data/README.md +106 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/onlia/client.rb +75 -0
- data/lib/onlia/configuration.rb +25 -0
- data/lib/onlia/version.rb +3 -0
- data/lib/onlia.rb +20 -0
- data/onlia.gemspec +31 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 64b2dd88cdd507bb735093672593505d01a59a8cfd12d776b51ecffbb79e6f9f
|
4
|
+
data.tar.gz: '0619bfe84333a2c1c2090ce0e9fd6d8d7707f006de491a5fe129595cb292e547'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4d34b8cb7807a17fd222ba5964c404852c309636ad15b65ef41f2a30ab8d145475bd48e138cfaea27c8a8210f37b88da2c986b3e2f987470eeba15fbc2bdc717
|
7
|
+
data.tar.gz: 60da5f8668f9e94ce94ee3e1b6a8221606b8ac24e53925096cd028c1c8428c6ea4b5a2a8bbf6626efd1d11f54e29b3618776bd600e17371f4766b47e0e87b111
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
onlia (0.1.0)
|
5
|
+
jwt (~> 2.5.0)
|
6
|
+
rest-client (>= 2.1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
coderay (1.1.3)
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
domain_name (0.5.20190701)
|
14
|
+
unf (>= 0.0.5, < 1.0.0)
|
15
|
+
http-accept (1.7.0)
|
16
|
+
http-cookie (1.0.5)
|
17
|
+
domain_name (~> 0.5)
|
18
|
+
jwt (2.5.0)
|
19
|
+
method_source (1.0.0)
|
20
|
+
mime-types (3.4.1)
|
21
|
+
mime-types-data (~> 3.2015)
|
22
|
+
mime-types-data (3.2022.0105)
|
23
|
+
netrc (0.11.0)
|
24
|
+
pry (0.14.1)
|
25
|
+
coderay (~> 1.1)
|
26
|
+
method_source (~> 1.0)
|
27
|
+
rake (12.3.3)
|
28
|
+
rest-client (2.1.0)
|
29
|
+
http-accept (>= 1.7.0, < 2.0)
|
30
|
+
http-cookie (>= 1.0.2, < 2.0)
|
31
|
+
mime-types (>= 1.16, < 4.0)
|
32
|
+
netrc (~> 0.8)
|
33
|
+
rspec (3.11.0)
|
34
|
+
rspec-core (~> 3.11.0)
|
35
|
+
rspec-expectations (~> 3.11.0)
|
36
|
+
rspec-mocks (~> 3.11.0)
|
37
|
+
rspec-core (3.11.0)
|
38
|
+
rspec-support (~> 3.11.0)
|
39
|
+
rspec-expectations (3.11.1)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.11.0)
|
42
|
+
rspec-mocks (3.11.1)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.11.0)
|
45
|
+
rspec-support (3.11.1)
|
46
|
+
unf (0.1.4)
|
47
|
+
unf_ext
|
48
|
+
unf_ext (0.0.8.2)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
onlia!
|
55
|
+
pry
|
56
|
+
rake (~> 12.0)
|
57
|
+
rspec (~> 3.0)
|
58
|
+
|
59
|
+
BUNDLED WITH
|
60
|
+
2.2.26
|
data/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# Onlia
|
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/onlia`. 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 'onlia'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install onlia
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Configure Onlia in config/initializers/onlia.rb
|
26
|
+
```
|
27
|
+
Onlia.configure do |config|
|
28
|
+
config.environment = "development"
|
29
|
+
config.api_key = "api_token_here"
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
Create onlia client in config/initializers/onlia.rb
|
34
|
+
```
|
35
|
+
$onlia_client = Onlia::Client.new
|
36
|
+
```
|
37
|
+
|
38
|
+
Refresh token if needed
|
39
|
+
```
|
40
|
+
$onlia_client.refresh_token
|
41
|
+
```
|
42
|
+
|
43
|
+
Get quote for Onlia
|
44
|
+
```
|
45
|
+
$onlia_client.get_quote(
|
46
|
+
{
|
47
|
+
"product": {
|
48
|
+
"auto": {
|
49
|
+
"purchaseDate": "2021-12-20",
|
50
|
+
"purchaseConditionCode": 0,
|
51
|
+
"vehicleModelYear": 2021,
|
52
|
+
"onliaVehicleCode": "192600",
|
53
|
+
"yearlyMileage": 9999,
|
54
|
+
"businessUsePercentage": 0,
|
55
|
+
"distanceHomeWork": 10,
|
56
|
+
"postalCode": "M5E1W7",
|
57
|
+
"winterTireIndicator": true
|
58
|
+
},
|
59
|
+
"coverages": [
|
60
|
+
{
|
61
|
+
"productCoverageCode": 0,
|
62
|
+
"amount": 1000000
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"productCoverageCode": 1,
|
66
|
+
"amount": 1000
|
67
|
+
},
|
68
|
+
{
|
69
|
+
"productCoverageCode": 2,
|
70
|
+
"amount": 500
|
71
|
+
}
|
72
|
+
],
|
73
|
+
"startDate": "2022-10-24"
|
74
|
+
},
|
75
|
+
"person": {
|
76
|
+
"atFaultAccidentsDetails": [],
|
77
|
+
"dateOfBirth": "1989-11-13",
|
78
|
+
"drivingLicenseFirstDateOfIssue": "2010-12-13",
|
79
|
+
"genderCode": 0,
|
80
|
+
"licenseClass": "G",
|
81
|
+
"maritalStateCode": 0,
|
82
|
+
"numberOfConvictions": 0,
|
83
|
+
"postalCode": "M5E1W7",
|
84
|
+
"provinceCode": "ON"
|
85
|
+
}
|
86
|
+
}
|
87
|
+
)
|
88
|
+
```
|
89
|
+
|
90
|
+
Autolookup by vin
|
91
|
+
```
|
92
|
+
$onlia_client.auto_lookup(
|
93
|
+
{ "vin": "xyz" }
|
94
|
+
)
|
95
|
+
```
|
96
|
+
|
97
|
+
## Development
|
98
|
+
|
99
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
100
|
+
|
101
|
+
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).
|
102
|
+
|
103
|
+
## Contributing
|
104
|
+
|
105
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/metaware/onlia.
|
106
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "onlia"
|
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__)
|
data/bin/setup
ADDED
data/lib/onlia/client.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'jwt'
|
4
|
+
|
5
|
+
module Onlia
|
6
|
+
class Client
|
7
|
+
class ResponseError < StandardError; end
|
8
|
+
attr_accessor :api_token, :raw_token, :decoded_token
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.refresh_token
|
12
|
+
end
|
13
|
+
|
14
|
+
def refresh_token
|
15
|
+
@raw_token = get_token
|
16
|
+
@api_token = @raw_token["token"]
|
17
|
+
@decoded_token = JWT.decode(@api_token, nil, false).first
|
18
|
+
end
|
19
|
+
|
20
|
+
def refresh_if_required
|
21
|
+
if @decoded_token && @decoded_token["exp"] < Time.now.to_i
|
22
|
+
self.refresh_token
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def post(endpoint, body, token = nil)
|
27
|
+
self.refresh_if_required
|
28
|
+
endpoint_url = "#{Onlia.configuration.base_url}/#{endpoint}"
|
29
|
+
headers = {
|
30
|
+
"Content-Type" => "application/json",
|
31
|
+
"Accept" => "application/json",
|
32
|
+
}
|
33
|
+
headers["Authorization"] = "Bearer #{token}" if !token.nil?
|
34
|
+
begin
|
35
|
+
response = RestClient::Request.execute(method: :post, url: endpoint_url, payload: body.to_json, headers: headers)
|
36
|
+
JSON.parse(response.body)
|
37
|
+
rescue RestClient::ExceptionWithResponse => exception
|
38
|
+
JSON.parse(exception.response.body)
|
39
|
+
rescue JSON::ParserError => exception
|
40
|
+
puts exception.response
|
41
|
+
rescue RestClient::Unauthorized, RestClient::Forbidden => exception
|
42
|
+
puts exception.response
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_token
|
47
|
+
request_body = {"apiKey": Onlia.configuration.api_key}
|
48
|
+
post("/login", request_body)
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_quote(params)
|
52
|
+
post("/Auto/quote", params, @api_token)
|
53
|
+
end
|
54
|
+
|
55
|
+
def auto_lookup(params)
|
56
|
+
post("/Auto/lookup", params, @api_token)
|
57
|
+
end
|
58
|
+
|
59
|
+
# TODO: Add more methods here
|
60
|
+
def bind_agreement(params)
|
61
|
+
puts "TODO: bind_agreement"
|
62
|
+
# post("/Auto/bind", params, @api_token)
|
63
|
+
end
|
64
|
+
|
65
|
+
def start_agreement(params)
|
66
|
+
puts "TODO: start_agreement"
|
67
|
+
# post("/Auto/start", params, @api_token)
|
68
|
+
end
|
69
|
+
|
70
|
+
def end_agreement(params)
|
71
|
+
puts "TODO: end_agreement"
|
72
|
+
# post("/Auto/end", params, @api_token)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Onlia
|
2
|
+
class Configuration
|
3
|
+
class EnvironmentMismatch < StandardError; end
|
4
|
+
|
5
|
+
attr_accessor :environment, :base_url, :api_key
|
6
|
+
|
7
|
+
ENVIRONMENT_MAP = {
|
8
|
+
"production" => "https://api.onlia.ca/api/v1",
|
9
|
+
"development" => "https://test-api.onlia.ca/api/v1",
|
10
|
+
}
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@environment = "production"
|
14
|
+
@base_url = ENVIRONMENT_MAP[@environment]
|
15
|
+
@api_key = ""
|
16
|
+
end
|
17
|
+
|
18
|
+
def environment=(environment)
|
19
|
+
raise EnvironmentMismatch, "#{@environment} is an invalid environment value" if ENVIRONMENT_MAP[environment].nil?
|
20
|
+
|
21
|
+
@environment = environment
|
22
|
+
@base_url = ENVIRONMENT_MAP[@environment]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/onlia.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "pry"
|
2
|
+
require "onlia/version"
|
3
|
+
require "onlia/configuration"
|
4
|
+
require "onlia/client"
|
5
|
+
|
6
|
+
module Onlia
|
7
|
+
class Error < StandardError; end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure
|
15
|
+
yield(configuration)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
data/onlia.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'lib/onlia/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "onlia"
|
5
|
+
spec.version = Onlia::VERSION
|
6
|
+
spec.authors = ["Manpreet"]
|
7
|
+
spec.email = ["manpreet@metawarelabs.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Onlia is a Ruby gem that provides a simple interface to the Onlia API.}
|
10
|
+
spec.description = %q{Onlia is a Ruby gem that provides a simple interface to the Onlia API. It allows you to request quote from Onlia API.}
|
11
|
+
spec.homepage = "https://roam.auto"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/metaware/onlia"
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/metaware/onlia/Readme.md"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency('pry')
|
28
|
+
|
29
|
+
spec.add_dependency('rest-client', '>= 2.1.0')
|
30
|
+
spec.add_dependency('jwt', '~> 2.5.0')
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: onlia
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Manpreet
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-10-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jwt
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.5.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.5.0
|
55
|
+
description: Onlia is a Ruby gem that provides a simple interface to the Onlia API.
|
56
|
+
It allows you to request quote from Onlia API.
|
57
|
+
email:
|
58
|
+
- manpreet@metawarelabs.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/onlia.rb
|
73
|
+
- lib/onlia/client.rb
|
74
|
+
- lib/onlia/configuration.rb
|
75
|
+
- lib/onlia/version.rb
|
76
|
+
- onlia.gemspec
|
77
|
+
homepage: https://roam.auto
|
78
|
+
licenses: []
|
79
|
+
metadata:
|
80
|
+
homepage_uri: https://roam.auto
|
81
|
+
source_code_uri: https://github.com/metaware/onlia
|
82
|
+
changelog_uri: https://github.com/metaware/onlia/Readme.md
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 2.5.0
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.7.10
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Onlia is a Ruby gem that provides a simple interface to the Onlia API.
|
103
|
+
test_files: []
|