toc_doc 1.0.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.
@@ -0,0 +1,79 @@
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
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'toc_doc/models/resource'
4
+ require 'toc_doc/models/availability'
5
+
6
+ require 'toc_doc/models/response/availability'
data/lib/toc_doc.rb ADDED
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'toc_doc/core/version'
4
+
5
+ require 'toc_doc/core/error'
6
+ require 'toc_doc/core/configurable'
7
+ require 'toc_doc/core/connection'
8
+ require 'toc_doc/core/uri_utils'
9
+
10
+ require 'toc_doc/models'
11
+
12
+ require 'toc_doc/client'
13
+
14
+ # The main module for TocDoc — a Ruby client for the Doctolib API.
15
+ #
16
+ # Configuration can be set at the module level and will be inherited by every
17
+ # {TocDoc::Client} instance created via {.client} or {.setup}.
18
+ #
19
+ # Any method available on {TocDoc::Client} can be called directly on `TocDoc`
20
+ # and will be forwarded to the memoized {.client}.
21
+ #
22
+ # @example Quick start
23
+ # TocDoc.setup do |config|
24
+ # config.api_endpoint = 'https://www.doctolib.de'
25
+ # config.auto_paginate = true
26
+ # end
27
+ #
28
+ # TocDoc.availabilities(
29
+ # visit_motive_ids: 7_767_829,
30
+ # agenda_ids: 1_101_600,
31
+ # practice_ids: 377_272
32
+ # )
33
+ #
34
+ # @see TocDoc::Configurable
35
+ # @see TocDoc::Client
36
+ module TocDoc
37
+ extend Configurable
38
+
39
+ class << self
40
+ # Returns a memoized {TocDoc::Client} configured with the current
41
+ # module-level options. A new client is created whenever the options
42
+ # have changed since the last call.
43
+ #
44
+ # @return [TocDoc::Client]
45
+ def client
46
+ if !defined?(@client) || @client.nil? || !@client.respond_to?(:same_options?) || !@client.same_options?(options)
47
+ @client = TocDoc::Client.new(options)
48
+ end
49
+ @client
50
+ end
51
+
52
+ # Allows replacing the current client instance.
53
+ #
54
+ # @param value [TocDoc::Client] a pre-configured client instance
55
+ # @return [TocDoc::Client]
56
+ attr_writer :client
57
+
58
+ # Configure TocDoc at the module level and return the client.
59
+ #
60
+ # @yield [config] yields self so options can be set in a block
61
+ # @yieldparam config [TocDoc] the module itself (responds to {Configurable} setters)
62
+ # @return [TocDoc::Client] the memoized client, reflecting the new configuration
63
+ #
64
+ # @example
65
+ # TocDoc.setup do |config|
66
+ # config.api_endpoint = 'https://www.doctolib.de'
67
+ # end
68
+ def setup
69
+ yield self if block_given?
70
+ client
71
+ end
72
+
73
+ # @!visibility private
74
+ def method_missing(method_name, ...)
75
+ if client.respond_to?(method_name)
76
+ client.public_send(method_name, ...)
77
+ else
78
+ super
79
+ end
80
+ end
81
+
82
+ # @!visibility private
83
+ def respond_to_missing?(method_name, include_private = false)
84
+ client.respond_to?(method_name, include_private) || super
85
+ end
86
+ end
87
+ end
88
+
89
+ # Initialize module-level configuration on load.
90
+ TocDoc.reset!
data/sig/toc_doc.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module TocDoc
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: toc_doc
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - 01max
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '3'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '1'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '3'
32
+ - !ruby/object:Gem::Dependency
33
+ name: faraday-retry
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '2.0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: '2.0'
46
+ description: |-
47
+ A standalone Ruby gem providing a Faraday-based client
48
+ with modular resource endpoints, configurable defaults, and a clean error hierarchy.
49
+ email:
50
+ - m.louguet@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - ".env.example"
56
+ - ".yardopts"
57
+ - CHANGELOG.md
58
+ - CODE_OF_CONDUCT.md
59
+ - LICENSE.md
60
+ - README.md
61
+ - Rakefile
62
+ - TODO.md
63
+ - lib/toc_doc.rb
64
+ - lib/toc_doc/client.rb
65
+ - lib/toc_doc/client/availabilities.rb
66
+ - lib/toc_doc/core/authentication.rb
67
+ - lib/toc_doc/core/configurable.rb
68
+ - lib/toc_doc/core/connection.rb
69
+ - lib/toc_doc/core/default.rb
70
+ - lib/toc_doc/core/error.rb
71
+ - lib/toc_doc/core/uri_utils.rb
72
+ - lib/toc_doc/core/version.rb
73
+ - lib/toc_doc/http/middleware/raise_error.rb
74
+ - lib/toc_doc/http/response/base_middleware.rb
75
+ - lib/toc_doc/middleware/.keep
76
+ - lib/toc_doc/models.rb
77
+ - lib/toc_doc/models/availability.rb
78
+ - lib/toc_doc/models/resource.rb
79
+ - lib/toc_doc/models/response/availability.rb
80
+ - sig/toc_doc.rbs
81
+ homepage: https://github.com/01max/toc_doc
82
+ licenses:
83
+ - GPL-3.0-or-later
84
+ metadata:
85
+ allowed_push_host: https://rubygems.org
86
+ homepage_uri: https://github.com/01max/toc_doc
87
+ source_code_uri: https://github.com/01max/toc_doc/tree/main
88
+ changelog_uri: https://github.com/01max/toc_doc/blob/main/CHANGELOG.md
89
+ rubygems_mfa_required: 'true'
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 3.2.0
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubygems_version: 3.6.7
105
+ specification_version: 4
106
+ summary: A Ruby gem to interact with the (unofficial) Doctolib API.
107
+ test_files: []