toc_doc 1.3.0 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6c39bc2d41f1be6ae2b12b23074de967614fc1c6067d217316c7cb8bb9f0c31
4
- data.tar.gz: 6c3a8732a25916bb75ebb18c7f53a79ff272a0c8b646477160a8381890404dcf
3
+ metadata.gz: 97e03e2d5bbc3fffa25a74e1dc6367d27befc2c25009889ff55b25c2f0abad46
4
+ data.tar.gz: 847c1832c1a927024404004c11c3adb966142d6e93df3de2692d9734f400b2d2
5
5
  SHA512:
6
- metadata.gz: dde234124b736d0149ac1f45bb6ab654487fb4e0c91bffb6c1b2462f51fa50a94cb59c5e9d4c4c5ef688eb12b9a8f8f321a0b5384b7d4bebe375506f81001b87
7
- data.tar.gz: 1fd5632c3e5c73f89ae8db6f844269d5674141332ea9fd1956691695c3ae7242a7d7f706b3b0742f361df6b7a6a8ed931dc25f6d4b2c01426c6cc0ee379dacde
6
+ metadata.gz: fe6ff537f03f02a3ecc17013558bcbe165667cc2bb1275d9cea12f28e84457672b278bdfc7f6e00a7f894be7ce5f3587bf02f70d2f6e5f7f70c0c2109372a145
7
+ data.tar.gz: c710d06fb3b1137c1ff2bc4a5f8c9a79c527c7c8e777d99bffd4f11f6799ae4c8dad188a558ac6f29a4696bde45eeb70ffb62b396a2e17cc6805005cf381cb41
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.4.0] - 2026-03-19
4
+
5
+ ### Added
6
+
7
+ - **`TocDoc::Place`** — new `Resource`-based model representing a practice location inside a profile response; exposes address/geo fields (`#address`, `#zipcode`, `#city`, `#full_address`, `#landline_number`, `#latitude`, `#longitude`, `#elevator`, `#handicap`, `#formal_name`) via dot-notation and adds `#coordinates` returning `[latitude, longitude]`
8
+ - **`TocDoc::Profile.find`** — class method that fetches a full profile page by slug or numeric ID from `/profiles/:identifier.json`; returns a typed `Profile::Practitioner` or `Profile::Organization` with `partial: false`
9
+ - **`TocDoc::Profile#skills`** — returns all skills across every practice as an array of `TocDoc::Resource` objects
10
+ - **`TocDoc::Profile#skills_for(practice_id)`** — returns skills for a single practice
11
+ - **`TocDoc.profile`** — top-level shortcut delegating to `TocDoc::Profile.find`
12
+ - **`TocDoc::Resource.main_attrs`** — class macro declaring which attribute keys appear in `#inspect`; inheritable by subclasses
13
+ - **`TocDoc::Resource.normalize_attrs`** — extracted as a public class method (string-key normalisation)
14
+ - **`TocDoc::Resource#inspect`** — custom implementation using `main_attrs` when declared, falling back to all keys
15
+
16
+ ### Changed
17
+
18
+ - **`TocDoc::Profile.build`** — updated to resolve full profile responses via boolean flags (`is_practitioner` / `organization`) in addition to the existing `owner_type` path used for search results; profiles built from search results are now tagged `partial: true`, full fetches `partial: false`; a `force_full_profile` flag on a search result transparently delegates to `Profile.find`
19
+ - **`TocDoc::Profile`** — `main_attrs :id, :partial` declared so inspect output stays concise
20
+
3
21
  ## [1.3.0] - 2026-03-15
4
22
 
5
23
  ### Added
data/README.md CHANGED
@@ -28,6 +28,7 @@ A Ruby gem for interacting with the (unofficial) Doctolib API. A thin, Faraday-b
28
28
  4. [Endpoints](#endpoints)
29
29
  - [Availabilities](#availabilities)
30
30
  - [Search](#search)
31
+ - [Profile](#profile)
31
32
  5. [Response objects](#response-objects)
32
33
  6. [Pagination](#pagination)
33
34
  7. [Error handling](#error-handling)
@@ -128,7 +129,7 @@ client.get('/availabilities.json', query: { visit_motive_ids: '123', agenda_ids:
128
129
  | Option | Default | Description |
129
130
  |---|---|---|
130
131
  | `api_endpoint` | `https://www.doctolib.fr` | Base URL. Change to `.de` / `.it` for other countries. |
131
- | `user_agent` | `TocDoc Ruby Gem 1.3.0` | `User-Agent` header sent with every request. |
132
+ | `user_agent` | `TocDoc Ruby Gem 1.4.0` | `User-Agent` header sent with every request. |
132
133
  | `default_media_type` | `application/json` | `Accept` and `Content-Type` headers. |
133
134
  | `per_page` | `15` | Default number of availability dates per request (capped at `15`). |
134
135
  | `middleware` | Retry + RaiseError + JSON + adapter | Full Faraday middleware stack. Override to customise completely. |
@@ -209,6 +210,37 @@ Valid `type:` values: `'profile'` (all profiles), `'practitioner'`, `'organizati
209
210
 
210
211
  **Return value:** a `TocDoc::Search::Result` when `type:` is omitted, or a filtered `Array` otherwise (see [Response objects](#response-objects)).
211
212
 
213
+ ### Profile
214
+
215
+ Fetch a full practitioner or organization profile page by slug or numeric ID.
216
+
217
+ ```ruby
218
+ # by slug
219
+ profile = TocDoc::Profile.find('jane-doe-bordeaux')
220
+
221
+ # by numeric ID
222
+ profile = TocDoc::Profile.find(1_542_899)
223
+
224
+ # module-level shortcut
225
+ profile = TocDoc.profile('jane-doe-bordeaux')
226
+ ```
227
+
228
+ `Profile.find` returns a typed `TocDoc::Profile::Practitioner` or `TocDoc::Profile::Organization` instance with `partial: false` (i.e. full profile data).
229
+
230
+ ```ruby
231
+ profile.name # => "Dr. Jane Doe"
232
+ profile.partial # => false
233
+ profile.practitioner? # => true
234
+
235
+ profile.skills # => [#<TocDoc::Resource ...>, ...]
236
+ profile.skills_for(377_272) # => skills for a specific practice
237
+
238
+ profile.places.first.city # => "Bordeaux"
239
+ profile.places.first.coordinates # => [44.8386722, -0.5780466]
240
+ ```
241
+
242
+ **Return value:** a `TocDoc::Profile::Practitioner` or `TocDoc::Profile::Organization` (see [Response objects](#response-objects)).
243
+
212
244
  ---
213
245
 
214
246
  ## Response objects
@@ -270,15 +302,40 @@ Returned by `TocDoc::Search.where` when `type:` is omitted.
270
302
 
271
303
  ### `TocDoc::Profile`
272
304
 
273
- Represents a search profile result (practitioner or organization). Use `Profile.build(attrs)` to obtain the correctly typed subclass instance.
305
+ Represents a practitioner or organization profile. Can be a lightweight search result (`partial: true`) or a full profile page (`partial: false`).
274
306
 
275
307
  | Method | Type | Description |
276
308
  |---|---|---|
277
- | `Profile.build(attrs)` | `Profile::Practitioner \| Profile::Organization` | Factory: returns `Practitioner` when `owner_type` is `"Account"`, `Organization` otherwise. |
309
+ | `Profile.find(identifier)` | `Profile::Practitioner \| Profile::Organization` | Fetches a full profile by slug or numeric ID. Returns `partial: false`. |
310
+ | `Profile.build(attrs)` | `Profile::Practitioner \| Profile::Organization` | Factory used internally by `Search::Result`; resolves type from `owner_type` or boolean flags. Returns `partial: true` for search results. |
311
+ | `#id` | `String \| Integer` | Profile identifier. |
312
+ | `#partial` | `Boolean` | `true` when built from a search result, `false` when fetched via `Profile.find`. |
278
313
  | `#practitioner?` | `Boolean` | `true` when this is a `Profile::Practitioner`. |
279
314
  | `#organization?` | `Boolean` | `true` when this is a `Profile::Organization`. |
315
+ | `#places` | `Array<TocDoc::Place>` | Practice locations (available on full profiles). |
316
+ | `#skills` | `Array<TocDoc::Resource>` | All skills across every practice (available on full profiles). |
317
+ | `#skills_for(practice_id)` | `Array<TocDoc::Resource>` | Skills for a single practice by its ID. |
318
+
319
+ `TocDoc::Profile::Practitioner` and `TocDoc::Profile::Organization` are typed subclasses that inherit dot-notation attribute access from `TocDoc::Resource`.
280
320
 
281
- `TocDoc::Profile::Practitioner` and `TocDoc::Profile::Organization` are thin subclasses that inherit dot-notation attribute access from `TocDoc::Resource`.
321
+ ### `TocDoc::Place`
322
+
323
+ Represents a practice location returned inside a full profile response. Inherits dot-notation attribute access from `TocDoc::Resource`.
324
+
325
+ | Method | Type | Description |
326
+ |---|---|---|
327
+ | `#id` | `String` | Practice identifier (e.g. `"practice-125055"`). |
328
+ | `#address` | `String` | Street address. |
329
+ | `#zipcode` | `String` | Postal code. |
330
+ | `#city` | `String` | City name. |
331
+ | `#full_address` | `String` | Combined address string. |
332
+ | `#landline_number` | `String \| nil` | Phone number, if available. |
333
+ | `#latitude` | `Float` | Latitude. |
334
+ | `#longitude` | `Float` | Longitude. |
335
+ | `#elevator` | `Boolean` | Whether the practice has elevator access. |
336
+ | `#handicap` | `Boolean` | Whether the practice is handicap-accessible. |
337
+ | `#formal_name` | `String \| nil` | Formal practice name, if available. |
338
+ | `#coordinates` | `Array<Float>` | Convenience method returning `[latitude, longitude]`. |
282
339
 
283
340
  ### `TocDoc::Speciality`
284
341
 
data/TODO.md CHANGED
@@ -2,12 +2,6 @@
2
2
 
3
3
  [POTENTIAL_ENDPOINTS][POTENTIAL_ENDPOINTS.md]
4
4
 
5
- ## 1.4
6
-
7
- - [ ] Profile
8
- - slug : https://www.doctolib.fr/profiles/mathilde-devun-lesparre-medoc.json
9
- - id : https://www.doctolib.fr/profiles/926388.json
10
-
11
5
  ## 1.5
12
6
 
13
7
  - [ ] Booking context
@@ -33,6 +27,12 @@
33
27
 
34
28
  # DONE & RELEASED
35
29
 
30
+ ## 1.4
31
+
32
+ - [x] Profile
33
+ - from slug : https://www.doctolib.fr/profiles/jane-doe-bordeaux.json
34
+ - from id : https://www.doctolib.fr/profiles/926388.json
35
+
36
36
  ## 1.3
37
37
 
38
38
  - [x] Search (autocomplete)
@@ -4,5 +4,5 @@ module TocDoc
4
4
  # The current version of the TocDoc gem.
5
5
  #
6
6
  # @return [String]
7
- VERSION = '1.3.0'
7
+ VERSION = '1.4.0'
8
8
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TocDoc
4
+ # Represents a practice location returned inside a profile response.
5
+ #
6
+ # All fields are accessible via dot-notation inherited from {TocDoc::Resource}.
7
+ # Nested arrays (+opening_hours+, +stations+) are returned as raw arrays of hashes.
8
+ #
9
+ # @example
10
+ # place = TocDoc::Place.new(
11
+ # 'id' => 'practice-125055',
12
+ # 'address' => '1 Rue Anonyme',
13
+ # 'zipcode' => '33000',
14
+ # 'city' => 'Bordeaux',
15
+ # 'full_address' => '1 Rue Anonyme, 33000 Bordeaux',
16
+ # 'landline_number' => '05 23 45 67 89',
17
+ # 'latitude' => 44.8386722,
18
+ # 'longitude' => -0.5780466,
19
+ # 'elevator' => true,
20
+ # 'handicap' => true,
21
+ # 'formal_name' => 'Centre de santé - Anonyme'
22
+ # )
23
+ # place.id #=> "practice-125055"
24
+ # place.city #=> "Bordeaux"
25
+ # place.full_address #=> "1 Rue Anonyme, 33000 Bordeaux"
26
+ # place.landline_number #=> "05 23 45 67 89"
27
+ # place.latitude #=> 44.8386722
28
+ # place.elevator #=> true
29
+ class Place < Resource
30
+ def coordinates
31
+ [latitude, longitude]
32
+ end
33
+ end
34
+ end
@@ -3,6 +3,12 @@
3
3
  module TocDoc
4
4
  class Profile
5
5
  # A practitioner profile (raw +owner_type: "Account"+).
6
- class Practitioner < Profile; end
6
+ class Practitioner < Profile
7
+ main_attrs :name_with_title
8
+
9
+ def to_s
10
+ name_with_title || name
11
+ end
12
+ end
7
13
  end
8
14
  end
@@ -12,20 +12,86 @@ module TocDoc
12
12
  # profile.practitioner? #=> true
13
13
  # profile.name #=> "Dr Smith"
14
14
  class Profile < Resource
15
- # Factory — returns a +Profile::Practitioner+ or +Profile::Organization+
16
- # depending on the +owner_type+ field of the raw attribute hash.
17
- #
18
- # @param attrs [Hash] raw attribute hash from the API response
19
- # @return [Profile::Practitioner, Profile::Organization]
20
- def self.build(attrs = {})
21
- case attrs['owner_type'] || attrs[:owner_type]
22
- when 'Account'
23
- Practitioner.new(attrs)
24
- else
25
- Organization.new(attrs)
15
+ PATH = '/profiles/%<identifier>s.json'
16
+
17
+ main_attrs :id, :partial
18
+
19
+ class << self
20
+ # Factory returns a +Profile::Practitioner+ or +Profile::Organization+.
21
+ #
22
+ # Resolves type via +owner_type+ first (search context), then falls back
23
+ # to the boolean flags present on profile-page responses.
24
+ #
25
+ # @param attrs [Hash] raw attribute hash from the API response
26
+ # @return [Profile::Practitioner, Profile::Organization]
27
+ def build(attrs = {})
28
+ attrs = normalize_attrs(attrs)
29
+ return find(attrs['value']) if attrs['force_full_profile'] && attrs['owner_type']
30
+
31
+ case attrs['owner_type']
32
+ when 'Account' then Practitioner.new(attrs.merge('partial' => true))
33
+ when 'Organization' then Organization.new(attrs.merge('partial' => true))
34
+ else build_from_flags(attrs)
35
+ end
36
+ end
37
+
38
+ # Fetches a full profile page by slug or numeric ID.
39
+ #
40
+ # @param identifier [String, Integer] profile slug or numeric ID
41
+ # @return [Profile::Practitioner, Profile::Organization]
42
+ # @raise [ArgumentError] if +identifier+ is +nil+
43
+ #
44
+ # @example
45
+ # TocDoc::Profile.find('jane-doe-bordeaux')
46
+ # TocDoc::Profile.find(1542899)
47
+ def find(identifier)
48
+ raise ArgumentError, 'identifier cannot be nil' if identifier.nil?
49
+
50
+ data = TocDoc.client.get(format(PATH, identifier: identifier))['data']
51
+ build(profile_attrs(data))
52
+ end
53
+
54
+ private
55
+
56
+ def build_from_flags(attrs)
57
+ if attrs['is_practitioner']
58
+ Practitioner.new(attrs.merge('partial' => false))
59
+ elsif attrs['organization']
60
+ Organization.new(attrs.merge('partial' => false))
61
+ else
62
+ raise ArgumentError, "Unable to determine profile type from attributes: #{attrs.inspect}"
63
+ end
64
+ end
65
+
66
+ def profile_attrs(data)
67
+ data['profile'].merge(
68
+ 'speciality' => TocDoc::Speciality.new(data['profile']['speciality'] || {}),
69
+ 'places' => Array(data['places']).map { |p| TocDoc::Place.new(p) },
70
+ 'legals' => data['legals'],
71
+ 'details' => data['details'],
72
+ 'fees' => data['fees'],
73
+ 'bookable' => data['bookable']
74
+ )
26
75
  end
27
76
  end
28
77
 
78
+ # Returns all skills across all practices as an array of {TocDoc::Resource}.
79
+ #
80
+ # @return [Array<TocDoc::Resource>]
81
+ def skills
82
+ hash = self['skills_by_practice'] || {}
83
+ hash.values.flatten.map { |s| TocDoc::Resource.new(s) }
84
+ end
85
+
86
+ # Returns skills for a single practice as an array of {TocDoc::Resource}.
87
+ #
88
+ # @param practice_id [Integer, String] the practice ID
89
+ # @return [Array<TocDoc::Resource>]
90
+ def skills_for(practice_id)
91
+ hash = self['skills_by_practice'] || {}
92
+ Array(hash[practice_id.to_s]).map { |s| TocDoc::Resource.new(s) }
93
+ end
94
+
29
95
  # @return [Boolean] true when this profile is a practitioner
30
96
  def practitioner?
31
97
  is_a?(Practitioner)
@@ -14,9 +14,43 @@ module TocDoc
14
14
  # resource[:date] #=> "2026-02-28"
15
15
  # resource.to_h #=> { "date" => "2026-02-28", "slots" => [] }
16
16
  class Resource
17
+ class << self
18
+ # Normalises a raw attribute hash to string keys, mirroring what
19
+ # {#initialize} does internally. Useful in class-level factory methods
20
+ # that need to inspect attrs before wrapping them in a Resource instance.
21
+ #
22
+ # @param attrs [Hash] raw hash with string or symbol keys
23
+ # @return [Hash{String => Object}]
24
+ def normalize_attrs(attrs)
25
+ attrs.transform_keys(&:to_s)
26
+ end
27
+
28
+ # Declares which attribute keys are shown in +#inspect+.
29
+ # When called with arguments, sets the list for this class.
30
+ # When called with no arguments, returns the list (or +nil+ if unset),
31
+ # walking the ancestor chain so subclasses inherit the declaration.
32
+ #
33
+ # Subclasses that never call +main_attrs+ fall back to showing all attrs.
34
+ #
35
+ # @example
36
+ # main_attrs :id, :name, :slug
37
+ #
38
+ # @param keys [Array<Symbol, String>]
39
+ # @return [Array<String>, nil]
40
+ def main_attrs(*keys)
41
+ if keys.empty?
42
+ ancestor = ancestors.find { |a| a.instance_variable_defined?(:@main_attrs) }
43
+ ancestor&.instance_variable_get(:@main_attrs)
44
+ else
45
+ inherited = superclass.respond_to?(:main_attrs) ? (superclass.main_attrs || []) : []
46
+ @main_attrs = (inherited + keys.map(&:to_s)).uniq
47
+ end
48
+ end
49
+ end
50
+
17
51
  # @param attrs [Hash] the raw attribute hash (string or symbol keys)
18
52
  def initialize(attrs = {})
19
- @attrs = attrs.transform_keys(&:to_s)
53
+ @attrs = self.class.normalize_attrs(attrs)
20
54
  end
21
55
 
22
56
  # Read an attribute by name.
@@ -56,7 +90,7 @@ module TocDoc
56
90
  def ==(other)
57
91
  case other
58
92
  when Resource then @attrs == other.to_h
59
- when Hash then @attrs == other.transform_keys(&:to_s)
93
+ when Hash then @attrs == self.class.normalize_attrs(other)
60
94
  else false
61
95
  end
62
96
  end
@@ -78,5 +112,12 @@ module TocDoc
78
112
  key = method_name.to_s
79
113
  @attrs.key?(key) ? @attrs[key] : super
80
114
  end
115
+
116
+ # @!visibility private
117
+ def inspect
118
+ keys = self.class.main_attrs || @attrs.keys
119
+ pairs = keys.map { |k| "@#{k}=#{@attrs[k.to_s].inspect}" }.join(', ')
120
+ "#<#{self.class} #{pairs}>"
121
+ end
81
122
  end
82
123
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'toc_doc/models/resource'
4
+ require 'toc_doc/models/speciality'
5
+ require 'toc_doc/models/place'
4
6
  require 'toc_doc/models/search'
5
7
 
6
8
  require 'toc_doc/models/availability'
7
9
  require 'toc_doc/models/availability/collection'
8
10
 
9
11
  require 'toc_doc/models/profile'
10
- require 'toc_doc/models/speciality'
data/lib/toc_doc.rb CHANGED
@@ -89,6 +89,17 @@ module TocDoc
89
89
  TocDoc::Search.where(**)
90
90
  end
91
91
 
92
+ # Fetches a full profile page by slug or numeric ID.
93
+ #
94
+ # Delegates to {TocDoc::Profile.find} — see that method for full
95
+ # parameter documentation.
96
+ #
97
+ # @param identifier [String, Integer] profile slug or numeric ID
98
+ # @return [TocDoc::Profile::Practitioner, TocDoc::Profile::Organization]
99
+ def profile(identifier)
100
+ TocDoc::Profile.find(identifier)
101
+ end
102
+
92
103
  # @!visibility private
93
104
  def method_missing(method_name, ...)
94
105
  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.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 01max
@@ -76,6 +76,7 @@ files:
76
76
  - lib/toc_doc/models.rb
77
77
  - lib/toc_doc/models/availability.rb
78
78
  - lib/toc_doc/models/availability/collection.rb
79
+ - lib/toc_doc/models/place.rb
79
80
  - lib/toc_doc/models/profile.rb
80
81
  - lib/toc_doc/models/profile/organization.rb
81
82
  - lib/toc_doc/models/profile/practitioner.rb