parking_ticket 1.0.40 → 1.0.42

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a45be3c94ffccf5e5e1f66abf01a80528a5f9ab95d22b7bbd281996889b3cd5f
4
- data.tar.gz: 52609368928c5d70bc382619b39bf2962209be2e0456bc90a4e0d89dfb3f0954
3
+ metadata.gz: 6e77e38e86c6e6caa460258bbcaadc68d36cd9132bcfa1addac8076241d7ccb1
4
+ data.tar.gz: 1dbf3192eff48e871d11cbddccbd671e123c8c04340511df1e69e89f76920d89
5
5
  SHA512:
6
- metadata.gz: 50c8f9a60ea1f075914e468fbb7057997397a2fd800003321e0f4e03a4e1efbcfc11b6352b6b3d508b1ac95cd5b823738385b8b8c31c298179cb7a7307a9fa02
7
- data.tar.gz: 5bc40023e17ed5235bccdbddd27d3e78e4cdea6c7e43ecc58397e81e85be5637ce5418106ffb0ab4f8c447660b65e19312a3da7f0d2979c4d14d00eaff2184a8
6
+ metadata.gz: 314a53f64ffcc2242859c3f1c3469d3511989b370aa4ca62f94f9769ab78433d6bbb889df6af732d86a8e39c5bc0c66d29f4d3ebb6354c3fe24e4c738fae50a0
7
+ data.tar.gz: 3ab7e2363a945b4f791551dc7d195599949e750fabdd04ede23f19dcef631150f9c4f7f4061a6685720767ba1564c289823128b8e00d33f91552224beef061fe
data/Gemfile CHANGED
@@ -14,8 +14,6 @@ gem 'vcr', '~> 6.0'
14
14
  # Mock web requests in tests
15
15
  gem 'webmock', '~> 3.12'
16
16
 
17
- gem 'byebug'
18
-
19
17
  gem 'faraday', '~> 2.7', '>= 2.7.2'
20
18
 
21
19
  gem 'json_matchers'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parking_ticket (1.0.40)
4
+ parking_ticket (1.0.42)
5
5
  faraday
6
6
 
7
7
  GEM
@@ -9,7 +9,6 @@ GEM
9
9
  specs:
10
10
  addressable (2.8.1)
11
11
  public_suffix (>= 2.0.2, < 6.0)
12
- byebug (11.1.3)
13
12
  crack (0.4.5)
14
13
  rexml
15
14
  diff-lcs (1.5.0)
@@ -49,7 +48,6 @@ PLATFORMS
49
48
  x86_64-linux
50
49
 
51
50
  DEPENDENCIES
52
- byebug
53
51
  faraday (~> 2.7, >= 2.7.2)
54
52
  json_matchers
55
53
  parking_ticket!
@@ -59,4 +57,4 @@ DEPENDENCIES
59
57
  webmock (~> 3.12)
60
58
 
61
59
  BUNDLED WITH
62
- 2.2.32
60
+ 2.3.10
@@ -1,4 +1,3 @@
1
- require 'byebug'
2
1
  module ParkingTicket
3
2
  module Clients
4
3
  class Adapter
@@ -39,11 +38,17 @@ module ParkingTicket
39
38
  fetch_and_map_payment_methods
40
39
  end
41
40
 
42
- def new_ticket(license_plate, zipcode, rate_option_id, quantity, time_unit, payment_method_id)
41
+ def quote(rate_option_id, zipcode, license_plate, quantity, time_unit)
42
+ raise_invalid_credentials! unless valid_credentials?
43
+ fetch_and_map_quote(rate_option_id, zipcode, license_plate, quantity, time_unit)
44
+ end
45
+
46
+ def new_ticket(license_plate, zipcode, rate_option_id, quantity, time_unit, payment_method_id:)
43
47
  raise_invalid_credentials! unless valid_credentials?
44
48
  return if running_ticket(license_plate, zipcode)
45
49
 
46
- request_new_ticket(license_plate, zipcode, rate_option_id, quantity, time_unit, payment_method_id)
50
+ request_new_ticket(license_plate, zipcode, rate_option_id, quantity, time_unit,
51
+ payment_method_id: payment_method_id)
47
52
  end
48
53
 
49
54
  private
@@ -54,20 +54,17 @@ module ParkingTicket
54
54
  end.first
55
55
  end
56
56
 
57
- def request_new_ticket(license_plate, zipcode, rate_option_id, quantity, time_unit, payment_method_id)
57
+ def request_new_ticket(license_plate, zipcode, rate_option_id, quantity, time_unit, payment_method_id:)
58
58
  mapped_time_unit = ACCEPTED_TIME_UNIT_MAPPER.key(time_unit)
59
- payment_method = fetch_and_map_payment_methods.find do |payment_method|
60
- payment_method[:client_internal_id] == payment_method_id
61
- end
62
59
  quote = fetch_and_map_quote(rate_option_id, zipcode, license_plate, quantity, mapped_time_unit)
63
60
  client.new_ticket(
64
61
  quote[:client_internal_id],
65
- payment_method[:client_internal_id],
66
62
  zipcode,
67
63
  license_plate,
68
64
  quantity,
69
65
  mapped_time_unit,
70
- quote[:starts_on]
66
+ quote[:starts_on],
67
+ payment_method_id: payment_method_id
71
68
  )
72
69
  end
73
70
 
@@ -82,11 +79,14 @@ module ParkingTicket
82
79
  end
83
80
 
84
81
  def fetch_and_map_quote(rate_option_id, zipcode, license_plate, quantity, time_unit)
85
- fetched_quote = client.quote(rate_option_id, zipcode, license_plate, quantity, time_unit)
82
+ mapped_time_unit = ACCEPTED_TIME_UNIT_MAPPER.key(time_unit)
83
+ fetched_quote = client.quote(rate_option_id, zipcode, license_plate, quantity, mapped_time_unit)
84
+
86
85
  {
87
86
  client_internal_id: fetched_quote['quoteId'],
88
87
  starts_on: fetched_quote['parkingStartTime'],
89
- ends_on: fetched_quote['parkingExpiryTime']
88
+ ends_on: fetched_quote['parkingExpiryTime'],
89
+ cost: fetched_quote.dig('totalCost', 'amount')
90
90
  }
91
91
  end
92
92
  end
@@ -58,38 +58,45 @@ module ParkingTicket
58
58
  ).body
59
59
  end
60
60
 
61
- def new_ticket(token, account_id, quote_id, payment_method_id, zipcode, license_plate, quantity, time_unit, start_time)
62
- connection(token).post(
63
- "/parking/accounts/#{account_id}/sessions/",
64
- {
65
- "expireTime": nil,
66
- "duration": {
67
- "quantity": quantity,
68
- "timeUnit": time_unit
69
- },
70
- "licensePlate": license_plate,
71
- "locationId": zipcode,
72
- "rateOptionId": '75101',
73
- "startTime": start_time,
74
- "quoteId": quote_id,
75
- "parkingAccountId": account_id,
76
- "paymentMethod": {
77
- "paymentMethodType": 'PaymentAccount',
78
- "payload": {
79
- "paymentAccountId": payment_method_id,
80
- "clientBrowserDetails": {
81
- "browserAcceptHeader": 'text/html',
82
- "browserColorDepth": '30',
83
- "browserJavaEnabled": 'false',
84
- "browserLanguage": 'fr-FR',
85
- "browserScreenHeight": '900',
86
- "browserScreenWidth": '1440',
87
- "browserTimeZone": '-60',
88
- "browserUserAgent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36'
89
- }
61
+ def new_ticket(token, account_id, quote_id, zipcode, license_plate, quantity, time_unit, start_time, payment_method_id:)
62
+ base_data = {
63
+ "expireTime": nil,
64
+ "duration": {
65
+ "quantity": quantity,
66
+ "timeUnit": time_unit
67
+ },
68
+ "licensePlate": license_plate,
69
+ "locationId": zipcode,
70
+ "rateOptionId": '75101',
71
+ "startTime": start_time,
72
+ "quoteId": quote_id,
73
+ "parkingAccountId": account_id
74
+ }
75
+
76
+ payment_data = {
77
+ "paymentMethod": {
78
+ "paymentMethodType": 'PaymentAccount',
79
+ "payload": {
80
+ "paymentAccountId": payment_method_id,
81
+ "clientBrowserDetails": {
82
+ "browserAcceptHeader": 'text/html',
83
+ "browserColorDepth": '30',
84
+ "browserJavaEnabled": 'false',
85
+ "browserLanguage": 'fr-FR',
86
+ "browserScreenHeight": '900',
87
+ "browserScreenWidth": '1440',
88
+ "browserTimeZone": '-60',
89
+ "browserUserAgent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36'
90
90
  }
91
91
  }
92
- }.to_json
92
+ }
93
+ }
94
+
95
+ final_data = payment_method_id ? base_data.merge(payment_data) : base_data
96
+
97
+ connection(token).post(
98
+ "/parking/accounts/#{account_id}/sessions/",
99
+ final_data.to_json
93
100
  ).body
94
101
  end
95
102
 
@@ -137,9 +144,9 @@ module ParkingTicket
137
144
  self.class.quote(token, account_id, rate_option_id, zipcode, license_plate, quantity, time_unit)
138
145
  end
139
146
 
140
- def new_ticket(quote_id, payment_method_id, zipcode, license_plate, quantity, time_unit, start_time)
141
- self.class.new_ticket(token, account_id, quote_id, payment_method_id, zipcode, license_plate, quantity,
142
- time_unit, start_time)
147
+ def new_ticket(quote_id, zipcode, license_plate, quantity, time_unit, start_time, payment_method_id:)
148
+ self.class.new_ticket(token, account_id, quote_id, zipcode, license_plate, quantity,
149
+ time_unit, start_time, payment_method_id)
143
150
  end
144
151
 
145
152
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ParkingTicket
4
- VERSION = '1.0.40'
4
+ VERSION = '1.0.42'
5
5
  end
@@ -70,6 +70,10 @@ module ParkingTicket
70
70
  adapter.new_ticket(license_plate, zipcode, rate_option_id, quantity, time_unit, payment_method_id)
71
71
  end
72
72
 
73
+ def quote(rate_option_id, zipcode, license_plate, quantity, time_unit)
74
+ adapter.quote(rate_option_id, zipcode, license_plate, quantity, time_unit)
75
+ end
76
+
73
77
  private
74
78
 
75
79
  def load_adapter!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parking_ticket
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.40
4
+ version: 1.0.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Ecrepont
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-17 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday