vng 0.1.17 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 151dfd76cad24aec1874237ce91d55347fb02a80514775184d36dd13982b0cf5
4
- data.tar.gz: 71044094cc3ff08ba6293b76b6c90a4396b45e25595dc33701260a47faf046af
3
+ metadata.gz: 706982b8a7566e56016073d4d5a0e049ed351da4cebab7ca002d7b52b49e46a8
4
+ data.tar.gz: 15f60eb8f382d6d4d48903dec324b2251617ae46d28ba0c14fef5471a1060d35
5
5
  SHA512:
6
- metadata.gz: 85a83c23434b23423675b35cae76107db4cbafc6d3c6511515c40a25b0eab74f0adea860e8590fdb1bb208095988b5a49d86e9c33f358500b087edcccf163174
7
- data.tar.gz: 94e0965205d433bae8bf4db0ab0ff3ea9e777c8b15f55f4435d5baa7cae9adc121d5a9e02eceb424b03b978e5bb12c6377f2b39d1c7a4486c440b7075447f7e7
6
+ metadata.gz: 2a1b3bab28a45018a6a3876c066c9a1d95c376c1d336e83f607c822cbd5bb84b11222f36ce8ca22a9198bca7d0f67a90fd476e61b99601a10a021dc5115fec90
7
+ data.tar.gz: 578f75157f4e0e326ec427cf64bc7c42b84dcecbcd37eaeec20cec7f4a6254b44c0eaaa1b69e4e614c64f9a183859041bbeb85b606a5b488daf75ce4cc850c18
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.19] - 2024-11-19
4
+
5
+ - Adds Route
6
+
7
+ ## [0.1.18] - 2024-11-19
8
+
9
+ - Ensure a plus sign in the email is not translated into a space
10
+
3
11
  ## [0.1.17] - 2024-11-17
4
12
 
5
13
  - Require at least 30 minutes for slot
data/README.md CHANGED
@@ -84,6 +84,8 @@ To run tests:
84
84
  rspec
85
85
  ```
86
86
 
87
+ Set `VNG_MOCK=1` to test against HTTP mocks.
88
+
87
89
  How to release new versions
88
90
  ===========================
89
91
 
@@ -40,12 +40,16 @@ module Vng
40
40
  # @return [String] the password for the API calls.
41
41
  attr_accessor :password
42
42
 
43
+ # @return [Boolean] whether to mock the HTTP calls to Vonigo
44
+ attr_accessor :mock
45
+
43
46
  # Initialize the global configuration settings, using the values of
44
47
  # the specified following environment variables by default.
45
48
  def initialize
46
49
  @host = ENV['VNG_HOST']
47
50
  @username = ENV['VNG_USERNAME']
48
51
  @password = ENV['VNG_PASSWORD']
52
+ @mock = ENV['VNG_MOCK'] == '1'
49
53
  end
50
54
  end
51
55
  end
data/lib/vng/contact.rb CHANGED
@@ -22,7 +22,7 @@ module Vng
22
22
  Fields: [
23
23
  {fieldID: 127, fieldValue: first_name},
24
24
  {fieldID: 128, fieldValue: last_name},
25
- {fieldID: 97, fieldValue: email},
25
+ {fieldID: 97, fieldValue: URI.encode_uri_component(email)},
26
26
  {fieldID: 96, fieldValue: phone},
27
27
  ]
28
28
  }
data/lib/vng/lead.rb CHANGED
@@ -20,7 +20,7 @@ module Vng
20
20
  Fields: [
21
21
  {fieldID: 121, optionID: '59'},
22
22
  {fieldID: 126, fieldValue: name},
23
- {fieldID: 238, fieldValue: email},
23
+ {fieldID: 238, fieldValue: URI.encode_uri_component(email)},
24
24
  {fieldID: 1024, fieldValue: phone},
25
25
  ]
26
26
  }
@@ -0,0 +1,107 @@
1
+ require 'vng/connection_error'
2
+ require 'vng/error'
3
+
4
+ module Vng
5
+ # Provides an abstract class for every Vonigo resource.
6
+ class Resource
7
+ private
8
+ def self.request(path:, body: {}, query: {}, include_security_token: true)
9
+ if Vng.configuration.mock
10
+ mock_request path:, body:, query:
11
+ else
12
+ http_request(path:, body:, query:, include_security_token:)
13
+ end
14
+ end
15
+
16
+ def self.mock_request(path:, body:, query:)
17
+ case path
18
+ when '/api/v1/security/login/'
19
+ {"securityToken"=>"1234567"}
20
+ when '/api/v1/resources/zips/'
21
+ {"Zips"=>[{"zip"=>"21765", "zoneName"=>"Brentwood", "state"=>"MD"}]}
22
+ when '/api/v1/resources/franchises/'
23
+ {"Franchises"=>[
24
+ {"franchiseID"=>106, "franchiseName"=>"Mississauga", "gmtOffsetFranchise"=>-300, "isActive"=>false},
25
+ {"franchiseID"=>107, "franchiseName"=>"Boise", "gmtOffsetFranchise"=>-420, "isActive"=>true},
26
+ ]}
27
+ when '/api/v1/resources/availability/'
28
+ if body.key?(:zip)
29
+ {"Ids"=>{"franchiseID"=>"172"}}
30
+ elsif body[:method] == '2'
31
+ {"Ids"=>{"lockID"=>"1406328"}}
32
+ else
33
+ {"Availability"=> [
34
+ {"dayID"=>"20241119", "routeID"=>"8949", "startTime"=>"1080"},
35
+ {"dayID"=>"20241119", "routeID"=>"8949", "startTime"=>"1110"},
36
+ ]}
37
+ end
38
+ when '/api/v1/resources/breeds/'
39
+ {"Breeds"=>[{"breedID"=>2, "breed"=>"Bulldog", "species"=>"Dog", "optionID"=>303, "breedLowWeight"=>30, "breedHighWeight"=>50}]}
40
+ when '/api/v1/data/Leads/'
41
+ {"Client"=>{"objectID"=>"916347"}, "Fields"=>[
42
+ {"fieldID"=>126, "fieldValue"=>"Vng Example"},
43
+ {"fieldID"=>238, "fieldValue"=>"vng@example.com"},
44
+ {"fieldID"=>1024, "fieldValue"=>"8648648640"},
45
+ ]}
46
+ when '/api/v1/data/Contacts/'
47
+ {"Contact"=>{"objectID"=>"2201007"}, "Fields"=>[
48
+ {"fieldID"=>127, "fieldValue"=>"Vng"},
49
+ {"fieldID"=>128, "fieldValue"=>"Example"},
50
+ {"fieldID"=>97, "fieldValue"=>"vng@example.com"},
51
+ {"fieldID"=>96, "fieldValue"=>"8648648640"},
52
+ ]}
53
+ when '/api/v1/data/Locations/'
54
+ {"Location"=>{"objectID"=>"995681"}}
55
+ when '/api/v1/data/Assets/'
56
+ {"Asset"=>{"objectID"=>"2201008"}}
57
+ when '/api/v1/data/priceLists/'
58
+ {"PriceItems"=>[
59
+ {"priceItemID"=>275111, "priceItem"=>"15 Step SPA Grooming", "value"=>85.0, "taxID"=>256, "durationPerUnit"=>45.0, "serviceBadge"=>"Required", "serviceCategory"=>"15 Step Spa", "isOnline"=>true, "isActive"=>true},
60
+ {"priceItemID"=>275300, "priceItem"=>"De-Shedding Treatment", "value"=>20.0, "taxID"=>256, "durationPerUnit"=>15.0, "serviceBadge"=>nil, "serviceCategory"=>"De-Shed", "isOnline"=>true, "isActive"=>false},
61
+ ]}
62
+ when '/api/v1/resources/serviceTypes/'
63
+ {"ServiceTypes"=>[
64
+ {"serviceTypeID"=>14, "serviceType"=>"Pet Grooming", "duration"=>90, "isActive"=>true},
65
+ ]}
66
+ when '/api/v1/data/WorkOrders/'
67
+ {"WorkOrder"=>{"objectID"=>"4138030"}}
68
+ when '/api/v1/data/Cases/'
69
+ {"Case"=>{"objectID"=>"28460"}}
70
+ else
71
+ {}
72
+ end
73
+ end
74
+
75
+ def self.http_request(path:, body:, query:, include_security_token: true)
76
+ uri = URI::HTTPS.build host: host, path: path
77
+ uri.query = URI.encode_www_form(query) if query.any?
78
+
79
+ method = query.any? ? Net::HTTP::Get : Net::HTTP::Post
80
+ request = method.new uri.request_uri
81
+ request.initialize_http_header 'Content-Type' => 'application/json'
82
+
83
+ if query.none?
84
+ body = body.merge(securityToken: security_token) if include_security_token
85
+ request.body = body.to_json
86
+ end
87
+
88
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
89
+ http.request request
90
+ end
91
+
92
+ JSON(response.body).tap do |data|
93
+ raise Vng::Error, "#{data['errMsg']} #{data['Errors']}" unless data['errNo'].zero?
94
+ end
95
+ rescue Errno::ECONNREFUSED, SocketError => e
96
+ raise Vng::ConnectionError, e.message
97
+ end
98
+
99
+ def self.host
100
+ Vng.configuration.host
101
+ end
102
+
103
+ def self.security_token
104
+ Vng.configuration.security_token
105
+ end
106
+ end
107
+ end
data/lib/vng/route.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'vng/resource'
2
+
3
+ module Vng
4
+ # Provides methods to interact with Vonigo ZIP routes.
5
+ class Route < Resource
6
+ PATH = '/api/v1/resources/Routes/'
7
+
8
+ attr_reader :id, :name
9
+
10
+ def initialize(id:, name:)
11
+ @id = id
12
+ @name = name
13
+ end
14
+
15
+ # TODO: Needs pagination
16
+ def self.all
17
+ data = request path: PATH
18
+
19
+ data['Routes'].filter do |route|
20
+ route['isActive']
21
+ end.map do |body|
22
+ id = body['routeID']
23
+ name = body['routeName']
24
+
25
+ new id: id, name: name
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/vng/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vng
2
- VERSION = '0.1.17'
2
+ VERSION = '0.1.19'
3
3
  end
data/lib/vng.rb CHANGED
@@ -16,6 +16,7 @@ require_relative 'vng/lead'
16
16
  require_relative 'vng/location'
17
17
  require_relative 'vng/lock'
18
18
  require_relative 'vng/price_item'
19
+ require_relative 'vng/route'
19
20
  require_relative 'vng/security_token'
20
21
  require_relative 'vng/service_type'
21
22
  require_relative 'vng/version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.17
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - claudiob
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-18 00:00:00.000000000 Z
11
+ date: 2024-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
@@ -50,8 +50,10 @@ files:
50
50
  - lib/vng/lead.rb
51
51
  - lib/vng/location.rb
52
52
  - lib/vng/lock.rb
53
+ - lib/vng/mock_resource.rb
53
54
  - lib/vng/price_item.rb
54
55
  - lib/vng/resource.rb
56
+ - lib/vng/route.rb
55
57
  - lib/vng/security_token.rb
56
58
  - lib/vng/service_type.rb
57
59
  - lib/vng/version.rb