servizehub 1.0.0 → 1.0.1
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/lib/servizehub/client.rb +59 -1
- data/lib/servizehub/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 273b3e612c965437c44f14fd30236e43090b8ffebe5bffee90f14716820cd07e
|
|
4
|
+
data.tar.gz: 0f9b3edcc27a9bfb83170026ec1a09ccd3e3abbe034b5c326b6d6afe545d3bcb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5a672d24f9f8574dc52f6d4cc36159486a1ccf8ef6f687c4bbe590e1b7877da87b8b7df3cbb2c2781cba75084651a6672d7eca548dd74f482a16f278a4e2eeac
|
|
7
|
+
data.tar.gz: fcdda5248e398fe5520fa3a35c747b74d7272d8940395dc0e45039e1a4596eedab13991611037f66111a3bb0f31ae3e30e2d73179552475d30ca90540956e415
|
data/lib/servizehub/client.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'net/http'
|
|
2
2
|
require 'uri'
|
|
3
3
|
require 'json'
|
|
4
|
+
require 'date'
|
|
4
5
|
|
|
5
6
|
module Servizehub
|
|
6
7
|
class Client
|
|
@@ -11,8 +12,17 @@ module Servizehub
|
|
|
11
12
|
@api_key = api_key
|
|
12
13
|
end
|
|
13
14
|
|
|
15
|
+
# Helper to validate date format YYYY-MM-DD
|
|
16
|
+
def valid_date?(date)
|
|
17
|
+
Date.strptime(date, '%Y-%m-%d')
|
|
18
|
+
true
|
|
19
|
+
rescue ArgumentError
|
|
20
|
+
false
|
|
21
|
+
end
|
|
22
|
+
|
|
14
23
|
def send_booking(date:, service_type:, status:)
|
|
15
24
|
raise ArgumentError, "All booking details are required" if date.nil? || service_type.nil? || status.nil?
|
|
25
|
+
raise ArgumentError, "Invalid date format, expected YYYY-MM-DD" unless valid_date?(date)
|
|
16
26
|
|
|
17
27
|
valid_statuses = ["available", "unavailable"]
|
|
18
28
|
raise ArgumentError, "Invalid status value" unless valid_statuses.include?(status)
|
|
@@ -32,10 +42,58 @@ module Servizehub
|
|
|
32
42
|
end
|
|
33
43
|
|
|
34
44
|
unless response.code.to_i < 400
|
|
35
|
-
|
|
45
|
+
begin
|
|
46
|
+
data = JSON.parse(response.body)
|
|
47
|
+
message = data["message"] || "Booking failed"
|
|
48
|
+
rescue
|
|
49
|
+
message = "Booking failed"
|
|
50
|
+
end
|
|
51
|
+
raise message
|
|
36
52
|
end
|
|
37
53
|
|
|
38
54
|
{ message: "Booking availability sent successfully" }
|
|
39
55
|
end
|
|
56
|
+
|
|
57
|
+
# Bulk bookings
|
|
58
|
+
def send_multiple_bookings(bookings)
|
|
59
|
+
raise ArgumentError, "Bookings array is required" unless bookings.is_a?(Array) && !bookings.empty?
|
|
60
|
+
|
|
61
|
+
valid_statuses = ["available", "unavailable"]
|
|
62
|
+
failed_bookings = []
|
|
63
|
+
|
|
64
|
+
bookings.each do |booking|
|
|
65
|
+
date = booking[:date]
|
|
66
|
+
service_type = booking[:serviceType]
|
|
67
|
+
status = booking[:status]
|
|
68
|
+
|
|
69
|
+
# Validate fields
|
|
70
|
+
if date.nil? || service_type.nil? || status.nil?
|
|
71
|
+
failed_bookings << booking.merge(error: "Missing required fields")
|
|
72
|
+
next
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
unless valid_date?(date)
|
|
76
|
+
failed_bookings << booking.merge(error: "Invalid date format, expected YYYY-MM-DD")
|
|
77
|
+
next
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
unless valid_statuses.include?(status)
|
|
81
|
+
failed_bookings << booking.merge(error: "Invalid status value")
|
|
82
|
+
next
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
begin
|
|
86
|
+
send_booking(date: date, service_type: service_type, status: status)
|
|
87
|
+
rescue => e
|
|
88
|
+
failed_bookings << booking.merge(error: e.message)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
if failed_bookings.empty?
|
|
93
|
+
{ message: "Booking availability sent successfully" }
|
|
94
|
+
else
|
|
95
|
+
{ message: "Some bookings failed", failedBookings: failed_bookings }
|
|
96
|
+
end
|
|
97
|
+
end
|
|
40
98
|
end
|
|
41
99
|
end
|
data/lib/servizehub/version.rb
CHANGED