Skip to content

Commit 59abb7e

Browse files
feat!: remove top level type aliases to relocated classes (#104)
1 parent ed3b639 commit 59abb7e

File tree

415 files changed

+2435
-2709
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

415 files changed

+2435
-2709
lines changed

lib/finch_api.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
require_relative "finch_api/internal/type/base_model"
4848
require_relative "finch_api/internal/type/base_page"
4949
require_relative "finch_api/internal/type/request_parameters"
50-
require_relative "finch_api/aliases"
50+
require_relative "finch_api/internal"
5151
require_relative "finch_api/request_options"
5252
require_relative "finch_api/errors"
5353
require_relative "finch_api/internal/transport/base_client"

lib/finch_api/aliases.rb

Lines changed: 0 additions & 19 deletions
This file was deleted.

lib/finch_api/errors.rb

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -189,32 +189,4 @@ class InternalServerError < FinchAPI::Errors::APIStatusError
189189
HTTP_STATUS = (500..)
190190
end
191191
end
192-
193-
Error = FinchAPI::Errors::Error
194-
195-
ConversionError = FinchAPI::Errors::ConversionError
196-
197-
APIError = FinchAPI::Errors::APIError
198-
199-
APIStatusError = FinchAPI::Errors::APIStatusError
200-
201-
APIConnectionError = FinchAPI::Errors::APIConnectionError
202-
203-
APITimeoutError = FinchAPI::Errors::APITimeoutError
204-
205-
BadRequestError = FinchAPI::Errors::BadRequestError
206-
207-
AuthenticationError = FinchAPI::Errors::AuthenticationError
208-
209-
PermissionDeniedError = FinchAPI::Errors::PermissionDeniedError
210-
211-
NotFoundError = FinchAPI::Errors::NotFoundError
212-
213-
ConflictError = FinchAPI::Errors::ConflictError
214-
215-
UnprocessableEntityError = FinchAPI::Errors::UnprocessableEntityError
216-
217-
RateLimitError = FinchAPI::Errors::RateLimitError
218-
219-
InternalServerError = FinchAPI::Errors::InternalServerError
220192
end

lib/finch_api/internal.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
module FinchAPI
4+
# @api private
5+
module Internal
6+
OMIT = Object.new.freeze
7+
end
8+
end

lib/finch_api/internal/transport/base_client.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def initialize(
339339

340340
begin
341341
status, response, stream = @requester.execute(input)
342-
rescue FinchAPI::APIConnectionError => e
342+
rescue FinchAPI::Errors::APIConnectionError => e
343343
status = e
344344
end
345345

@@ -361,7 +361,7 @@ def initialize(
361361
retry_count: retry_count,
362362
send_retry_header: send_retry_header
363363
)
364-
in FinchAPI::APIConnectionError if retry_count >= max_retries
364+
in FinchAPI::Errors::APIConnectionError if retry_count >= max_retries
365365
raise status
366366
in (400..) if retry_count >= max_retries || !self.class.should_retry?(status, headers: response)
367367
decoded = Kernel.then do
@@ -421,7 +421,7 @@ def initialize(
421421
# @return [Object]
422422
def request(req)
423423
self.class.validate!(req)
424-
model = req.fetch(:model) { FinchAPI::Unknown }
424+
model = req.fetch(:model) { FinchAPI::Internal::Type::Unknown }
425425
opts = req[:options].to_h
426426
FinchAPI::RequestOptions.validate!(opts)
427427
request = build_request(req.except(:options), opts)

lib/finch_api/internal/type/array_of.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def ===(other) = other.is_a?(Array) && other.all?(item_type)
3333
#
3434
# @return [Boolean]
3535
def ==(other)
36-
other.is_a?(FinchAPI::ArrayOf) && other.nilable? == nilable? && other.item_type == item_type
36+
# rubocop:disable Layout/LineLength
37+
other.is_a?(FinchAPI::Internal::Type::ArrayOf) && other.nilable? == nilable? && other.item_type == item_type
38+
# rubocop:enable Layout/LineLength
3739
end
3840

3941
# @api private

lib/finch_api/internal/type/base_model.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class << self
2323
#
2424
# @return [Hash{Symbol=>Hash{Symbol=>Object}}]
2525
def known_fields
26-
@known_fields ||= (self < FinchAPI::BaseModel ? superclass.known_fields.dup : {})
26+
@known_fields ||= (self < FinchAPI::Internal::Type::BaseModel ? superclass.known_fields.dup : {})
2727
end
2828

2929
# @api private
@@ -67,10 +67,10 @@ def fields
6767
const = if required && !nilable
6868
info.fetch(
6969
:const,
70-
FinchAPI::Internal::Util::OMIT
70+
FinchAPI::Internal::OMIT
7171
)
7272
else
73-
FinchAPI::Internal::Util::OMIT
73+
FinchAPI::Internal::OMIT
7474
end
7575

7676
[name_sym, setter].each { undef_method(_1) } if known_fields.key?(name_sym)
@@ -89,7 +89,7 @@ def fields
8989

9090
define_method(name_sym) do
9191
target = type_fn.call
92-
value = @data.fetch(name_sym) { const == FinchAPI::Internal::Util::OMIT ? nil : const }
92+
value = @data.fetch(name_sym) { const == FinchAPI::Internal::OMIT ? nil : const }
9393
state = {strictness: :strong, exactness: {yes: 0, no: 0, maybe: 0}, branched: 0}
9494
if (nilable || !required) && value.nil?
9595
nil
@@ -105,7 +105,7 @@ def fields
105105
# rubocop:disable Layout/LineLength
106106
message = "Failed to parse #{cls}.#{__method__} from #{value.class} to #{target.inspect}. To get the unparsed API response, use #{cls}[:#{__method__}]."
107107
# rubocop:enable Layout/LineLength
108-
raise FinchAPI::ConversionError.new(message)
108+
raise FinchAPI::Errors::ConversionError.new(message)
109109
end
110110
end
111111

@@ -175,7 +175,7 @@ def optional(name_sym, type_info, spec = {})
175175
# @param other [Object]
176176
#
177177
# @return [Boolean]
178-
def ==(other) = other.is_a?(Class) && other <= FinchAPI::BaseModel && other.fields == fields
178+
def ==(other) = other.is_a?(Class) && other <= FinchAPI::Internal::Type::BaseModel && other.fields == fields
179179
end
180180

181181
# @param other [Object]
@@ -186,7 +186,7 @@ def ==(other) = self.class == other.class && @data == other.to_h
186186
class << self
187187
# @api private
188188
#
189-
# @param value [FinchAPI::BaseModel, Hash{Object=>Object}, Object]
189+
# @param value [FinchAPI::Internal::Type::BaseModel, Hash{Object=>Object}, Object]
190190
#
191191
# @param state [Hash{Symbol=>Object}] .
192192
#
@@ -196,7 +196,7 @@ class << self
196196
#
197197
# @option state [Integer] :branched
198198
#
199-
# @return [FinchAPI::BaseModel, Object]
199+
# @return [FinchAPI::Internal::Type::BaseModel, Object]
200200
def coerce(value, state:)
201201
exactness = state.fetch(:exactness)
202202

@@ -221,7 +221,7 @@ def coerce(value, state:)
221221
api_name, nilable, const = field.fetch_values(:api_name, :nilable, :const)
222222

223223
unless val.key?(api_name)
224-
if required && mode != :dump && const == FinchAPI::Internal::Util::OMIT
224+
if required && mode != :dump && const == FinchAPI::Internal::OMIT
225225
exactness[nilable ? :maybe : :no] += 1
226226
else
227227
exactness[:yes] += 1
@@ -255,7 +255,7 @@ def coerce(value, state:)
255255

256256
# @api private
257257
#
258-
# @param value [FinchAPI::BaseModel, Object]
258+
# @param value [FinchAPI::Internal::Type::BaseModel, Object]
259259
#
260260
# @return [Hash{Object=>Object}, Object]
261261
def dump(value)
@@ -284,7 +284,7 @@ def dump(value)
284284

285285
known_fields.each_value do |field|
286286
mode, api_name, const = field.fetch_values(:mode, :api_name, :const)
287-
next if mode == :coerce || acc.key?(api_name) || const == FinchAPI::Internal::Util::OMIT
287+
next if mode == :coerce || acc.key?(api_name) || const == FinchAPI::Internal::OMIT
288288
acc.store(api_name, const)
289289
end
290290

@@ -351,13 +351,13 @@ def to_yaml(*a) = self.class.dump(self).to_yaml(*a)
351351

352352
# Create a new instance of a model.
353353
#
354-
# @param data [Hash{Symbol=>Object}, FinchAPI::BaseModel]
354+
# @param data [Hash{Symbol=>Object}, FinchAPI::Internal::Type::BaseModel]
355355
def initialize(data = {})
356356
case FinchAPI::Internal::Util.coerce_hash(data)
357357
in Hash => coerced
358358
@data = coerced
359359
else
360-
raise ArgumentError.new("Expected a #{Hash} or #{FinchAPI::BaseModel}, got #{data.inspect}")
360+
raise ArgumentError.new("Expected a #{Hash} or #{FinchAPI::Internal::Type::BaseModel}, got #{data.inspect}")
361361
end
362362
end
363363

lib/finch_api/internal/type/boolean_model.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def self.===(other) = other == true || other == false
1919
# @param other [Object]
2020
#
2121
# @return [Boolean]
22-
def self.==(other) = other.is_a?(Class) && other <= FinchAPI::BooleanModel
22+
def self.==(other) = other.is_a?(Class) && other <= FinchAPI::Internal::Type::BooleanModel
2323

2424
class << self
2525
# @api private

lib/finch_api/internal/type/converter.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ def coerce(value, state:) = (raise NotImplementedError)
3131
def dump(value)
3232
case value
3333
in Array
34-
value.map { FinchAPI::Unknown.dump(_1) }
34+
value.map { FinchAPI::Internal::Type::Unknown.dump(_1) }
3535
in Hash
36-
value.transform_values { FinchAPI::Unknown.dump(_1) }
37-
in FinchAPI::BaseModel
36+
value.transform_values { FinchAPI::Internal::Type::Unknown.dump(_1) }
37+
in FinchAPI::Internal::Type::BaseModel
3838
value.class.dump(value)
3939
else
4040
value
@@ -64,7 +64,7 @@ def type_info(spec)
6464
in Hash
6565
type_info(spec.slice(:const, :enum, :union).first&.last)
6666
in true | false
67-
-> { FinchAPI::BooleanModel }
67+
-> { FinchAPI::Internal::Type::BooleanModel }
6868
in FinchAPI::Internal::Type::Converter | Class | Symbol
6969
-> { spec }
7070
in NilClass | Integer | Float
@@ -209,7 +209,7 @@ def coerce(
209209
#
210210
# @return [Object]
211211
def dump(target, value)
212-
target.is_a?(FinchAPI::Internal::Type::Converter) ? target.dump(value) : FinchAPI::Unknown.dump(value)
212+
target.is_a?(FinchAPI::Internal::Type::Converter) ? target.dump(value) : FinchAPI::Internal::Type::Unknown.dump(value)
213213
end
214214
end
215215
end

lib/finch_api/internal/type/enum.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def ===(other) = values.include?(other)
6262
#
6363
# @return [Boolean]
6464
def ==(other)
65-
other.is_a?(Module) && other.singleton_class <= FinchAPI::Enum && other.values.to_set == values.to_set
65+
other.is_a?(Module) && other.singleton_class <= FinchAPI::Internal::Type::Enum && other.values.to_set == values.to_set
6666
end
6767

6868
# @api private

0 commit comments

Comments
 (0)