toc_doc 1.4.0 → 1.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +64 -1
- data/TODO.md +6 -5
- data/lib/toc_doc/core/version.rb +1 -1
- data/lib/toc_doc/models/agenda.rb +21 -0
- data/lib/toc_doc/models/booking_info.rb +128 -0
- data/lib/toc_doc/models/profile/practitioner.rb +1 -1
- data/lib/toc_doc/models/profile.rb +70 -8
- data/lib/toc_doc/models/visit_motive.rb +18 -0
- data/lib/toc_doc/models.rb +3 -0
- data/lib/toc_doc.rb +11 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: beef9501f028dfc80d31fb212f9ff876b20b952801ce7712702144bfa572fb32
|
|
4
|
+
data.tar.gz: ade0bafa23b88557931944c4199e64b9f45c972814d5b7af4b6b343602ae32eb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5fcf8a1d6b3e3ef1e200bbd34c91922859f1c31ebb1ed208c6810d75470e56a63030c1f325f2ec9c39bbb54a73b97f831b5503d26528e34f62863f8a63cbedda
|
|
7
|
+
data.tar.gz: 20b38a89845bdf86a3b6effae5f47fbfc97e1d461b309a95a0c1a5b072bce2e9b6c58ee627719a07b02751b93e0edcfb309e552d6c6516998c3e34a8fb1ab2ef
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [1.5.0] - 2026-03-28
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **`TocDoc::BookingInfo`** — new envelope class for the slot-selection funnel info endpoint (`/online_booking/api/slot_selection_funnel/v1/info.json`); `BookingInfo.find(identifier)` fetches booking context by profile slug or numeric ID and returns a typed `BookingInfo` instance
|
|
8
|
+
- **`TocDoc::BookingInfo#profile`** — returns the typed profile (`Practitioner` or `Organization`) via `Profile.build`
|
|
9
|
+
- **`TocDoc::BookingInfo#specialities`** — returns an array of `TocDoc::Speciality` objects
|
|
10
|
+
- **`TocDoc::BookingInfo#visit_motives`** — returns an array of `TocDoc::VisitMotive` objects
|
|
11
|
+
- **`TocDoc::BookingInfo#agendas`** — returns an array of `TocDoc::Agenda` objects, each pre-resolved with its matching `VisitMotive` objects via `visit_motive_ids`
|
|
12
|
+
- **`TocDoc::BookingInfo#places`** — returns an array of `TocDoc::Place` objects
|
|
13
|
+
- **`TocDoc::BookingInfo#practitioners`** — returns an array of `TocDoc::Profile::Practitioner` objects (marked `partial: true`)
|
|
14
|
+
- **`TocDoc::BookingInfo#organization?`** — delegates to the inner profile
|
|
15
|
+
- **`TocDoc::VisitMotive`** — new `Resource`-based model representing a visit motive (reason for consultation); exposes `#id` and `#name` via dot-notation
|
|
16
|
+
- **`TocDoc::Agenda`** — new `Resource`-based model representing an agenda (calendar); exposes `#id` and `#practice_id` via dot-notation; supports pre-resolved `#visit_motives` when built through `BookingInfo`
|
|
17
|
+
- **`TocDoc.booking_info`** — top-level shortcut delegating to `TocDoc::BookingInfo.find`
|
|
18
|
+
|
|
3
19
|
## [1.4.0] - 2026-03-19
|
|
4
20
|
|
|
5
21
|
### Added
|
data/README.md
CHANGED
|
@@ -29,6 +29,7 @@ A Ruby gem for interacting with the (unofficial) Doctolib API. A thin, Faraday-b
|
|
|
29
29
|
- [Availabilities](#availabilities)
|
|
30
30
|
- [Search](#search)
|
|
31
31
|
- [Profile](#profile)
|
|
32
|
+
- [BookingInfo](#bookinginfo)
|
|
32
33
|
5. [Response objects](#response-objects)
|
|
33
34
|
6. [Pagination](#pagination)
|
|
34
35
|
7. [Error handling](#error-handling)
|
|
@@ -129,7 +130,7 @@ client.get('/availabilities.json', query: { visit_motive_ids: '123', agenda_ids:
|
|
|
129
130
|
| Option | Default | Description |
|
|
130
131
|
|---|---|---|
|
|
131
132
|
| `api_endpoint` | `https://www.doctolib.fr` | Base URL. Change to `.de` / `.it` for other countries. |
|
|
132
|
-
| `user_agent` | `TocDoc Ruby Gem 1.
|
|
133
|
+
| `user_agent` | `TocDoc Ruby Gem 1.5.0` | `User-Agent` header sent with every request. |
|
|
133
134
|
| `default_media_type` | `application/json` | `Accept` and `Content-Type` headers. |
|
|
134
135
|
| `per_page` | `15` | Default number of availability dates per request (capped at `15`). |
|
|
135
136
|
| `middleware` | Retry + RaiseError + JSON + adapter | Full Faraday middleware stack. Override to customise completely. |
|
|
@@ -241,6 +242,35 @@ profile.places.first.coordinates # => [44.8386722, -0.5780466]
|
|
|
241
242
|
|
|
242
243
|
**Return value:** a `TocDoc::Profile::Practitioner` or `TocDoc::Profile::Organization` (see [Response objects](#response-objects)).
|
|
243
244
|
|
|
245
|
+
### BookingInfo
|
|
246
|
+
|
|
247
|
+
Fetch the slot-selection funnel context for a practitioner or organization by slug or numeric ID.
|
|
248
|
+
|
|
249
|
+
```ruby
|
|
250
|
+
# by slug
|
|
251
|
+
info = TocDoc::BookingInfo.find('jane-doe-bordeaux')
|
|
252
|
+
|
|
253
|
+
# by numeric ID
|
|
254
|
+
info = TocDoc::BookingInfo.find(1_542_899)
|
|
255
|
+
|
|
256
|
+
# module-level shortcut
|
|
257
|
+
info = TocDoc.booking_info('jane-doe-bordeaux')
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
`BookingInfo.find` hits `/online_booking/api/slot_selection_funnel/v1/info.json` and returns a `TocDoc::BookingInfo` instance containing the full booking context needed to drive the appointment-booking funnel.
|
|
261
|
+
|
|
262
|
+
```ruby
|
|
263
|
+
info.profile # => #<TocDoc::Profile::Practitioner ...>
|
|
264
|
+
info.specialities # => [#<TocDoc::Speciality ...>, ...]
|
|
265
|
+
info.visit_motives # => [#<TocDoc::VisitMotive id=..., name="...">, ...]
|
|
266
|
+
info.agendas # => [#<TocDoc::Agenda id=..., practice_id=...>, ...]
|
|
267
|
+
info.places # => [#<TocDoc::Place ...>, ...]
|
|
268
|
+
info.practitioners # => [#<TocDoc::Profile::Practitioner partial=true>, ...]
|
|
269
|
+
info.organization? # => false
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
**Return value:** a `TocDoc::BookingInfo` (see [Response objects](#response-objects)).
|
|
273
|
+
|
|
244
274
|
---
|
|
245
275
|
|
|
246
276
|
## Response objects
|
|
@@ -337,6 +367,39 @@ Represents a practice location returned inside a full profile response. Inherits
|
|
|
337
367
|
| `#formal_name` | `String \| nil` | Formal practice name, if available. |
|
|
338
368
|
| `#coordinates` | `Array<Float>` | Convenience method returning `[latitude, longitude]`. |
|
|
339
369
|
|
|
370
|
+
### `TocDoc::BookingInfo`
|
|
371
|
+
|
|
372
|
+
Returned by `TocDoc::BookingInfo.find`; also accessible via the `TocDoc.booking_info` module-level shortcut.
|
|
373
|
+
|
|
374
|
+
| Method | Type | Description |
|
|
375
|
+
|---|---|---|
|
|
376
|
+
| `#profile` | `Profile::Practitioner \| Profile::Organization` | Typed profile built via `Profile.build`. |
|
|
377
|
+
| `#specialities` | `Array<TocDoc::Speciality>` | Specialities associated with the booking context. |
|
|
378
|
+
| `#visit_motives` | `Array<TocDoc::VisitMotive>` | Available visit motives (reasons for consultation). |
|
|
379
|
+
| `#agendas` | `Array<TocDoc::Agenda>` | Agendas, each pre-resolved with their matching `VisitMotive` objects. |
|
|
380
|
+
| `#places` | `Array<TocDoc::Place>` | Practice locations. |
|
|
381
|
+
| `#practitioners` | `Array<TocDoc::Profile::Practitioner>` | Practitioners associated with this booking context (`partial: true`). |
|
|
382
|
+
| `#organization?` | `Boolean` | Delegates to the inner profile. |
|
|
383
|
+
|
|
384
|
+
### `TocDoc::VisitMotive`
|
|
385
|
+
|
|
386
|
+
Represents a visit motive (reason for consultation) returned inside a `BookingInfo` response. Inherits dot-notation attribute access from `TocDoc::Resource`.
|
|
387
|
+
|
|
388
|
+
| Method | Type | Description |
|
|
389
|
+
|---|---|---|
|
|
390
|
+
| `#id` | `Integer` | Visit motive identifier. |
|
|
391
|
+
| `#name` | `String` | Human-readable name of the visit motive. |
|
|
392
|
+
|
|
393
|
+
### `TocDoc::Agenda`
|
|
394
|
+
|
|
395
|
+
Represents an agenda (calendar) returned inside a `BookingInfo` response. Inherits dot-notation attribute access from `TocDoc::Resource`.
|
|
396
|
+
|
|
397
|
+
| Method | Type | Description |
|
|
398
|
+
|---|---|---|
|
|
399
|
+
| `#id` | `Integer` | Agenda identifier. |
|
|
400
|
+
| `#practice_id` | `Integer` | ID of the associated practice. |
|
|
401
|
+
| `#visit_motives` | `Array<TocDoc::VisitMotive>` | Visit motives pre-resolved via `visit_motive_ids` when built through `BookingInfo`. |
|
|
402
|
+
|
|
340
403
|
### `TocDoc::Speciality`
|
|
341
404
|
|
|
342
405
|
Represents a speciality returned by the autocomplete endpoint. Inherits dot-notation attribute access from `TocDoc::Resource`.
|
data/TODO.md
CHANGED
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[POTENTIAL_ENDPOINTS][POTENTIAL_ENDPOINTS.md]
|
|
4
4
|
|
|
5
|
-
## 1.5
|
|
6
|
-
|
|
7
|
-
- [ ] Booking context
|
|
8
|
-
- https://www.doctolib.fr/online_booking/api/slot_selection_funnel/v1/info.json?profile_slug=926388
|
|
9
|
-
|
|
10
5
|
## 1.6
|
|
11
6
|
|
|
12
7
|
### Better API usage
|
|
@@ -27,6 +22,12 @@
|
|
|
27
22
|
|
|
28
23
|
# DONE & RELEASED
|
|
29
24
|
|
|
25
|
+
## 1.5
|
|
26
|
+
|
|
27
|
+
- [x] Booking context
|
|
28
|
+
- practitioner : https://www.doctolib.fr/online_booking/api/slot_selection_funnel/v1/info.json?profile_slug=926388
|
|
29
|
+
- organization : https://www.doctolib.fr/online_booking/api/slot_selection_funnel/v1/info.json?profile_slug=325629
|
|
30
|
+
|
|
30
31
|
## 1.4
|
|
31
32
|
|
|
32
33
|
- [x] Profile
|
data/lib/toc_doc/core/version.rb
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module TocDoc
|
|
4
|
+
# Represents an agenda (calendar) returned by the booking info endpoint.
|
|
5
|
+
#
|
|
6
|
+
# The +id+ and +practice_id+ fields are the primary attributes. Additional
|
|
7
|
+
# fields such as +visit_motive_ids+ and +visit_motive_ids_by_practice_id+ are
|
|
8
|
+
# accessible via dot-notation inherited from {TocDoc::Resource}.
|
|
9
|
+
#
|
|
10
|
+
# @example
|
|
11
|
+
# agenda = TocDoc::Agenda.new(
|
|
12
|
+
# 'id' => 42,
|
|
13
|
+
# 'practice_id' => 'practice-125055',
|
|
14
|
+
# 'visit_motive_ids' => [1, 2]
|
|
15
|
+
# )
|
|
16
|
+
# agenda.id #=> 42
|
|
17
|
+
# agenda.practice_id #=> "practice-125055"
|
|
18
|
+
class Agenda < Resource
|
|
19
|
+
main_attrs :id, :practice_id
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'toc_doc/models/profile'
|
|
4
|
+
require 'toc_doc/models/speciality'
|
|
5
|
+
require 'toc_doc/models/place'
|
|
6
|
+
require 'toc_doc/models/visit_motive'
|
|
7
|
+
require 'toc_doc/models/agenda'
|
|
8
|
+
|
|
9
|
+
module TocDoc
|
|
10
|
+
# Envelope returned by the slot-selection funnel info endpoint.
|
|
11
|
+
#
|
|
12
|
+
# Wraps the raw API response and exposes typed collections for the booking
|
|
13
|
+
# context: profile, specialities, visit motives, agendas, places, and
|
|
14
|
+
# practitioners.
|
|
15
|
+
#
|
|
16
|
+
# Unlike {TocDoc::Profile}, this class is NOT a {Resource} subclass — it is
|
|
17
|
+
# a plain envelope class, similar in role to {TocDoc::Search::Result}.
|
|
18
|
+
#
|
|
19
|
+
# @example
|
|
20
|
+
# info = TocDoc::BookingInfo.find('jane-doe-bordeaux')
|
|
21
|
+
# info.profile #=> #<TocDoc::Profile::Practitioner>
|
|
22
|
+
# info.visit_motives #=> [#<TocDoc::VisitMotive>, ...]
|
|
23
|
+
# info.organization? #=> false
|
|
24
|
+
class BookingInfo
|
|
25
|
+
PATH = '/online_booking/api/slot_selection_funnel/v1/info.json'
|
|
26
|
+
|
|
27
|
+
class << self
|
|
28
|
+
# Fetches booking info for a profile slug or numeric ID.
|
|
29
|
+
#
|
|
30
|
+
# @param identifier [String, Integer] profile slug or numeric ID,
|
|
31
|
+
# forwarded as the +profile_slug+ query parameter
|
|
32
|
+
# @return [BookingInfo]
|
|
33
|
+
# @raise [ArgumentError] if +identifier+ is +nil+
|
|
34
|
+
#
|
|
35
|
+
# @example
|
|
36
|
+
# TocDoc::BookingInfo.find('jane-doe-bordeaux')
|
|
37
|
+
# TocDoc::BookingInfo.find(325629)
|
|
38
|
+
def find(identifier)
|
|
39
|
+
raise ArgumentError, 'identifier cannot be nil' if identifier.nil?
|
|
40
|
+
|
|
41
|
+
data = TocDoc.client.get(PATH, query: { profile_slug: identifier })['data']
|
|
42
|
+
new(data)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @param data [Hash] the +data+ value from the API response body
|
|
47
|
+
def initialize(data)
|
|
48
|
+
@data = data
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# The profile associated with this booking context, typed via
|
|
52
|
+
# {TocDoc::Profile.build}.
|
|
53
|
+
#
|
|
54
|
+
# @return [TocDoc::Profile::Practitioner, TocDoc::Profile::Organization]
|
|
55
|
+
def profile
|
|
56
|
+
@profile ||= Profile.build(@data['profile'])
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# All specialities for this booking context.
|
|
60
|
+
#
|
|
61
|
+
# @return [Array<TocDoc::Speciality>]
|
|
62
|
+
def specialities
|
|
63
|
+
@specialities ||= Array(@data['specialities']).map do |speciality_attrs|
|
|
64
|
+
Speciality.new(speciality_attrs)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# All visit motives for this booking context.
|
|
69
|
+
#
|
|
70
|
+
# @return [Array<TocDoc::VisitMotive>]
|
|
71
|
+
def visit_motives
|
|
72
|
+
@visit_motives ||= Array(@data['visit_motives']).map do |visit_motive_attrs|
|
|
73
|
+
VisitMotive.new(visit_motive_attrs)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# All agendas for this booking context.
|
|
78
|
+
#
|
|
79
|
+
# @return [Array<TocDoc::Agenda>]
|
|
80
|
+
def agendas
|
|
81
|
+
@agendas ||= Array(@data['agendas']).map do |agenda_attrs|
|
|
82
|
+
agenda_visit_motives = visit_motives.select do |vm|
|
|
83
|
+
agenda_attrs['visit_motive_ids'].include?(vm.id)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
Agenda.new(agenda_attrs.merge('visit_motives' => agenda_visit_motives))
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# All practice locations for this booking context.
|
|
91
|
+
#
|
|
92
|
+
# @return [Array<TocDoc::Place>]
|
|
93
|
+
def places
|
|
94
|
+
@places ||= Array(@data['places']).map do |place_attrs|
|
|
95
|
+
Place.new(place_attrs)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# All practitioners associated with this booking context.
|
|
100
|
+
#
|
|
101
|
+
# Always constructed as {TocDoc::Profile::Practitioner} since the
|
|
102
|
+
# +practitioners+ array in this endpoint exclusively contains practitioners.
|
|
103
|
+
# Marked as partial since the data is a summary, not a full profile page.
|
|
104
|
+
#
|
|
105
|
+
# @return [Array<TocDoc::Profile::Practitioner>]
|
|
106
|
+
def practitioners
|
|
107
|
+
@practitioners ||= Array(@data['practitioners']).map do |practitioner_attrs|
|
|
108
|
+
Profile::Practitioner.new(practitioner_attrs.merge('partial' => true))
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Returns +true+ when the top-level profile is an organization.
|
|
113
|
+
#
|
|
114
|
+
# Delegates to {TocDoc::Profile#organization?}.
|
|
115
|
+
#
|
|
116
|
+
# @return [Boolean]
|
|
117
|
+
def organization?
|
|
118
|
+
profile.organization?
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Returns the raw data hash.
|
|
122
|
+
#
|
|
123
|
+
# @return [Hash]
|
|
124
|
+
def to_h
|
|
125
|
+
@data
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -19,20 +19,26 @@ module TocDoc
|
|
|
19
19
|
class << self
|
|
20
20
|
# Factory — returns a +Profile::Practitioner+ or +Profile::Organization+.
|
|
21
21
|
#
|
|
22
|
-
# Resolves type via +owner_type+ first (
|
|
22
|
+
# Resolves type via +owner_type+ first (autocomplete context), then falls back
|
|
23
23
|
# to the boolean flags present on profile-page responses.
|
|
24
24
|
#
|
|
25
25
|
# @param attrs [Hash] raw attribute hash from the API response
|
|
26
26
|
# @return [Profile::Practitioner, Profile::Organization]
|
|
27
|
+
# @raise [ArgumentError] if +attrs+ contains an unknown +owner_type+ or the
|
|
28
|
+
# profile type cannot be determined from the available flags
|
|
29
|
+
#
|
|
30
|
+
# @example Build from an autocomplete result
|
|
31
|
+
# TocDoc::Profile.build('owner_type' => 'Account', 'name' => 'Dr Smith')
|
|
32
|
+
# @example Build from a full profile response
|
|
33
|
+
# TocDoc::Profile.build('is_practitioner' => true, 'name' => 'Dr Smith')
|
|
27
34
|
def build(attrs = {})
|
|
28
35
|
attrs = normalize_attrs(attrs)
|
|
29
|
-
return find(attrs['value']) if attrs['force_full_profile'] && attrs['owner_type']
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
return find(attrs['value']) if attrs['force_full_profile']
|
|
38
|
+
|
|
39
|
+
build_from_autocomplete(attrs) ||
|
|
40
|
+
build_from_booking_info(attrs) ||
|
|
41
|
+
build_from_full_profile(attrs)
|
|
36
42
|
end
|
|
37
43
|
|
|
38
44
|
# Fetches a full profile page by slug or numeric ID.
|
|
@@ -53,7 +59,31 @@ module TocDoc
|
|
|
53
59
|
|
|
54
60
|
private
|
|
55
61
|
|
|
56
|
-
|
|
62
|
+
# Autocomplete results carry an +owner_type+ key that tells us the
|
|
63
|
+
# profile type directly. When +force_full_profile+ is set, fetches
|
|
64
|
+
# the full profile page instead of building a partial.
|
|
65
|
+
#
|
|
66
|
+
# @param attrs [Hash] normalized attribute hash
|
|
67
|
+
# @return [Profile::Practitioner, Profile::Organization, nil] +nil+ when
|
|
68
|
+
# +owner_type+ is absent
|
|
69
|
+
# @raise [ArgumentError] if +owner_type+ is present but unrecognised
|
|
70
|
+
def build_from_autocomplete(attrs)
|
|
71
|
+
return unless attrs['owner_type']
|
|
72
|
+
|
|
73
|
+
case attrs['owner_type']
|
|
74
|
+
when 'Account' then Practitioner.new(attrs.merge('partial' => true))
|
|
75
|
+
when 'Organization' then Organization.new(attrs.merge('partial' => true))
|
|
76
|
+
else raise ArgumentError, "Unknown owner_type: #{attrs['owner_type']}"
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Builds a profile from a full profile-page response.
|
|
81
|
+
#
|
|
82
|
+
# @param attrs [Hash] normalized attribute hash from a full profile page
|
|
83
|
+
# @return [Profile::Practitioner, Profile::Organization]
|
|
84
|
+
# @raise [ArgumentError] if neither +is_practitioner+ nor +organization+
|
|
85
|
+
# flag is present in +attrs+
|
|
86
|
+
def build_from_full_profile(attrs)
|
|
57
87
|
if attrs['is_practitioner']
|
|
58
88
|
Practitioner.new(attrs.merge('partial' => false))
|
|
59
89
|
elsif attrs['organization']
|
|
@@ -63,6 +93,26 @@ module TocDoc
|
|
|
63
93
|
end
|
|
64
94
|
end
|
|
65
95
|
|
|
96
|
+
# Booking-info profiles carry `organization` (true/false) but lack
|
|
97
|
+
# `is_practitioner`. Returns nil when the shape doesn't match so the
|
|
98
|
+
# caller can fall through to build_from_full_profile.
|
|
99
|
+
#
|
|
100
|
+
# @param attrs [Hash] normalized attribute hash
|
|
101
|
+
# @return [Profile::Practitioner, Profile::Organization, nil] +nil+ when
|
|
102
|
+
# the booking-info shape is not matched
|
|
103
|
+
def build_from_booking_info(attrs)
|
|
104
|
+
return unless attrs.key?('organization') && !attrs.key?('is_practitioner')
|
|
105
|
+
|
|
106
|
+
return Organization.new(attrs.merge('partial' => true)) if attrs['organization']
|
|
107
|
+
|
|
108
|
+
Practitioner.new(attrs.merge('partial' => true))
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Extracts and coerces profile attributes from the raw API response.
|
|
112
|
+
#
|
|
113
|
+
# @param data [Hash] the +data+ key from the API response body
|
|
114
|
+
# @return [Hash] merged attribute hash with +speciality+ and +places+
|
|
115
|
+
# coerced into model objects
|
|
66
116
|
def profile_attrs(data)
|
|
67
117
|
data['profile'].merge(
|
|
68
118
|
'speciality' => TocDoc::Speciality.new(data['profile']['speciality'] || {}),
|
|
@@ -78,6 +128,9 @@ module TocDoc
|
|
|
78
128
|
# Returns all skills across all practices as an array of {TocDoc::Resource}.
|
|
79
129
|
#
|
|
80
130
|
# @return [Array<TocDoc::Resource>]
|
|
131
|
+
#
|
|
132
|
+
# @example
|
|
133
|
+
# profile.skills #=> [#<TocDoc::Resource ...>, ...]
|
|
81
134
|
def skills
|
|
82
135
|
hash = self['skills_by_practice'] || {}
|
|
83
136
|
hash.values.flatten.map { |s| TocDoc::Resource.new(s) }
|
|
@@ -87,17 +140,26 @@ module TocDoc
|
|
|
87
140
|
#
|
|
88
141
|
# @param practice_id [Integer, String] the practice ID
|
|
89
142
|
# @return [Array<TocDoc::Resource>]
|
|
143
|
+
#
|
|
144
|
+
# @example
|
|
145
|
+
# profile.skills_for(123) #=> [#<TocDoc::Resource ...>, ...]
|
|
90
146
|
def skills_for(practice_id)
|
|
91
147
|
hash = self['skills_by_practice'] || {}
|
|
92
148
|
Array(hash[practice_id.to_s]).map { |s| TocDoc::Resource.new(s) }
|
|
93
149
|
end
|
|
94
150
|
|
|
95
151
|
# @return [Boolean] true when this profile is a practitioner
|
|
152
|
+
#
|
|
153
|
+
# @example
|
|
154
|
+
# profile.practitioner? #=> true
|
|
96
155
|
def practitioner?
|
|
97
156
|
is_a?(Practitioner)
|
|
98
157
|
end
|
|
99
158
|
|
|
100
159
|
# @return [Boolean] true when this profile is an organization
|
|
160
|
+
#
|
|
161
|
+
# @example
|
|
162
|
+
# profile.organization? #=> false
|
|
101
163
|
def organization?
|
|
102
164
|
is_a?(Organization)
|
|
103
165
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module TocDoc
|
|
4
|
+
# Represents a visit motive (reason for consultation) returned by the booking
|
|
5
|
+
# info endpoint.
|
|
6
|
+
#
|
|
7
|
+
# The +id+ and +name+ fields are the primary attributes. Additional fields
|
|
8
|
+
# such as +restrictions+ are accessible via dot-notation inherited from
|
|
9
|
+
# {TocDoc::Resource}.
|
|
10
|
+
#
|
|
11
|
+
# @example
|
|
12
|
+
# motive = TocDoc::VisitMotive.new('id' => 1, 'name' => 'Consultation', 'restrictions' => [])
|
|
13
|
+
# motive.id #=> 1
|
|
14
|
+
# motive.name #=> "Consultation"
|
|
15
|
+
class VisitMotive < Resource
|
|
16
|
+
main_attrs :id, :name
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/toc_doc/models.rb
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
require 'toc_doc/models/resource'
|
|
4
4
|
require 'toc_doc/models/speciality'
|
|
5
5
|
require 'toc_doc/models/place'
|
|
6
|
+
require 'toc_doc/models/visit_motive'
|
|
7
|
+
require 'toc_doc/models/agenda'
|
|
8
|
+
require 'toc_doc/models/booking_info'
|
|
6
9
|
require 'toc_doc/models/search'
|
|
7
10
|
|
|
8
11
|
require 'toc_doc/models/availability'
|
data/lib/toc_doc.rb
CHANGED
|
@@ -100,6 +100,17 @@ module TocDoc
|
|
|
100
100
|
TocDoc::Profile.find(identifier)
|
|
101
101
|
end
|
|
102
102
|
|
|
103
|
+
# Fetches booking context data for a profile by slug or numeric ID.
|
|
104
|
+
#
|
|
105
|
+
# Delegates to {TocDoc::BookingInfo.find} — see that method for full
|
|
106
|
+
# parameter documentation.
|
|
107
|
+
#
|
|
108
|
+
# @param identifier [String, Integer] profile slug or numeric ID
|
|
109
|
+
# @return [TocDoc::BookingInfo]
|
|
110
|
+
def booking_info(identifier)
|
|
111
|
+
TocDoc::BookingInfo.find(identifier)
|
|
112
|
+
end
|
|
113
|
+
|
|
103
114
|
# @!visibility private
|
|
104
115
|
def method_missing(method_name, ...)
|
|
105
116
|
if client.respond_to?(method_name)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: toc_doc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- 01max
|
|
@@ -74,8 +74,10 @@ files:
|
|
|
74
74
|
- lib/toc_doc/http/response/base_middleware.rb
|
|
75
75
|
- lib/toc_doc/middleware/.keep
|
|
76
76
|
- lib/toc_doc/models.rb
|
|
77
|
+
- lib/toc_doc/models/agenda.rb
|
|
77
78
|
- lib/toc_doc/models/availability.rb
|
|
78
79
|
- lib/toc_doc/models/availability/collection.rb
|
|
80
|
+
- lib/toc_doc/models/booking_info.rb
|
|
79
81
|
- lib/toc_doc/models/place.rb
|
|
80
82
|
- lib/toc_doc/models/profile.rb
|
|
81
83
|
- lib/toc_doc/models/profile/organization.rb
|
|
@@ -84,6 +86,7 @@ files:
|
|
|
84
86
|
- lib/toc_doc/models/search.rb
|
|
85
87
|
- lib/toc_doc/models/search/result.rb
|
|
86
88
|
- lib/toc_doc/models/speciality.rb
|
|
89
|
+
- lib/toc_doc/models/visit_motive.rb
|
|
87
90
|
- sig/toc_doc.rbs
|
|
88
91
|
homepage: https://github.com/01max/toc_doc
|
|
89
92
|
licenses:
|