Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.25"
".": "0.1.0-alpha.26"
}
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## 0.1.0-alpha.26 (2025-03-12)

Full Changelog: [v0.1.0-alpha.25...v0.1.0-alpha.26](https://github.com/orbcorp/orb-ruby/compare/v0.1.0-alpha.25...v0.1.0-alpha.26)

### Bug Fixes

* enums should only coerce matching symbols into strings ([#149](https://github.com/orbcorp/orb-ruby/issues/149)) ([1de63b1](https://github.com/orbcorp/orb-ruby/commit/1de63b1d39a7747b08b51cf416b5fa3db6a980a1))


### Chores

* fused enum should use faster internal iteration by default ([#143](https://github.com/orbcorp/orb-ruby/issues/143)) ([1e20ed1](https://github.com/orbcorp/orb-ruby/commit/1e20ed147852db214689352294b4818fb76eff00))
* improve documentation ([#144](https://github.com/orbcorp/orb-ruby/issues/144)) ([afa2343](https://github.com/orbcorp/orb-ruby/commit/afa234381c6955219e184aa8c14084cdfa8a072d))
* **internal:** codegen related update ([#140](https://github.com/orbcorp/orb-ruby/issues/140)) ([c7a3c48](https://github.com/orbcorp/orb-ruby/commit/c7a3c48caa6e26c736623c29eaac2466c28083e2))
* **internal:** codegen related update ([#141](https://github.com/orbcorp/orb-ruby/issues/141)) ([6d86b55](https://github.com/orbcorp/orb-ruby/commit/6d86b558ac458e6f560dcd753bfbbe417dc81f76))
* **internal:** codegen related update ([#145](https://github.com/orbcorp/orb-ruby/issues/145)) ([39ef52b](https://github.com/orbcorp/orb-ruby/commit/39ef52b535d1495da3b5717b98cf9ea5cba94eff))
* **internal:** codegen related update ([#146](https://github.com/orbcorp/orb-ruby/issues/146)) ([e26d896](https://github.com/orbcorp/orb-ruby/commit/e26d896ac7e4704a4186e68db3b5784f377e723d))
* **internal:** codegen related update ([#148](https://github.com/orbcorp/orb-ruby/issues/148)) ([d6758f6](https://github.com/orbcorp/orb-ruby/commit/d6758f61a116f2ec4e7b22010b6a99f1ec6b6318))
* **internal:** version bump ([#138](https://github.com/orbcorp/orb-ruby/issues/138)) ([94e3490](https://github.com/orbcorp/orb-ruby/commit/94e34903c66b574ac35cd441625e95bf38c4c710))

## 0.1.0-alpha.25 (2025-03-11)

Full Changelog: [v0.1.0-alpha.24...v0.1.0-alpha.25](https://github.com/orbcorp/orb-ruby/compare/v0.1.0-alpha.24...v0.1.0-alpha.25)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GIT
PATH
remote: .
specs:
orb (0.1.0.pre.alpha.25)
orb (0.1.0.pre.alpha.26)
connection_pool

GEM
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ customer = orb.customers.create(email: "[email protected]", name: "My
puts(customer.id)
```

## Pagination
### Pagination

List methods in the Orb API are paginated.

Expand Down
2 changes: 2 additions & 0 deletions lib/orb/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,10 @@ def request(req)
# @return [String]
#
def inspect
# rubocop:disable Layout/LineLength
base_url = Orb::Util.unparse_uri(@base_url)
"#<#{self.class.name}:0x#{object_id.to_s(16)} base_url=#{base_url} max_retries=#{@max_retries} timeout=#{@timeout}>"
# rubocop:enable Layout/LineLength
end
end
end
29 changes: 25 additions & 4 deletions lib/orb/base_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def type_info(spec)
type_info(spec.slice(:const, :enum, :union).first&.last)
in Proc
spec
in Orb::Converter | Class
in Orb::Converter | Class | Symbol
-> { spec }
in true | false
-> { Orb::BooleanModel }
in NilClass | true | false | Symbol | Integer | Float
in NilClass | Integer | Float
-> { spec.class }
end
end
Expand All @@ -82,6 +82,13 @@ def coerce(target, value)
case target
in Orb::Converter
target.coerce(value)
in Symbol
case value
in Symbol | String if (val = value.to_sym) == target
val
else
value
end
in Class
case target
in -> { _1 <= NilClass }
Expand Down Expand Up @@ -140,6 +147,13 @@ def try_strict_coerce(target, value)
case target
in Orb::Converter
target.try_strict_coerce(value)
in Symbol
case value
in Symbol | String if (val = value.to_sym) == target
[true, val, 1]
else
[false, false, 0]
end
in Class
case [target, value]
in [-> { _1 <= NilClass }, _]
Expand Down Expand Up @@ -363,7 +377,14 @@ class << self
#
# @return [Symbol, Object]
#
def coerce(value) = (value.is_a?(String) ? value.to_sym : value)
def coerce(value)
case value
in Symbol | String if values.include?(val = value.to_sym)
val
else
value
end
end

# @!parse
# # @private
Expand All @@ -384,7 +405,7 @@ def try_strict_coerce(value)
return [true, value, 1] if values.include?(value)

case value
in String if values.include?(val = value.to_sym)
in Symbol | String if values.include?(val = value.to_sym)
[true, val, 1]
else
case [value, values.first]
Expand Down
20 changes: 20 additions & 0 deletions lib/orb/base_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ module Orb
#
# @abstract
#
# @example
# ```ruby
# if page.has_next?
# page = page.next_page
# end
# ```
#
# @example
# ```ruby
# page.auto_paging_each do |top_level|
# puts(top_level)
# end
# ```
#
# @example
# ```ruby
# top_levels = page.to_enum.take(2)
#
# top_levels => Array
# ```
module BasePage
# @return [Boolean]
#
Expand Down
8 changes: 4 additions & 4 deletions lib/orb/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
#
# @example
# ```ruby
# page.auto_paging_each do |item|
# # item ...
# page.auto_paging_each do |coupon|
# puts(coupon)
# end
# ```
#
# @example
# ```ruby
# items = page.to_enum.take(2)
# coupons = page.to_enum.take(2)
#
# items => Array
# coupons => Array
# ```
class Page
include Orb::BasePage
Expand Down Expand Up @@ -68,7 +68,7 @@
#
def next_page
unless next_page?
raise RuntimeError.new("No more pages available. Please check #next_page? before calling ##{__method__}")

Check warning on line 71 in lib/orb/page.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/LineLength: Line is too long. [113/110]
end

req = Orb::Util.deep_merge(@req, {query: {cursor: pagination_metadata&.next_cursor}})
Expand All @@ -92,7 +92,7 @@
# @return [String]
#
def inspect
"#<#{self.class}:0x#{object_id.to_s(16)} data=#{data.inspect} pagination_metadata=#{pagination_metadata.inspect}>"

Check warning on line 95 in lib/orb/page.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/LineLength: Line is too long. [120/110]
end

class PaginationMetadata < Orb::BaseModel
Expand Down
33 changes: 23 additions & 10 deletions lib/orb/pooled_net_requester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@
#
# @option request [Hash{String=>String}] :headers
#
# @param blk [Proc]
#
# @return [Net::HTTPGenericRequest]
#
def build_request(request)
def build_request(request, &)
method, url, headers, body = request.fetch_values(:method, :url, :headers, :body)
req = Net::HTTPGenericRequest.new(
method.to_s.upcase,
Expand All @@ -62,14 +64,16 @@
headers.each { req[_1] = _2 }

case body
in nil

Check warning on line 67 in lib/orb/pooled_net_requester.rb

View workflow job for this annotation

GitHub Actions / lint

Lint/EmptyInPattern: Avoid `in` branches without a body.
in String
req.body = body
req["content-length"] ||= body.bytesize.to_s unless req["transfer-encoding"]
req.body_stream = Orb::Util::ReadIOAdapter.new(body, &)
in StringIO
req.body = body.string
in IO
body.rewind
req.body_stream = body
req["content-length"] ||= body.size.to_s unless req["transfer-encoding"]
req.body_stream = Orb::Util::ReadIOAdapter.new(body, &)
in IO | Enumerator
req["transfer-encoding"] ||= "chunked" unless req["content-length"]
req.body_stream = Orb::Util::ReadIOAdapter.new(body, &)
end

req
Expand Down Expand Up @@ -97,7 +101,7 @@

pool =
@mutex.synchronize do
@pools[origin] ||= ConnectionPool.new(size: Etc.nprocessors) do
@pools[origin] ||= ConnectionPool.new(size: @size) do
self.class.connect(url)
end
end
Expand Down Expand Up @@ -128,14 +132,17 @@
#
def execute(request)
url, deadline = request.fetch_values(:url, :deadline)
req = self.class.build_request(request)

eof = false
finished = false
enum = Enumerator.new do |y|
with_pool(url) do |conn|
next if finished

req = self.class.build_request(request) do
self.class.calibrate_socket_timeout(conn, deadline)
end

self.class.calibrate_socket_timeout(conn, deadline)
conn.start unless conn.started?

Expand All @@ -156,19 +163,25 @@
end

conn, response = enum.next
body = Orb::Util.fused_enum(enum) do
body = Orb::Util.fused_enum(enum, external: true) do
finished = true
tap do
enum.next
rescue StopIteration
nil
end
conn.finish if !eof && conn&.started?
end
[response, (response.body = body)]
end

def initialize
# @private
#
# @param size [Integer]
#
def initialize(size: Etc.nprocessors)
@mutex = Mutex.new
@size = size
@pools = {}
end
end
Expand Down
Loading
Loading