Skip to content

Commit 9297be8

Browse files
chore(internal): minor touch ups on sdk internals
1 parent 2b99ae2 commit 9297be8

6 files changed

Lines changed: 55 additions & 46 deletions

File tree

lib/orb/internal/page.rb

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,6 @@ class Page
2222
# @return [PaginationMetadata]
2323
attr_accessor :pagination_metadata
2424

25-
# @api private
26-
#
27-
# @param client [Orb::Internal::Transport::BaseClient]
28-
# @param req [Hash{Symbol=>Object}]
29-
# @param headers [Hash{String=>String}, Net::HTTPHeader]
30-
# @param page_data [Hash{Symbol=>Object}]
31-
def initialize(client:, req:, headers:, page_data:)
32-
super
33-
34-
case page_data
35-
in {data: Array | nil => data}
36-
@data = data&.map { Orb::Internal::Type::Converter.coerce(@model, _1) }
37-
else
38-
end
39-
40-
case page_data
41-
in {pagination_metadata: Hash | nil => pagination_metadata}
42-
@pagination_metadata =
43-
Orb::Internal::Type::Converter.coerce(
44-
Orb::Internal::Page::PaginationMetadata,
45-
pagination_metadata
46-
)
47-
else
48-
end
49-
end
50-
5125
# @return [Boolean]
5226
def next_page?
5327
!pagination_metadata&.next_cursor.nil?
@@ -82,15 +56,38 @@ def auto_paging_each(&blk)
8256
end
8357
end
8458

59+
# @api private
60+
#
61+
# @param client [Orb::Internal::Transport::BaseClient]
62+
# @param req [Hash{Symbol=>Object}]
63+
# @param headers [Hash{String=>String}, Net::HTTPHeader]
64+
# @param page_data [Hash{Symbol=>Object}]
65+
def initialize(client:, req:, headers:, page_data:)
66+
super
67+
68+
case page_data
69+
in {data: Array | nil => data}
70+
@data = data&.map { Orb::Internal::Type::Converter.coerce(@model, _1) }
71+
else
72+
end
73+
case page_data
74+
in {pagination_metadata: Hash | nil => pagination_metadata}
75+
@pagination_metadata =
76+
Orb::Internal::Type::Converter.coerce(
77+
Orb::Internal::Page::PaginationMetadata,
78+
pagination_metadata
79+
)
80+
else
81+
end
82+
end
83+
8584
# @api private
8685
#
8786
# @return [String]
8887
def inspect
89-
# rubocop:disable Layout/LineLength
9088
model = Orb::Internal::Type::Converter.inspect(@model, depth: 1)
9189

92-
"#<#{self.class}[#{model}]:0x#{object_id.to_s(16)} pagination_metadata=#{pagination_metadata.inspect}>"
93-
# rubocop:enable Layout/LineLength
90+
"#<#{self.class}[#{model}]:0x#{object_id.to_s(16)}>"
9491
end
9592

9693
class PaginationMetadata < Orb::Internal::Type::BaseModel

lib/orb/internal/transport/base_client.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,23 @@ def follow_redirect(request, status:, response_headers:)
9393
URI.join(url, response_headers["location"])
9494
rescue ArgumentError
9595
message = "Server responded with status #{status} but no valid location header."
96-
raise Orb::Errors::APIConnectionError.new(url: url, message: message)
96+
raise Orb::Errors::APIConnectionError.new(
97+
url: url,
98+
response: response_headers,
99+
message: message
100+
)
97101
end
98102

99103
request = {**request, url: location}
100104

101105
case [url.scheme, location.scheme]
102106
in ["https", "http"]
103107
message = "Tried to redirect to a insecure URL"
104-
raise Orb::Errors::APIConnectionError.new(url: url, message: message)
108+
raise Orb::Errors::APIConnectionError.new(
109+
url: url,
110+
response: response_headers,
111+
message: message
112+
)
105113
else
106114
nil
107115
end
@@ -350,7 +358,7 @@ def initialize(
350358
self.class.reap_connection!(status, stream: stream)
351359

352360
message = "Failed to complete the request within #{self.class::MAX_REDIRECTS} redirects."
353-
raise Orb::Errors::APIConnectionError.new(url: url, message: message)
361+
raise Orb::Errors::APIConnectionError.new(url: url, response: response, message: message)
354362
in 300..399
355363
self.class.reap_connection!(status, stream: stream)
356364

lib/orb/internal/type/array_of.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class ArrayOf
1515

1616
private_class_method :new
1717

18+
# @overload [](type_info, spec = {})
19+
#
1820
# @param type_info [Hash{Symbol=>Object}, Proc, Orb::Internal::Type::Converter, Class]
1921
#
2022
# @param spec [Hash{Symbol=>Object}] .
@@ -26,7 +28,7 @@ class ArrayOf
2628
# @option spec [Proc] :union
2729
#
2830
# @option spec [Boolean] :"nil?"
29-
def self.[](type_info, spec = {}) = new(type_info, spec)
31+
def self.[](...) = new(...)
3032

3133
# @param other [Object]
3234
#
@@ -131,9 +133,9 @@ def initialize(type_info, spec = {})
131133
#
132134
# @return [String]
133135
def inspect(depth: 0)
134-
# rubocop:disable Layout/LineLength
135-
"#{self.class}[#{[Orb::Internal::Type::Converter.inspect(item_type, depth: depth.succ), nilable? ? 'nil' : nil].compact.join(' | ')}]"
136-
# rubocop:enable Layout/LineLength
136+
items = Orb::Internal::Type::Converter.inspect(item_type, depth: depth.succ)
137+
138+
"#{self.class}[#{[items, nilable? ? 'nil' : nil].compact.join(' | ')}]"
137139
end
138140
end
139141
end

lib/orb/internal/type/enum.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ def coerce(value, state:)
110110
#
111111
# @return [String]
112112
def inspect(depth: 0)
113-
# rubocop:disable Layout/LineLength
114113
return super() if depth.positive?
115114

116-
"#{name}[#{values.map { Orb::Internal::Type::Converter.inspect(_1, depth: depth.succ) }.join(' | ')}]"
117-
# rubocop:enable Layout/LineLength
115+
members = values.map { Orb::Internal::Type::Converter.inspect(_1, depth: depth.succ) }
116+
117+
"#{name}[#{members.join(' | ')}]"
118118
end
119119
end
120120
end

lib/orb/internal/type/hash_of.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class HashOf
1515

1616
private_class_method :new
1717

18+
# @overload [](type_info, spec = {})
19+
#
1820
# @param type_info [Hash{Symbol=>Object}, Proc, Orb::Internal::Type::Converter, Class]
1921
#
2022
# @param spec [Hash{Symbol=>Object}] .
@@ -26,7 +28,7 @@ class HashOf
2628
# @option spec [Proc] :union
2729
#
2830
# @option spec [Boolean] :"nil?"
29-
def self.[](type_info, spec = {}) = new(type_info, spec)
31+
def self.[](...) = new(...)
3032

3133
# @param other [Object]
3234
#
@@ -151,9 +153,9 @@ def initialize(type_info, spec = {})
151153
#
152154
# @return [String]
153155
def inspect(depth: 0)
154-
# rubocop:disable Layout/LineLength
155-
"#{self.class}[#{[Orb::Internal::Type::Converter.inspect(item_type, depth: depth.succ), nilable? ? 'nil' : nil].compact.join(' | ')}]"
156-
# rubocop:enable Layout/LineLength
156+
items = Orb::Internal::Type::Converter.inspect(item_type, depth: depth.succ)
157+
158+
"#{self.class}[#{[items, nilable? ? 'nil' : nil].compact.join(' | ')}]"
157159
end
158160
end
159161
end

lib/orb/internal/type/union.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ def dump(value, state:)
232232
#
233233
# @return [String]
234234
def inspect(depth: 0)
235-
# rubocop:disable Layout/LineLength
236235
return super() if depth.positive?
237236

238-
"#{name}[#{variants.map { Orb::Internal::Type::Converter.inspect(_1, depth: depth.succ) }.join(' | ')}]"
239-
# rubocop:enable Layout/LineLength
237+
members = variants.map { Orb::Internal::Type::Converter.inspect(_1, depth: depth.succ) }
238+
239+
"#{name}[#{members.join(' | ')}]"
240240
end
241241
end
242242
end

0 commit comments

Comments
 (0)