parking_ticket 1.0.1 → 1.0.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/client/pay_by_phone/adapter.rb +10 -0
- data/lib/client/pay_by_phone/request.rb +28 -16
- data/lib/parking_ticket/version.rb +1 -1
- data/lib/parking_ticket.rb +32 -1
- data/parking_ticket-1.0.1.gem +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 683fc243081f913aef89d5424d206710fa0ddadd4eb8cf431f978046732cc57a
|
4
|
+
data.tar.gz: 64ee6ac6aedca57693dcd3266e89fb717abc46128ad5900bcaabf0f92656dc94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa871a2cba4a8364c5c051e599f1cbc4867cfcf4aa1d50ea5a021f876d45bbba019f292cf22500afff59be800e6ed926f5fa9877e6d15339919b3575a637c3d7
|
7
|
+
data.tar.gz: 3e240587339c43d75ccc9bdd48586b92daf1c2d1e51011fb82118d51d0372f358941012119fcab2b55896b3a1ba022b4b698c75a26de2273d4b1a4eec194c0b8
|
data/Gemfile.lock
CHANGED
@@ -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
|
@@ -98,22 +125,7 @@ module ParkingTicket
|
|
98
125
|
end
|
99
126
|
|
100
127
|
def token
|
101
|
-
|
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
|
data/lib/parking_ticket.rb
CHANGED
@@ -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
|
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.
|
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
|
11
|
+
date: 2023-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/parking_ticket/configuration.rb
|
48
48
|
- lib/parking_ticket/version.rb
|
49
49
|
- parking_ticket-1.0.0.gem
|
50
|
+
- parking_ticket-1.0.1.gem
|
50
51
|
homepage: https://github.com/troptropcontent/parking_ticket
|
51
52
|
licenses:
|
52
53
|
- MIT
|