smartcar 3.0.5 → 3.1.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: b8dc25bb663d8c581e0c3f93b2ba5cb4f66c0a256dc740363f4feb3ccafe90c1
4
- data.tar.gz: c71d59a150f691b68d1ed15143195808c0477bdf51f886583878b6eba8e35a89
3
+ metadata.gz: 32c5b37d833b0951c08a33faa9e4c3af4cc02a5032b46fdd22ee80418aaa23ec
4
+ data.tar.gz: e89526a99861483111ef3fb8af353d64e2444f32641772e34a78f66524f66a7d
5
5
  SHA512:
6
- metadata.gz: 70c6cc755ca8b163eb46a4ed98da557315fd0213b3464556fb68156f9436f2a548cba21dc0a71ced2bda1e934d27ddcd663beab09f8361e8b04536d7a36d770f
7
- data.tar.gz: 2dfb31c7115cc455fee5efac58705be45f2eb4c0790ee4678a23ff4b43a02acbbf4d6952ecf85ec4136a3cd7af1855030e5c0fc3edeaae1ee2c0d18afe309303
6
+ metadata.gz: cc82965cdba424926a2929cc8c6ba9e9e9c957939b60fde968485ba04985dc50542372d7c42dbb6621fbda362f2666a8a67ee93b0665548f7806b6d46f85efc0
7
+ data.tar.gz: 0faa6f47b0242ec99b5d3752a7ae2507bea41da3bb1b9a41880dc22dd6ebcf50292456f00586f489095dc00c2f86924e76eef8170acfa48e410d0b4d13d46156
data/.rubocop.yml CHANGED
@@ -27,3 +27,6 @@ Metrics/MethodLength:
27
27
  Max: 20
28
28
  Exclude:
29
29
  - 'spec/smartcar/helpers/auth_helper.rb'
30
+
31
+ Metrics/ClassLength:
32
+ Max: 200
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smartcar (3.0.5)
4
+ smartcar (3.1.0)
5
5
  oauth2 (~> 1.4)
6
6
  recursive-open-struct (~> 1.1.3)
7
7
 
data/lib/smartcar/base.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'oauth2'
4
4
  require 'base64'
5
+ require 'rbconfig'
5
6
  module Smartcar
6
7
  # The Base class for all of the other class.
7
8
  # Let other classes inherit from here and put common methods here.
@@ -23,11 +24,15 @@ module Smartcar
23
24
  # @param data [Hash] request body if needed.
24
25
  #
25
26
  # @return [Hash] The response Json parsed as a hash.
26
- define_method verb do |path, data = nil|
27
+ define_method verb do |path, data = nil, headers = {}|
27
28
  response = service.send(verb) do |request|
28
- request.headers['Authorization'] = auth_type == BASIC ? "Basic #{token}" : "Bearer #{token}"
29
- request.headers['sc-unit-system'] = unit_system if unit_system
30
- request.headers['Content-Type'] = 'application/json'
29
+ request_headers = {}
30
+ request_headers['Authorization'] = auth_type == BASIC ? "Basic #{token}" : "Bearer #{token}"
31
+ request_headers['sc-unit-system'] = unit_system if unit_system
32
+ request_headers['Content-Type'] = 'application/json'
33
+ request_headers['User-Agent'] =
34
+ "Smartcar/#{VERSION} (#{RbConfig::CONFIG['host_os']}; #{RbConfig::CONFIG['arch']}) Ruby v#{RUBY_VERSION}"
35
+ request.headers = request_headers.merge(headers)
31
36
  complete_path = "/v#{version}#{path}"
32
37
  if verb == :get
33
38
  request.url complete_path, data
@@ -201,7 +201,7 @@ module Smartcar
201
201
  #
202
202
  # @param webhook_id [String] Webhook id to subscribe to
203
203
  #
204
- # @return [OpenStruct] And object representing the JSON response and a meta attribute
204
+ # @return [OpenStruct] An object representing the JSON response and a meta attribute
205
205
  # with the relevant items from response headers.
206
206
  def subscribe!(webhook_id)
207
207
  response, headers = post(METHODS.dig(:subscribe!, :path).call(id, webhook_id), {})
@@ -234,5 +234,22 @@ module Smartcar
234
234
  response, headers = post("/vehicles/#{id}/batch", request_body)
235
235
  process_batch_response(response, headers)
236
236
  end
237
+
238
+ # General purpose method to make requests to the Smartcar API - can be
239
+ # used to make requests to brand specific endpoints.
240
+ #
241
+ # @param method [String] The HTTP request method to use.
242
+ # @param path [String] The path to make the request to.
243
+ # @param body [Hash] The request body.
244
+ # @param headers [Hash] The headers to inlcude in the request.
245
+ #
246
+ # @return [OpenStruct] An object with a "body" attribute that contains the
247
+ # response body and a "meta" attribute with the relevant items from response headers.
248
+ def request(method, path, body = {}, headers = {})
249
+ path = "/vehicles/#{id}/#{path}"
250
+ raw_response, headers = send(method, path, body, headers)
251
+ meta = build_meta(headers)
252
+ json_to_ostruct({ body: raw_response, meta: meta })
253
+ end
237
254
  end
238
255
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Smartcar
4
4
  # Gem current version number
5
- VERSION = '3.0.5'
5
+ VERSION = '3.1.0'
6
6
  end
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.0.5
4
+ version: 3.1.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-19 00:00:00.000000000 Z
11
+ date: 2022-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler