toc_doc 1.1.0 → 1.3.0

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.
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module TocDoc
4
- module Response
5
- # Wraps the top-level response from the Doctolib availabilities API.
6
- #
7
- # @example
8
- # response = TocDoc::Response::Availability.new(parsed_json)
9
- # response.total #=> 2
10
- # response.next_slot #=> "2026-02-28T10:00:00.000+01:00"
11
- # response.availabilities #=> [#<TocDoc::Availability ...>, ...]
12
- class Availability < Resource
13
- # The total number of available slots across all dates.
14
- #
15
- # @return [Integer]
16
- #
17
- # @example
18
- # response.total #=> 5
19
- def total
20
- @attrs['total']
21
- end
22
-
23
- # The nearest available appointment slot.
24
- #
25
- # When the API includes an explicit +next_slot+ key (common when there
26
- # are no slots in the loaded date window) that value is returned
27
- # directly. Otherwise the first slot of the first date that has one
28
- # is returned.
29
- #
30
- # @return [String, nil] ISO 8601 datetime string, or +nil+ when no
31
- # slot is available
32
- #
33
- # @example
34
- # response.next_slot #=> "2026-02-28T10:00:00.000+01:00"
35
- def next_slot
36
- return @attrs['next_slot'] if @attrs.key?('next_slot')
37
-
38
- Array(@attrs['availabilities']).each do |entry|
39
- slots = Array(entry['slots'])
40
- return slots.first unless slots.empty?
41
- end
42
-
43
- nil
44
- end
45
-
46
- # Dates that have at least one available slot, wrapped as
47
- # {TocDoc::Availability} objects.
48
- #
49
- # @return [Array<TocDoc::Availability>]
50
- #
51
- # @example
52
- # response.availabilities.each do |avail|
53
- # puts "#{avail.date}: #{avail.slots.size} slot(s)"
54
- # end
55
- def availabilities
56
- @availabilities ||= Array(@attrs['availabilities'])
57
- .select { |entry| Array(entry['slots']).any? }
58
- .map { |entry| TocDoc::Availability.new(entry) }
59
- end
60
-
61
- # All availability date entries, including those with no slots.
62
- #
63
- # @return [Array<TocDoc::Availability>]
64
- def raw_availabilities
65
- @raw_availabilities ||= Array(@attrs['availabilities']).map do |entry|
66
- TocDoc::Availability.new(entry)
67
- end
68
- end
69
-
70
- # Returns a plain Hash representation, with nested +availabilities+
71
- # expanded back to raw Hashes.
72
- #
73
- # @return [Hash{String => Object}]
74
- def to_h
75
- super.merge('availabilities' => availabilities.map(&:to_h))
76
- end
77
- end
78
- end
79
- end