vng 0.1.18 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/lib/vng/configuration.rb +4 -0
- data/lib/vng/mock_resource.rb +107 -0
- data/lib/vng/route.rb +29 -0
- data/lib/vng/version.rb +1 -1
- data/lib/vng.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 706982b8a7566e56016073d4d5a0e049ed351da4cebab7ca002d7b52b49e46a8
|
4
|
+
data.tar.gz: 15f60eb8f382d6d4d48903dec324b2251617ae46d28ba0c14fef5471a1060d35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a1b3bab28a45018a6a3876c066c9a1d95c376c1d336e83f607c822cbd5bb84b11222f36ce8ca22a9198bca7d0f67a90fd476e61b99601a10a021dc5115fec90
|
7
|
+
data.tar.gz: 578f75157f4e0e326ec427cf64bc7c42b84dcecbcd37eaeec20cec7f4a6254b44c0eaaa1b69e4e614c64f9a183859041bbeb85b606a5b488daf75ce4cc850c18
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/vng/configuration.rb
CHANGED
@@ -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
|
@@ -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
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.
|
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-
|
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
|