smartcar 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32c5b37d833b0951c08a33faa9e4c3af4cc02a5032b46fdd22ee80418aaa23ec
4
- data.tar.gz: e89526a99861483111ef3fb8af353d64e2444f32641772e34a78f66524f66a7d
3
+ metadata.gz: af85a8f04bb5ecfd37182ae539ef60e5ca4e9487edf5db544109417df43d82d0
4
+ data.tar.gz: 5f2ccac9657e5e5b122b32943fa48845aa0acd5319dccc8836fd6b3cbf063ced
5
5
  SHA512:
6
- metadata.gz: cc82965cdba424926a2929cc8c6ba9e9e9c957939b60fde968485ba04985dc50542372d7c42dbb6621fbda362f2666a8a67ee93b0665548f7806b6d46f85efc0
7
- data.tar.gz: 0faa6f47b0242ec99b5d3752a7ae2507bea41da3bb1b9a41880dc22dd6ebcf50292456f00586f489095dc00c2f86924e76eef8170acfa48e410d0b4d13d46156
6
+ metadata.gz: 47abd5b611ddc7089be88614c2b79a4d2c33db498f1254eea55f2ed1426b795752b47b7e08e9ac8825086790313738f16affdf536ebed450963b36fd0d1305e3
7
+ data.tar.gz: 3ffef0a6f8f06da4c9f70a6798a9f701521831cdc30bbc183e613515b2b9520a492bd2d9e686a5c4cca0421d42def98bc0ccb6c4239cabd1d7b250ba5416f31d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smartcar (3.1.0)
4
+ smartcar (3.2.0)
5
5
  oauth2 (~> 1.4)
6
6
  recursive-open-struct (~> 1.1.3)
7
7
 
@@ -20,36 +20,16 @@ GEM
20
20
  rexml
21
21
  diff-lcs (1.5.0)
22
22
  docile (1.4.0)
23
- faraday (1.9.3)
24
- faraday-em_http (~> 1.0)
25
- faraday-em_synchrony (~> 1.0)
26
- faraday-excon (~> 1.1)
27
- faraday-httpclient (~> 1.0)
28
- faraday-multipart (~> 1.0)
29
- faraday-net_http (~> 1.0)
30
- faraday-net_http_persistent (~> 1.0)
31
- faraday-patron (~> 1.0)
32
- faraday-rack (~> 1.0)
33
- faraday-retry (~> 1.0)
23
+ faraday (2.2.0)
24
+ faraday-net_http (~> 2.0)
34
25
  ruby2_keywords (>= 0.0.4)
35
- faraday-em_http (1.0.0)
36
- faraday-em_synchrony (1.0.0)
37
- faraday-excon (1.1.0)
38
- faraday-httpclient (1.0.1)
39
- faraday-multipart (1.0.3)
40
- multipart-post (>= 1.2, < 3)
41
- faraday-net_http (1.0.1)
42
- faraday-net_http_persistent (1.2.0)
43
- faraday-patron (1.0.0)
44
- faraday-rack (1.0.0)
45
- faraday-retry (1.0.3)
26
+ faraday-net_http (2.0.2)
46
27
  hashdiff (1.0.1)
47
28
  jwt (2.3.0)
48
29
  multi_json (1.15.0)
49
30
  multi_xml (0.6.0)
50
- multipart-post (2.1.1)
51
- oauth2 (1.4.7)
52
- faraday (>= 0.8, < 2.0)
31
+ oauth2 (1.4.9)
32
+ faraday (>= 0.17.3, < 3.0)
53
33
  jwt (>= 1.0, < 3.0)
54
34
  multi_json (~> 1.3)
55
35
  multi_xml (~> 0.5)
data/README.md CHANGED
@@ -116,6 +116,32 @@ Example Usage for oAuth -
116
116
  # get a new token or use .
117
117
  ```
118
118
 
119
+ ## Advanced configuration
120
+
121
+ This SDK uses the [Faraday HTTP client library](https://lostisland.github.io/faraday/) which supports extensive customization through the use of middleware. If you need to customize the behavior of HTTP request/response processing, you can provide your own instance of Faraday::Connection to most methods in this library.
122
+
123
+ **Important:** If you provide your own Faraday connection, you are responsible for configuring all HTTP connection behavior, including timeouts! This SDK uses some custom timeouts internally to ensure best behavior by default, so unless you want to customize them you may want to replicate those timeouts.
124
+
125
+ Example of providing a custom Faraday connection to various methods:
126
+ ```ruby
127
+ # Example Faraday connection that uses the Instrumentation middleware
128
+ service = Faraday::Connection.new(url: Smartcar::API_ORIGIN, request: { timeout: Smartcar::DEFAULT_REQUEST_TIMEOUT }) do |c|
129
+ c.request :instrumentation
130
+ end
131
+
132
+ # Passing the custom service to #get_vehicles
133
+ Smartcar.get_vehicles(token: token, options: { service: service })
134
+
135
+ # Passing the custom service to #get_user
136
+ Smartcar.get_user(token: token, options: { service: service })
137
+
138
+ # Passing the custom service to #get_compatibility
139
+ Smartcar.get_compatibility(vin: vin, scope: scope, options: { service: service })
140
+
141
+ # Passing the custom service into a Smartcar::Vehicle object
142
+ vehicle = Smartcar::Vehicle.new(token: token, id: id, options: { service: service })
143
+ ```
144
+
119
145
  ## Development
120
146
 
121
147
  To install this gem onto your local machine, run `bundle exec rake install`.
data/lib/smartcar/base.rb CHANGED
@@ -13,8 +13,6 @@ module Smartcar
13
13
  class InvalidParameterValue < StandardError; end
14
14
  # Constant for Basic auth type
15
15
  BASIC = 'Basic'
16
- # Number of seconds to wait for response
17
- REQUEST_TIMEOUT = 310
18
16
 
19
17
  attr_accessor :token, :error, :unit_system, :version, :auth_type
20
18
 
@@ -65,7 +63,10 @@ module Smartcar
65
63
  #
66
64
  # @return [OAuth2::AccessToken] An initialized AccessToken instance that acts as service client
67
65
  def service
68
- @service ||= Faraday.new(url: ENV['SMARTCAR_API_ORIGIN'] || API_ORIGIN, request: { timeout: REQUEST_TIMEOUT })
66
+ @service ||= Faraday.new(
67
+ url: ENV['SMARTCAR_API_ORIGIN'] || API_ORIGIN,
68
+ request: { timeout: DEFAULT_REQUEST_TIMEOUT }
69
+ )
69
70
  end
70
71
  end
71
72
  end
@@ -11,6 +11,7 @@ module Smartcar
11
11
  # @attr [Hash] options
12
12
  # @attr unit_system [String] Unit system to represent the data in, defaults to Imperial
13
13
  # @attr version [String] API version to be used.
14
+ # @attr service [Faraday::Connection] An optional connection object to be used for requests.
14
15
  class Vehicle < Base
15
16
  attr_reader :id
16
17
 
@@ -69,12 +70,13 @@ module Smartcar
69
70
  }, skip: true }
70
71
  }.freeze
71
72
 
72
- def initialize(token:, id:, options: { unit_system: METRIC, version: Smartcar.get_api_version })
73
+ def initialize(token:, id:, options: {})
73
74
  super
74
75
  @token = token
75
76
  @id = id
76
- @unit_system = options[:unit_system]
77
- @version = options[:version]
77
+ @unit_system = options[:unit_system] || METRIC
78
+ @version = options[:version] || Smartcar.get_api_version
79
+ @service = options[:service]
78
80
 
79
81
  raise InvalidParameterValue.new, "Invalid Units provided : #{@unit_system}" unless UNITS.include?(@unit_system)
80
82
  raise InvalidParameterValue.new, 'Vehicle ID (id) is a required field' if id.nil?
@@ -247,7 +249,7 @@ module Smartcar
247
249
  # response body and a "meta" attribute with the relevant items from response headers.
248
250
  def request(method, path, body = {}, headers = {})
249
251
  path = "/vehicles/#{id}/#{path}"
250
- raw_response, headers = send(method, path, body, headers)
252
+ raw_response, headers = send(method.downcase, path, body, headers)
251
253
  meta = build_meta(headers)
252
254
  json_to_ostruct({ body: raw_response, meta: meta })
253
255
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Smartcar
4
4
  # Gem current version number
5
- VERSION = '3.1.0'
5
+ VERSION = '3.2.0'
6
6
  end
data/lib/smartcar.rb CHANGED
@@ -31,6 +31,9 @@ module Smartcar
31
31
  # Constant for units
32
32
  UNITS = [IMPERIAL, METRIC].freeze
33
33
 
34
+ # Number of seconds to wait for responses
35
+ DEFAULT_REQUEST_TIMEOUT = 310
36
+
34
37
  # Smartcar API version variable - defaulted to 2.0
35
38
  @api_version = '2.0'
36
39
 
@@ -54,22 +57,22 @@ module Smartcar
54
57
 
55
58
  # Module method Used to check compatiblity for VIN and scope
56
59
  #
57
- # API Documentation - https://smartcar.com/docs/api#connect-compatibility
60
+ # API Documentation - https://smartcar.com/docs/api#compatibility-api. Options Hash
58
61
  # @param vin [String] VIN of the vehicle to be checked
59
62
  # @param scope [Array of Strings] - array of scopes
60
63
  # @param country [String] An optional country code according to
61
- # [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
62
- # Defaults to US.
63
- # @param options [Hash] Other optional parameters including overrides
64
+ # [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2). Defaults to US.
65
+ # @param options [Hash] Other optional parameters including overrides (only valid for Smartcar API v1.0)
64
66
  # @option options [String] :client_id Client ID that overrides ENV
65
67
  # @option options [String] :client_secret Client Secret that overrides ENV
66
68
  # @option options [String] :version API version to use, defaults to what is globally set
67
69
  # @option options [Hash] :flags A hash of flag name string as key and a string or boolean value.
68
- # @option options [Boolean] :test_mode Wether to use test mode or not.
70
+ # @option options [Boolean] :test_mode Whether to use test mode or not.
69
71
  # @option options [String] :test_mode_compatibility_level this is required argument while using
70
72
  # test mode with a real vin. For more information refer to docs.
73
+ # @option options [Faraday::Connection] :service Optional connection object to be used for requests
71
74
  #
72
- # @return [OpenStruct] And object representing the JSON response mentioned in https://smartcar.com/docs/api#connect-compatibility
75
+ # @return [OpenStruct] And object representing the JSON response mentioned in https://smartcar.com/docs/api#compatibility-api
73
76
  # and a meta attribute with the relevant items from response headers.
74
77
  def get_compatibility(vin:, scope:, country: 'US', options: {})
75
78
  raise InvalidParameterValue.new, 'vin is a required field' if vin.nil?
@@ -78,7 +81,8 @@ module Smartcar
78
81
  base_object = Base.new(
79
82
  {
80
83
  version: options[:version] || Smartcar.get_api_version,
81
- auth_type: Base::BASIC
84
+ auth_type: Base::BASIC,
85
+ service: options[:service]
82
86
  }
83
87
  )
84
88
 
@@ -94,14 +98,18 @@ module Smartcar
94
98
  #
95
99
  # API Documentation - https://smartcar.com/docs/api#get-user
96
100
  # @param token [String] Access token
101
+ # @param version [String] Optional API version to use, defaults to what is globally set
102
+ # @param options [Hash] Other optional parameters including overrides
103
+ # @option options [Faraday::Connection] :service Optional connection object to be used for requests
97
104
  #
98
105
  # @return [OpenStruct] And object representing the JSON response mentioned in https://smartcar.com/docs/api#get-user
99
106
  # and a meta attribute with the relevant items from response headers.
100
- def get_user(token:, version: Smartcar.get_api_version)
107
+ def get_user(token:, version: Smartcar.get_api_version, options: {})
101
108
  base_object = Base.new(
102
109
  {
103
110
  token: token,
104
- version: version
111
+ version: version,
112
+ service: options[:service]
105
113
  }
106
114
  )
107
115
  base_object.build_response(*base_object.fetch(path: PATHS[:user]))
@@ -112,14 +120,18 @@ module Smartcar
112
120
  # API Documentation - https://smartcar.com/docs/api#get-all-vehicles
113
121
  # @param token [String] - Access token
114
122
  # @param paging [Hash] - Optional filter parameters (check documentation)
123
+ # @param version [String] Optional API version to use, defaults to what is globally set
124
+ # @param options [Hash] Other optional parameters including overrides
125
+ # @option options [Faraday::Connection] :service Optional connection object to be used for requests
115
126
  #
116
127
  # @return [OpenStruct] And object representing the JSON response mentioned in https://smartcar.com/docs/api#get-all-vehicles
117
128
  # and a meta attribute with the relevant items from response headers.
118
- def get_vehicles(token:, paging: {}, version: Smartcar.get_api_version)
129
+ def get_vehicles(token:, paging: {}, version: Smartcar.get_api_version, options: {})
119
130
  base_object = Base.new(
120
131
  {
121
132
  token: token,
122
- version: version
133
+ version: version,
134
+ service: options[:service]
123
135
  }
124
136
  )
125
137
  base_object.build_response(*base_object.fetch(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartcar
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ashwin Subramanian
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-28 00:00:00.000000000 Z
11
+ date: 2022-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler