parking_ticket 1.0.0 → 1.0.32

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: b2316d548e3f47bee94290a6e0b4399150d1db6948217c4a0434cae0b3ab5ebd
4
- data.tar.gz: 31cbaee19c0e458085ef5ab1c142d2fe5f24a82ff152e9e797c1a8e4ddd03782
3
+ metadata.gz: 683fc243081f913aef89d5424d206710fa0ddadd4eb8cf431f978046732cc57a
4
+ data.tar.gz: 64ee6ac6aedca57693dcd3266e89fb717abc46128ad5900bcaabf0f92656dc94
5
5
  SHA512:
6
- metadata.gz: e5c572a25ce7df3ab41f449dbaf1999df4efde403ccad560c87bf284ceb1e08ae3c072a4950a06244ffe94086b147fb0fb56d779a16315cdae05a34e5f39450f
7
- data.tar.gz: a1e55ec8f66f0909c49bd53d5cc89ceb243cd6f72d6070befe77f9f57c8b10d4650a396a5f7054cdec7959400e0cb2dd64f42415300bf168f74ebed8715d6e2a
6
+ metadata.gz: aa871a2cba4a8364c5c051e599f1cbc4867cfcf4aa1d50ea5a021f876d45bbba019f292cf22500afff59be800e6ed926f5fa9877e6d15339919b3575a637c3d7
7
+ data.tar.gz: 3e240587339c43d75ccc9bdd48586b92daf1c2d1e51011fb82118d51d0372f358941012119fcab2b55896b3a1ba022b4b698c75a26de2273d4b1a4eec194c0b8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parking_ticket (1.0.0)
4
+ parking_ticket (1.0.32)
5
5
  faraday
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ ![example workflow](https://github.com/troptropcontent/parking_ticket/actions/workflows/main.yml/badge.svg)
1
2
  # ParkingTicket
2
3
 
3
4
  This gem is a wrapper around the majors residential parking tickets api (for now only PayByPhone is supported).
@@ -22,22 +23,45 @@ Or install it yourself as:
22
23
 
23
24
  To make the gem work above your parking account you need set some environment variables :
24
25
 
25
- #PayByPhone :
26
- - `PAYBYPHONE_PASSWORD` : your PayByPhone password
27
- - `PAYBYPHONE_USERNAME` : your PayByPhone username (usually your phone number)
28
- - `PAYBYPHONE_LICENSEPLATE` : tyhe license plate of the car that must be covered
29
- - `PAYBYPHONE_ZIPCODE` : the zipcode you're resident in
30
- - `PAYBYPHONE_CARDNUMBER` : the credit card used to pay parking tickets (must be formated as folow xxxxxx------xxxx)
26
+ This give you access to a bunch of classes but the most important one is the ParkingTicket::Base.
31
27
 
32
- #Other apis to come
28
+ This class can be instanciated as follow :
33
29
 
34
- Two methods comes with the gem :
30
+ ```
31
+ parking_ticket = ParkingTicket::Base.new(
32
+ 'pay_by_phone',
33
+ {
34
+ username: your_pay_by_phone_username,
35
+ password: your_pay_by_phone_password,
36
+ license_plate: your_license_plate,
37
+ zipcode: the_zipcode_where_you_are_resident,
38
+ card_number: the_card_number_registered_on_pay_by_phone_you_want_to_use, # must be in the format : xxxxxx------xxxx
39
+ }
40
+ )
41
+ ```
42
+
43
+ Once instanciated and configured correctly (the methods won't work if the is a missing key in the confguration hash), you can use the two instance methods to do what you have to do :
35
44
 
36
- #`ParkingTicket.current_ticket`
37
- => returns an object representing a currently running residential ticket for your car. It returns nil if no ticket are found.
45
+ - #current_ticket
46
+ This checks if a ticket is currently running for the license_plate.
47
+ Returns :
48
+ ```
49
+ #if a ticket is found :
50
+ {
51
+ starts_on: 2023-01-11 15:40:22 UTC,
52
+ ends_on: 2023-01-18 15:40:22 UTC,
53
+ cost: 9.0,
54
+ license_plate: your_license_plate,
55
+ client: "PayByPhone",
56
+ client_ticket_id: the_id_returned_by_the_adapter,
57
+ }
58
+
59
+ #if no ticket is found
60
+ nil
61
+ ```
38
62
 
39
- #`ParkingTicket.renew`
40
- => register a new residential ticket for your car, this won't work if current_ticket returns something.
63
+ - #renew
64
+ This will trigger the renewal of your ticket, works only if no current_ticket is found
41
65
 
42
66
  Then you can create a scrypt like this one :
43
67
 
@@ -45,7 +69,16 @@ Then you can create a scrypt like this one :
45
69
  #your_scrypt.rb
46
70
  require 'parking_ticket'
47
71
 
48
- ticket_client = ParkingTicket.new
72
+ ticket_client = ParkingTicket::Base.new(
73
+ 'pay_by_phone',
74
+ {
75
+ username: your_pay_by_phone_username,
76
+ password: your_pay_by_phone_password,
77
+ license_plate: your_license_plate,
78
+ zipcode: the_zipcode_where_you_are_resident,
79
+ card_number: the_card_number_registered_on_pay_by_phone_you_want_to_use, # must be in the format : xxxxxx------xxxx
80
+ }
81
+ )
49
82
 
50
83
  unless ticket_client.current_ticket
51
84
  ticket_client.renew
@@ -53,7 +86,7 @@ end
53
86
 
54
87
  ```
55
88
 
56
- And play as often as you want to ensure that you always have a ticket for your car.
89
+ And play it as often as you want to ensure that you always have a ticket for your car.
57
90
  (But this is very HTTP request consuming, a lot of wasted request will be performed, i am sure that you can do better than that.)
58
91
 
59
92
  Exemple of application : [parkautomat](https://github.com/troptropcontent/parkautomat)
@@ -2,10 +2,20 @@ module ParkingTicket
2
2
  module Client
3
3
  module PayByPhone
4
4
  class Adapter
5
+ class << self
6
+ def valid_credentials?(username, password)
7
+ Request.valid_credentials?(username, password)
8
+ end
9
+ end
10
+
5
11
  def initialize(configuration)
6
12
  @configuration = configuration
7
13
  end
8
14
 
15
+ def valid_credentials?(_username, _password)
16
+ request.valid_credentials?(_username, _password)
17
+ end
18
+
9
19
  def covered?
10
20
  !!current_ticket
11
21
  end
@@ -3,6 +3,33 @@ module ParkingTicket
3
3
  module Client
4
4
  module PayByPhone
5
5
  class Request
6
+ class << self
7
+ def valid_credentials?(username, password)
8
+ auth(username, password).status == 200
9
+ end
10
+
11
+ private
12
+
13
+ def auth(username, password)
14
+ conn = Faraday.new('https://auth.paybyphoneapis.com') do |f|
15
+ f.response :json
16
+ end
17
+ conn.post(
18
+ '/token',
19
+ URI.encode_www_form({
20
+ grant_type: 'password',
21
+ username: username,
22
+ password: password,
23
+ client_id: 'paybyphone_web'
24
+ }),
25
+ {
26
+ 'Accept' => 'application/json, text/plain, */*',
27
+ 'X-Pbp-ClientType' => 'WebApp'
28
+ }
29
+ )
30
+ end
31
+ end
32
+
6
33
  def initialize(configuration)
7
34
  @configuration = configuration
8
35
  end
@@ -11,7 +38,7 @@ module ParkingTicket
11
38
  connection.get("/parking/accounts/#{account_id}/sessions?periodType=Current").body
12
39
  end
13
40
 
14
- def new_ticket(_account_id, _parking_start_time, _quote_id, _payment_method_id)
41
+ def new_ticket(account_id, parking_start_time, quote_id, payment_method_id)
15
42
  connection.post(
16
43
  "/parking/accounts/#{account_id}/sessions/",
17
44
  {
@@ -98,22 +125,7 @@ module ParkingTicket
98
125
  end
99
126
 
100
127
  def token
101
- conn = Faraday.new('https://auth.paybyphoneapis.com') do |f|
102
- f.response :json
103
- end
104
- conn.post(
105
- '/token',
106
- URI.encode_www_form({
107
- grant_type: 'password',
108
- username: @configuration.username,
109
- password: @configuration.password,
110
- client_id: 'paybyphone_web'
111
- }),
112
- {
113
- 'Accept' => 'application/json, text/plain, */*',
114
- 'X-Pbp-ClientType' => 'WebApp'
115
- }
116
- ).body['access_token']
128
+ self.class.send(:auth, @configuration.username, @configuration.password).body['access_token']
117
129
  end
118
130
  end
119
131
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ParkingTicket
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.32'
5
5
  end
@@ -10,6 +10,35 @@ require 'client/pay_by_phone/request'
10
10
 
11
11
  module ParkingTicket
12
12
  class Base
13
+ class << self
14
+ def valid_credentials?(adapter_name, username, password)
15
+ adapter = Client::PayByPhone::Adapter if adapter_name == 'pay_by_phone'
16
+ raise Error, 'EasyPark will be handled in the next major release' if adapter_name == 'easy_park'
17
+ raise Error, "Unhandled adapter : #{adapter_name}" unless adapter
18
+
19
+ adapter.valid_credentials?(username, password)
20
+ end
21
+
22
+ def config
23
+ yield(self)
24
+ end
25
+
26
+ attr_accessor :ticket_format
27
+
28
+ def format_ticket(ticket)
29
+ return unless ticket_format
30
+
31
+ ticket_format.each_with_object({}) do |element, acumulator|
32
+ if element.is_a?(Hash)
33
+ original_key = element.keys.first
34
+ target_key = element.values.first
35
+ acumulator[target_key] = ticket[original_key]
36
+ else
37
+ acumulator[element] = ticket[element]
38
+ end
39
+ end
40
+ end
41
+ end
13
42
  attr_reader :configuration
14
43
 
15
44
  class Error < StandardError
@@ -30,7 +59,9 @@ module ParkingTicket
30
59
  end
31
60
 
32
61
  def current_ticket
33
- adapter.current_ticket
62
+ ticket = adapter.current_ticket
63
+ ticket = self.class.format_ticket(ticket) if self.class.ticket_format && ticket
64
+ ticket
34
65
  end
35
66
 
36
67
  private
Binary file
Binary file
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.0
4
+ version: 1.0.32
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-01-13 00:00:00.000000000 Z
11
+ date: 2023-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -46,6 +46,8 @@ files:
46
46
  - lib/parking_ticket.rb
47
47
  - lib/parking_ticket/configuration.rb
48
48
  - lib/parking_ticket/version.rb
49
+ - parking_ticket-1.0.0.gem
50
+ - parking_ticket-1.0.1.gem
49
51
  homepage: https://github.com/troptropcontent/parking_ticket
50
52
  licenses:
51
53
  - MIT