parking_ticket 1.0.1 → 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: 46eea131e0a69fa49115d452afc9ee575b52a06084eb8a026bf115b33b2d46f6
4
- data.tar.gz: 735ffb052fecb3599af5bf71ec7a28c60e48e8ed2025e8cb7923e7f6bb570851
3
+ metadata.gz: 683fc243081f913aef89d5424d206710fa0ddadd4eb8cf431f978046732cc57a
4
+ data.tar.gz: 64ee6ac6aedca57693dcd3266e89fb717abc46128ad5900bcaabf0f92656dc94
5
5
  SHA512:
6
- metadata.gz: 21652de95a323f337d244d5c652a826b5cda0de762c4d3e4f7be31bcf9b62a2e5e7d14eaf7744b48ac9c7aae1de0c03984e1fe3be76cf4cd34b9a4012e785857
7
- data.tar.gz: bfdc6306def10532b510639fe275c7e948f274797e99f4eb314e06a3af98502713e40e57e23756959137f51a0c7b4252caf1e26eaa8f8d6dd738ee02caf6e44a
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.1)
4
+ parking_ticket (1.0.32)
5
5
  faraday
6
6
 
7
7
  GEM
@@ -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
- 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.1'
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
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.1
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-16 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
@@ -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