ballparc 0.1.0 → 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 +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +52 -10
- data/lib/ballparc/version.rb +1 -1
- data/lib/ballparc.rb +37 -24
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf504281ce08b9faef0a59d1fddde69597a969746ec1e1f02b216e5c7a187eb6
|
4
|
+
data.tar.gz: ff5c93be2ea132f5c7cf5b665818b3d9e148439d08ad7fccdd1ad664c5cb6ba8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88af63c04e10bf963acf567febdc29f53fe4d4e033fd3b7d47a383f4e542e345cddeacb7d7e0bac735b9e8a046304edf6a76850f919add2d2a4eb681c9ea83ca
|
7
|
+
data.tar.gz: b9aa10aec6eebda09a64af6eebcf454bd70db5a80feb7b614de9e0432609d9782bc082871063d9d3975551a7723de691701a9486e2234d6cd7d18ff75e2bf43b
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
# Ballparc
|
2
|
+
This gem is for implementing the ballparc API for managing vehicle in ballparc Parking Management System. We used the ballparc API in this gem to create, update and deactivate vehicles also we can view violation using this gem. For now this gem can only create, deactivate and can view violation event using this gem methods.
|
2
3
|
|
3
|
-
|
4
|
+
## Installation
|
5
|
+
For adding this gem in application you can add gem name in gemfile and run the bundle command.
|
6
|
+
In gemfile add this line:
|
4
7
|
|
5
|
-
|
8
|
+
gem ballparc
|
6
9
|
|
7
|
-
|
10
|
+
In console run this command after adding gem in gemfile:
|
8
11
|
|
9
|
-
|
12
|
+
bundle
|
13
|
+
|
14
|
+
Also you can install the gem and add to the application's Gemfile by executing:
|
10
15
|
|
11
16
|
$ bundle add ballparc
|
12
17
|
|
@@ -16,17 +21,54 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
16
21
|
|
17
22
|
## Usage
|
18
23
|
|
19
|
-
|
24
|
+
For creating parking_session in ballparc use this method:
|
25
|
+
|
26
|
+
Ballparc.create_parking_session(body_data, debug = true)
|
27
|
+
|
28
|
+
For deactivating parking_session in ballparc use this method:
|
29
|
+
|
30
|
+
Ballparc.deactivate_parking_session(paid_vehicle_id, debug = true)
|
31
|
+
|
32
|
+
To view violation in ballparc use this method:
|
33
|
+
|
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
|
+
}
|
50
|
+
|
51
|
+
Example 2: For view violation.
|
52
|
+
|
53
|
+
data = {start_date: '2024-01-21', end_date: '2024-01-23', plate_number: 'ABC12'}
|
54
|
+
|
55
|
+
Example 3: For deactivate parking_session, we need to pass the ballparc paid vehicle's id.
|
56
|
+
|
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.
|
59
|
+
|
60
|
+
Example: Ballparc.create_parking_session(body_data, debug = true)
|
20
61
|
|
21
|
-
|
62
|
+
If we will not pass the debug in argument then gem will use the Ballparc's production server.
|
22
63
|
|
23
|
-
|
64
|
+
Example: Ballparc.create_parking_session(body_data)
|
24
65
|
|
25
|
-
|
66
|
+
For making this gem work we need to add two environment variables in our application with these names:
|
26
67
|
|
27
|
-
|
68
|
+
BALLPARC_KEY=abcxyz
|
69
|
+
BALLPARC_SECRET=abcxyz
|
28
70
|
|
29
|
-
|
71
|
+
For more information please see the Ballparc documentation [here](https://developer.ballparc.com/)
|
30
72
|
|
31
73
|
## License
|
32
74
|
|
data/lib/ballparc/version.rb
CHANGED
data/lib/ballparc.rb
CHANGED
@@ -6,21 +6,23 @@ require 'json'
|
|
6
6
|
require 'uri'
|
7
7
|
|
8
8
|
module Ballparc
|
9
|
-
|
10
|
-
|
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
|
-
req = Net::HTTP::Post.new(url)
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
response = http.request(req)
|
23
|
+
@req = Net::HTTP::Post.new(url)
|
24
|
+
add_headers
|
25
|
+
response = http.request(@req)
|
24
26
|
|
25
27
|
result = JSON.parse(response.body)
|
26
28
|
if response.code == '200' && result['data'].present?
|
@@ -32,15 +34,15 @@ module Ballparc
|
|
32
34
|
{ message: e.message, status: :internal_server_error }
|
33
35
|
end
|
34
36
|
|
35
|
-
def self.view_violation(
|
36
|
-
|
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]}")
|
37
40
|
http = Net::HTTP.new(url.host, url.port)
|
38
41
|
http.use_ssl = true
|
39
|
-
req = Net::HTTP::Get.new(url)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
response = http.request(req)
|
42
|
+
@req = Net::HTTP::Get.new(url)
|
43
|
+
add_headers
|
44
|
+
response = http.request(@req)
|
45
|
+
|
44
46
|
result = JSON.parse(response.body)
|
45
47
|
if response.code == '200' && result['data'].present?
|
46
48
|
{ message: 'Violation found.', ballparc_result: result, status: :ok }
|
@@ -51,15 +53,15 @@ module Ballparc
|
|
51
53
|
{ message: e.message, status: :internal_server_error }
|
52
54
|
end
|
53
55
|
|
54
|
-
def self.deactivate_parking_session(
|
55
|
-
|
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}")
|
56
59
|
http = Net::HTTP.new(url.host, url.port)
|
57
60
|
http.use_ssl = true
|
58
|
-
req = Net::HTTP::Delete.new(url)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
response = http.request(req)
|
61
|
+
@req = Net::HTTP::Delete.new(url)
|
62
|
+
add_headers
|
63
|
+
response = http.request(@req)
|
64
|
+
|
63
65
|
if response.code == '204'
|
64
66
|
{ message: 'Successfully deactivated paid vehicle', result_code: response.code.to_i, status: :ok }
|
65
67
|
else
|
@@ -68,4 +70,15 @@ module Ballparc
|
|
68
70
|
rescue StandardError => e
|
69
71
|
{ message: e.message, status: :internal_server_error }
|
70
72
|
end
|
73
|
+
|
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
|
83
|
+
end
|
71
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.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- PLECCO Technologies
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
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.
|
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.
|