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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40d934824d3e25fcc65341b37ebdc52f5e859f6a6b8fa43c0bb3818bc7fe7722
4
- data.tar.gz: 87c202e396dfc575a0b9642f25e2d96834d8710d30d5a1c862c88a1437b55779
3
+ metadata.gz: bf504281ce08b9faef0a59d1fddde69597a969746ec1e1f02b216e5c7a187eb6
4
+ data.tar.gz: ff5c93be2ea132f5c7cf5b665818b3d9e148439d08ad7fccdd1ad664c5cb6ba8
5
5
  SHA512:
6
- metadata.gz: a1719ebc2baa5a26d20321bd02952fc0866f9e75baf63a25e89c4d8b389bdf9d317072a96594d270f0d8154eb12b16c7b5008bef1d67b8ae6cb0de2cc14b3947
7
- data.tar.gz: 93786fa33285cf1f30bff3c606ef03e52e5d9b4bb64c6dcacde69010fe8dbaf74ec7ca23338879039a7de2c51fddbd18d6ed12ccedfc500c2bb12a96388902a3
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.0)
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.3.26
42
+ 2.3.21
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ballparc`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
8
+ gem ballparc
6
9
 
7
- ## Installation
10
+ In console run this command after adding gem in gemfile:
8
11
 
9
- Install the gem and add to the application's Gemfile by executing:
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
- TODO: Write usage instructions here
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
- ## Development
62
+ If we will not pass the debug in argument then gem will use the Ballparc's production server.
22
63
 
23
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
64
+ Example: Ballparc.create_parking_session(body_data)
24
65
 
25
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
66
+ For making this gem work we need to add two environment variables in our application with these names:
26
67
 
27
- ## Contributing
68
+ BALLPARC_KEY=abcxyz
69
+ BALLPARC_SECRET=abcxyz
28
70
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ballparc.
71
+ For more information please see the Ballparc documentation [here](https://developer.ballparc.com/)
30
72
 
31
73
  ## License
32
74
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ballparc
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/ballparc.rb CHANGED
@@ -6,21 +6,23 @@ 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
- req = Net::HTTP::Post.new(url)
20
- integration.header.each do |key, value|
21
- req[key] = value
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(endpoint, integration, data)
36
- 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]}")
37
40
  http = Net::HTTP.new(url.host, url.port)
38
41
  http.use_ssl = true
39
- req = Net::HTTP::Get.new(url)
40
- integration.header.each do |key, value|
41
- req[key] = value
42
- end
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(endpoint, integration, paid_vehicle_id)
55
- 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}")
56
59
  http = Net::HTTP.new(url.host, url.port)
57
60
  http.use_ssl = true
58
- req = Net::HTTP::Delete.new(url)
59
- integration.header.each do |key, value|
60
- req[key] = value
61
- end
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.0
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-02 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.