Class: TocDoc::BookingInfo
- Inherits:
-
Object
- Object
- TocDoc::BookingInfo
- Defined in:
- lib/toc_doc/models/booking_info.rb
Overview
Envelope returned by the slot-selection funnel info endpoint.
Wraps the raw API response and exposes typed collections for the booking context: profile, specialities, visit motives, agendas, places, and practitioners.
Unlike Profile, this class is NOT a Resource subclass — it is a plain envelope class, similar in role to Search::Result.
Constant Summary collapse
- PATH =
API path for the slot-selection funnel info endpoint.
'/online_booking/api/slot_selection_funnel/v1/info.json'
Class Method Summary collapse
-
.find(identifier) ⇒ BookingInfo
Fetches booking info for a profile slug or numeric ID.
Instance Method Summary collapse
-
#agendas ⇒ Array<TocDoc::Agenda>
All agendas for this booking context.
-
#initialize(data) ⇒ BookingInfo
constructor
A new instance of BookingInfo.
-
#organization? ⇒ Boolean
Returns +true+ when the top-level profile is an organization.
-
#places ⇒ Array<TocDoc::Place>
All practice locations for this booking context.
-
#practitioners ⇒ Array<TocDoc::Profile::Practitioner>
All practitioners associated with this booking context.
-
#profile ⇒ TocDoc::Profile::Practitioner, TocDoc::Profile::Organization
The profile associated with this booking context, typed via Profile.build.
-
#raw ⇒ Hash
Returns the raw data hash as received from the API.
-
#specialities ⇒ Array<TocDoc::Speciality>
All specialities for this booking context.
-
#to_h ⇒ Hash{String => Object}
Returns a hydrated hash with all typed collections serialized to plain Hashes.
-
#to_json ⇒ String
Serialize the booking info to a JSON string.
-
#visit_motives ⇒ Array<TocDoc::VisitMotive>
All visit motives for this booking context.
Constructor Details
#initialize(data) ⇒ BookingInfo
Returns a new instance of BookingInfo.
50 51 52 |
# File 'lib/toc_doc/models/booking_info.rb', line 50 def initialize(data) @data = data end |
Class Method Details
.find(identifier) ⇒ BookingInfo
Fetches booking info for a profile slug or numeric ID.
41 42 43 44 45 46 |
# File 'lib/toc_doc/models/booking_info.rb', line 41 def find(identifier) raise ArgumentError, 'identifier cannot be nil' if identifier.nil? data = TocDoc.client.get(PATH, query: { profile_slug: identifier })['data'] new(data) end |
Instance Method Details
#agendas ⇒ Array<TocDoc::Agenda>
All agendas for this booking context.
Visit motives are resolved via a hash index keyed by ID, so lookup is O(1) per motive rather than O(n) per agenda. Unknown visit_motive_ids are silently dropped.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/toc_doc/models/booking_info.rb', line 87 def agendas @agendas ||= begin vm_index = visit_motives.to_h { |vm| [vm.id, vm] } Array(@data['agendas']).map do |agenda_attrs| agenda_visit_motives = Array(agenda_attrs['visit_motive_ids']).filter_map { |id| vm_index[id] } Agenda.new(agenda_attrs.merge('visit_motives' => agenda_visit_motives)) end end end |
#organization? ⇒ Boolean
Returns +true+ when the top-level profile is an organization.
Delegates to Profile#organization?.
125 126 127 |
# File 'lib/toc_doc/models/booking_info.rb', line 125 def organization? profile.organization? end |
#places ⇒ Array<TocDoc::Place>
All practice locations for this booking context.
101 102 103 104 105 |
# File 'lib/toc_doc/models/booking_info.rb', line 101 def places @places ||= Array(@data['places']).map do |place_attrs| Place.new(place_attrs) end end |
#practitioners ⇒ Array<TocDoc::Profile::Practitioner>
All practitioners associated with this booking context.
Always constructed as Profile::Practitioner since the +practitioners+ array in this endpoint exclusively contains practitioners. Marked as partial since the data is a summary, not a full profile page.
114 115 116 117 118 |
# File 'lib/toc_doc/models/booking_info.rb', line 114 def practitioners @practitioners ||= Array(@data['practitioners']).map do |practitioner_attrs| Profile::Practitioner.new(practitioner_attrs.merge('partial' => true)) end end |
#profile ⇒ TocDoc::Profile::Practitioner, TocDoc::Profile::Organization
The profile associated with this booking context, typed via Profile.build.
58 59 60 |
# File 'lib/toc_doc/models/booking_info.rb', line 58 def profile @profile ||= Profile.build(@data['profile']) end |
#raw ⇒ Hash
Returns the raw data hash as received from the API.
132 133 134 |
# File 'lib/toc_doc/models/booking_info.rb', line 132 def raw @data end |
#specialities ⇒ Array<TocDoc::Speciality>
All specialities for this booking context.
65 66 67 68 69 |
# File 'lib/toc_doc/models/booking_info.rb', line 65 def specialities @specialities ||= Array(@data['specialities']).map do |speciality_attrs| Speciality.new(speciality_attrs) end end |
#to_h ⇒ Hash{String => Object}
Returns a hydrated hash with all typed collections serialized to plain Hashes. Unlike #raw, nested objects are converted via their own +#to_h+ methods.
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/toc_doc/models/booking_info.rb', line 141 def to_h { 'profile' => profile.to_h, 'specialities' => specialities.map(&:to_h), 'visit_motives' => visit_motives.map(&:to_h), 'agendas' => agendas.map(&:to_h), 'places' => places.map(&:to_h), 'practitioners' => practitioners.map(&:to_h) } end |
#to_json ⇒ String
Serialize the booking info to a JSON string.
156 157 158 |
# File 'lib/toc_doc/models/booking_info.rb', line 156 def to_json(*) to_h.to_json(*) end |
#visit_motives ⇒ Array<TocDoc::VisitMotive>
All visit motives for this booking context.
74 75 76 77 78 |
# File 'lib/toc_doc/models/booking_info.rb', line 74 def visit_motives @visit_motives ||= Array(@data['visit_motives']).map do |visit_motive_attrs| VisitMotive.new(visit_motive_attrs) end end |