Class: TocDoc::BookingInfo

Inherits:
Object
  • Object
show all
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.

Examples:

info = TocDoc::BookingInfo.find('jane-doe-bordeaux')
info.profile        #=> #<TocDoc::Profile::Practitioner>
info.visit_motives  #=> [#<TocDoc::VisitMotive>, ...]
info.organization?  #=> false

Constant Summary collapse

PATH =

API path for the slot-selection funnel info endpoint.

Returns:

  • (String)
'/online_booking/api/slot_selection_funnel/v1/info.json'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ BookingInfo

Returns a new instance of BookingInfo.

Parameters:

  • data (Hash)

    the +data+ value from the API response body



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.

Examples:

TocDoc::BookingInfo.find('jane-doe-bordeaux')
TocDoc::BookingInfo.find(325629)

Parameters:

  • identifier (String, Integer)

    profile slug or numeric ID, forwarded as the +profile_slug+ query parameter

Returns:

Raises:

  • (ArgumentError)

    if +identifier+ is +nil+



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

#agendasArray<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.

Returns:



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?.

Returns:

  • (Boolean)


125
126
127
# File 'lib/toc_doc/models/booking_info.rb', line 125

def organization?
  profile.organization?
end

#placesArray<TocDoc::Place>

All practice locations for this booking context.

Returns:



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

#practitionersArray<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.

Returns:



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

#profileTocDoc::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

#rawHash

Returns the raw data hash as received from the API.

Returns:

  • (Hash)


132
133
134
# File 'lib/toc_doc/models/booking_info.rb', line 132

def raw
  @data
end

#specialitiesArray<TocDoc::Speciality>

All specialities for this booking context.

Returns:



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_hHash{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.

Returns:

  • (Hash{String => Object})


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_jsonString

Serialize the booking info to a JSON string.

Parameters:

  • args (Array)

    forwarded to +Hash#to_json+

Returns:

  • (String)


156
157
158
# File 'lib/toc_doc/models/booking_info.rb', line 156

def to_json(*)
  to_h.to_json(*)
end

#visit_motivesArray<TocDoc::VisitMotive>

All visit motives for this booking context.

Returns:



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