ballparc 0.1.1 → 0.1.2

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: 2ea22c1b29ab377f2d5147282a85a2862fb0ab9736322c038f3e697994c7fd02
4
- data.tar.gz: 6507cb0005195e4ea567ba27ab217da7d7116777eb0cea8eb5d205d1c9acc78e
3
+ metadata.gz: bf504281ce08b9faef0a59d1fddde69597a969746ec1e1f02b216e5c7a187eb6
4
+ data.tar.gz: ff5c93be2ea132f5c7cf5b665818b3d9e148439d08ad7fccdd1ad664c5cb6ba8
5
5
  SHA512:
6
- metadata.gz: e2c72e5e329d8145a499ee5b067943cf1d7ecf431c257a71a98e7a36a9a8a2937a7ccba49ed62a714f7607ef62c28af1e6ec07002b0285e9f94ea4b9fb08e6f0
7
- data.tar.gz: a0d71fcf725bc974dc49b29ac7678d234b7480ce8d84233208e7de7a0590e3bef2f4033906d8c9bd0421aaf74c638a89fd90e69416bb2f568189e8070e3a4fa1
6
+ metadata.gz: 88af63c04e10bf963acf567febdc29f53fe4d4e033fd3b7d47a383f4e542e345cddeacb7d7e0bac735b9e8a046304edf6a76850f919add2d2a4eb681c9ea83ca
7
+ data.tar.gz: b9aa10aec6eebda09a64af6eebcf454bd70db5a80feb7b614de9e0432609d9782bc082871063d9d3975551a7723de691701a9486e2234d6cd7d18ff75e2bf43b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ballparc (0.1.1)
4
+ ballparc (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -39,4 +39,4 @@ DEPENDENCIES
39
39
  rubocop (~> 1.21)
40
40
 
41
41
  BUNDLED WITH
42
- 2.5.5
42
+ 2.3.21
data/README.md CHANGED
@@ -23,55 +23,53 @@ If bundler is not being used to manage dependencies, install the gem by executin
23
23
 
24
24
  For creating parking_session in ballparc use this method:
25
25
 
26
- Ballparc.create_parking_session(endpoint, integration, body_data)
26
+ Ballparc.create_parking_session(body_data, debug = true)
27
27
 
28
28
  For deactivating parking_session in ballparc use this method:
29
29
 
30
- Ballparc.deactivate_parking_session(endpoint, integration, paid_vehicle_id)
30
+ Ballparc.deactivate_parking_session(paid_vehicle_id, debug = true)
31
31
 
32
32
  To view violation in ballparc use this method:
33
33
 
34
- Ballparc.view_violation(endpoint, integration, data)
35
-
36
- In above methods we pass 3 arguments:
37
- a). Endpoint is a ballparc API that we need to use, for testing we can use prefix mock server domain
34
+ Ballparc.view_violation(body_data, debug = true)
35
+
36
+ In above methods we pass 2 arguments:
37
+ a). Data is fields required by the ballparc API.
38
+ Example 1: For create parking session.
39
+
40
+ data:
41
+ { 'location_id': "Ballparc Location ID",
42
+ 'source': "Your Company API",
43
+ 'start_time': "2019-02-02 14:39:20",
44
+ 'end_time': "2019-02-03 14:39:20",
45
+ 'space_number': Space number,
46
+ 'plate_number': "123XYZ",
47
+ 'plate_state': "TN",
48
+ 'external_key': "A101"
49
+ }
38
50
 
39
- https://private-anon-71ed75e81f-ballparcv2.apiary-mock.com/
51
+ Example 2: For view violation.
40
52
 
41
- Example for creating paid vehicle use this mock server endpoint:
53
+ data = {start_date: '2024-01-21', end_date: '2024-01-23', plate_number: 'ABC12'}
42
54
 
43
- https://private-anon-71ed75e81f-ballparcv2.apiary-mock.com/enforcement/paid_vehicles
55
+ Example 3: For deactivate parking_session, we need to pass the ballparc paid vehicle's id.
44
56
 
45
- For production you can replace mock server domain with the production domain.
46
- Example:
57
+ b). Debug is an optional argument and it's a boolean flag for testing purpose only.
58
+ If debug is true then it will use the Ballparc's mock server to return actual response data so we can see the response data structure.
47
59
 
48
- production_domain/enforcement/paid_vehicles
60
+ Example: Ballparc.create_parking_session(body_data, debug = true)
49
61
 
50
- b). Integration is a row of table that must contain a column with 'header' name, and header must contain these key and value:
62
+ If we will not pass the debug in argument then gem will use the Ballparc's production server.
51
63
 
52
- header:
53
- { "accept"=>"application/x.ballparc.v2+json",
54
- "x-api-key"=>"Your ballparc API key",
55
- "content_type"=>"application/json",
56
- "x-api-secret"=>"Your ballparc API secret key" }
64
+ Example: Ballparc.create_parking_session(body_data)
57
65
 
58
- Note: You can send these headers in a variable, but make sure key must be same as above so you don't require a table.
66
+ For making this gem work we need to add two environment variables in our application with these names:
59
67
 
60
- c). Data is data required by the ballparc API.
61
- Example:
62
-
63
- {
64
- 'location_id': "Ballparc Location ID",
65
- 'source': "Your Company API",
66
- 'start_time': "2019-02-02 14:39:20",
67
- 'end_time': "2019-02-03 14:39:20",
68
- 'space_number': Space number,
69
- 'plate_number': "123XYZ",
70
- 'plate_state': "TN",
71
- 'external_key': "A101"
72
- }
68
+ BALLPARC_KEY=abcxyz
69
+ BALLPARC_SECRET=abcxyz
73
70
 
74
71
  For more information please see the Ballparc documentation [here](https://developer.ballparc.com/)
72
+
75
73
  ## License
76
74
 
77
75
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ballparc
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/ballparc.rb CHANGED
@@ -6,18 +6,22 @@ require 'json'
6
6
  require 'uri'
7
7
 
8
8
  module Ballparc
9
- def self.create_parking_session(endpoint, integration, body_data)
10
- endpoint += '?'
9
+ PROD_SERVER_DOMAIN = 'https://api.ballparc.com/enforcement'
10
+ MOCK_SERVER_DOMAIN = 'https://private-anon-b4097ff57b-ballparcv2.apiary-mock.com/enforcement'
11
+
12
+ def self.create_parking_session(body_data, for_debug = false)
13
+ check_endpoint(for_debug)
14
+ @endpoint += '/paid_vehicles?'
11
15
  body_data.each do |key, value|
12
- endpoint += "#{key}=#{value}&"
16
+ @endpoint += "#{key}=#{value}&"
13
17
  end
14
- endpoint.chop!
18
+ @endpoint.chop!
15
19
 
16
- url = URI(endpoint)
20
+ url = URI(@endpoint)
17
21
  http = Net::HTTP.new(url.host, url.port)
18
22
  http.use_ssl = true
19
23
  @req = Net::HTTP::Post.new(url)
20
- add_headers(integration)
24
+ add_headers
21
25
  response = http.request(@req)
22
26
 
23
27
  result = JSON.parse(response.body)
@@ -30,12 +34,13 @@ module Ballparc
30
34
  { message: e.message, status: :internal_server_error }
31
35
  end
32
36
 
33
- def self.view_violation(endpoint, integration, data)
34
- url = URI("#{endpoint}?start_date=#{data[:start_date]}&end_date=#{data[:end_date]}&plate_number=#{data[:plate_number]}")
37
+ def self.view_violation(data, for_debug = false)
38
+ check_endpoint(for_debug)
39
+ url = URI("#{@endpoint}/violations?start_date=#{data[:start_date]}&end_date=#{data[:end_date]}&plate_number=#{data[:plate_number]}")
35
40
  http = Net::HTTP.new(url.host, url.port)
36
41
  http.use_ssl = true
37
42
  @req = Net::HTTP::Get.new(url)
38
- add_headers(integration)
43
+ add_headers
39
44
  response = http.request(@req)
40
45
 
41
46
  result = JSON.parse(response.body)
@@ -48,12 +53,13 @@ module Ballparc
48
53
  { message: e.message, status: :internal_server_error }
49
54
  end
50
55
 
51
- def self.deactivate_parking_session(endpoint, integration, paid_vehicle_id)
52
- url = URI("#{endpoint}/#{paid_vehicle_id}")
56
+ def self.deactivate_parking_session(paid_vehicle_id, for_debug = false)
57
+ check_endpoint(for_debug)
58
+ url = URI("#{@endpoint}/paid_vehicles/#{paid_vehicle_id}")
53
59
  http = Net::HTTP.new(url.host, url.port)
54
60
  http.use_ssl = true
55
61
  @req = Net::HTTP::Delete.new(url)
56
- add_headers(integration)
62
+ add_headers
57
63
  response = http.request(@req)
58
64
 
59
65
  if response.code == '204'
@@ -65,9 +71,14 @@ module Ballparc
65
71
  { message: e.message, status: :internal_server_error }
66
72
  end
67
73
 
68
- def self.add_headers(integration)
69
- integration.header.each do |key, value|
70
- @req[key] = value
71
- end
74
+ def self.add_headers
75
+ @req['accept'] = 'application/x.ballparc.v2+json'
76
+ @req['content_type'] = 'application/json'
77
+ @req['x-api-key'] = ENV['BALLPARC_KEY']
78
+ @req['x-api-secret'] = ENV['BALLPARC_SECRET']
79
+ end
80
+
81
+ def self.check_endpoint(for_debug)
82
+ @endpoint = for_debug ? MOCK_SERVER_DOMAIN : PROD_SERVER_DOMAIN
72
83
  end
73
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ballparc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
- - Plecco
7
+ - PLECCO Technologies
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-07 00:00:00.000000000 Z
11
+ date: 2024-02-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Will be used for the Ballparc API integration.
14
14
  email:
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  requirements: []
49
- rubygems_version: 3.5.5
49
+ rubygems_version: 3.3.7
50
50
  signing_key:
51
51
  specification_version: 4
52
52
  summary: Will be used for the Ballparc API integration.