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.22"
".": "0.1.0-alpha.23"
}
7 changes: 6 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ AllCops:
- "bin/*"
NewCops: enable
SuggestExtensions: false
TargetRubyVersion: 3.1.0
TargetRubyVersion: 3.2.0

# Whether MFA is required or not should be left to the token configuration.
Gemspec/RequireMFA:
Expand Down Expand Up @@ -112,6 +112,8 @@ Metrics/AbcSize:
Metrics/BlockLength:
AllowedPatterns:
- assert_pattern
- type_alias
- define_sorbet_constant!
Exclude:
- "**/*.rbi"

Expand Down Expand Up @@ -182,6 +184,9 @@ Style/ClassAndModuleChildren:
Exclude:
- "test/**/*"

Style/CommentAnnotation:
Enabled: false

# We should go back and add these docs, but ignore for now.
Style/Documentation:
Enabled: false
Expand Down
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 195
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/increase%2Fincrease-99d09de90656238ac57bf6711950f043967548c1c4e2ad31b606dd51e0daa3e9.yml
openapi_spec_hash: 597d3aed886356d053b7c571cab6380b
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/increase%2Fincrease-3b98767c54e46b8a6cb396e0ec9c40154ab6566387fe3869ca2f36cb98759633.yml
openapi_spec_hash: 870fbf29bc099f704b2e90a55362d6e5
config_hash: 1619155422217276e2489ae10ce63a25
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 0.1.0-alpha.23 (2025-05-13)

Full Changelog: [v0.1.0-alpha.22...v0.1.0-alpha.23](https://github.com/Increase/increase-ruby/compare/v0.1.0-alpha.22...v0.1.0-alpha.23)

### Features

* expose base client options as read only attributes ([22199bc](https://github.com/Increase/increase-ruby/commit/22199bc7e21f1c545662ae0da9934598f8c190e5))
* expose recursive `#to_h` conversion ([bc9b4f3](https://github.com/Increase/increase-ruby/commit/bc9b4f3e3063d52a4454084832f3b12a052a4af8))


### Bug Fixes

* **internal:** update gemspec name ([4323fb5](https://github.com/Increase/increase-ruby/commit/4323fb58792ad85fe9109898bbf47f578cb3f43a))


### Chores

* fix misc linting / minor issues ([730b149](https://github.com/Increase/increase-ruby/commit/730b14968b92319ce539148582bfe9e968fe07f3))

## 0.1.0-alpha.22 (2025-05-12)

Full Changelog: [v0.1.0-alpha.21...v0.1.0-alpha.22](https://github.com/Increase/increase-ruby/compare/v0.1.0-alpha.21...v0.1.0-alpha.22)
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:
increase (0.1.0.pre.alpha.22)
increase (0.1.0.pre.alpha.23)
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 @@ -15,7 +15,7 @@ To use this gem, install via Bundler by adding the following to your application
<!-- x-release-please-start-version -->

```ruby
gem "increase", "~> 0.1.0.pre.alpha.22"
gem "increase", "~> 0.1.0.pre.alpha.23"
```

<!-- x-release-please-end -->
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ desc("Lint `*.rb(i)`")
multitask(:"lint:rubocop") do
find = %w[find ./lib ./test ./rbi -type f -and ( -name *.rb -or -name *.rbi ) -print0]

rubocop = %w[rubocop --fail-level E]
rubocop = %w[rubocop]
rubocop += %w[--format github] if ENV.key?("CI")

# some lines cannot be shortened
Expand Down Expand Up @@ -147,7 +147,7 @@ multitask(:"build:gem") do
sig/*
GLOB

sh(*%w[gem build -- openai.gemspec])
sh(*%w[gem build -- increase.gemspec])
rm_rf(ignore_file)
end

Expand Down
2 changes: 2 additions & 0 deletions lib/increase.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

# Standard libraries.
# rubocop:disable Lint/RedundantRequireStatement
require "English"
require "cgi"
require "date"
Expand All @@ -15,6 +16,7 @@
require "stringio"
require "time"
require "uri"
# rubocop:enable Lint/RedundantRequireStatement

# We already ship the preferred sorbet manifests in the package itself.
# `tapioca` currently does not offer us a way to opt out of unnecessary compilation.
Expand Down
2 changes: 1 addition & 1 deletion lib/increase/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class APIStatusError < Increase::Errors::APIError
# @param response [nil]
# @param message [String, nil]
#
# @return [Increase::Errors::APIStatusError]
# @return [self]
def self.for(url:, status:, body:, request:, response:, message: nil)
key = Increase::Internal::Util.dig(body, :type)
kwargs = {
Expand Down
35 changes: 30 additions & 5 deletions lib/increase/internal/transport/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,27 @@ def reap_connection!(status, stream:)
end
end

# @return [URI::Generic]
attr_reader :base_url

# @return [Float]
attr_reader :timeout

# @return [Integer]
attr_reader :max_retries

# @return [Float]
attr_reader :initial_retry_delay

# @return [Float]
attr_reader :max_retry_delay

# @return [Hash{String=>String}]
attr_reader :headers

# @return [String, nil]
attr_reader :idempotency_header

# @api private
# @return [Increase::Internal::Transport::PooledNetRequester]
attr_reader :requester
Expand Down Expand Up @@ -184,10 +205,11 @@ def initialize(
},
headers
)
@base_url = Increase::Internal::Util.parse_uri(base_url)
@base_url_components = Increase::Internal::Util.parse_uri(base_url)
@base_url = Increase::Internal::Util.unparse_uri(@base_url_components)
@idempotency_header = idempotency_header&.to_s&.downcase
@max_retries = max_retries
@timeout = timeout
@max_retries = max_retries
@initial_retry_delay = initial_retry_delay
@max_retry_delay = max_retry_delay
end
Expand Down Expand Up @@ -278,10 +300,14 @@ def initialize(
Increase::Internal::Util.deep_merge(*[req[:body], opts[:extra_body]].compact)
end

url = Increase::Internal::Util.join_parsed_uri(
@base_url_components,
{**req, path: path, query: query}
)
headers, encoded = Increase::Internal::Util.encode_content(headers, body)
{
method: method,
url: Increase::Internal::Util.join_parsed_uri(@base_url, {**req, path: path, query: query}),
url: url,
headers: headers,
body: encoded,
max_retries: opts.fetch(:max_retries, @max_retries),
Expand Down Expand Up @@ -475,8 +501,7 @@ def request(req)
# @return [String]
def inspect
# rubocop:disable Layout/LineLength
base_url = Increase::Internal::Util.unparse_uri(@base_url)
"#<#{self.class.name}:0x#{object_id.to_s(16)} base_url=#{base_url} max_retries=#{@max_retries} timeout=#{@timeout}>"
"#<#{self.class.name}:0x#{object_id.to_s(16)} base_url=#{@base_url} max_retries=#{@max_retries} timeout=#{@timeout}>"
# rubocop:enable Layout/LineLength
end

Expand Down
71 changes: 46 additions & 25 deletions lib/increase/internal/type/base_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,39 @@ def dump(value, state:)
end
end

class << self
# @api private
#
# @param model [Increase::Internal::Type::BaseModel]
# @param convert [Boolean]
#
# @return [Hash{Symbol=>Object}]
def recursively_to_h(model, convert:)
rec = ->(x) do
case x
in Increase::Internal::Type::BaseModel
if convert
fields = x.class.known_fields
x.to_h.to_h do |key, val|
[key, rec.call(fields.key?(key) ? x.public_send(key) : val)]
rescue Increase::Errors::ConversionError
[key, rec.call(val)]
end
else
rec.call(x.to_h)
end
in Hash
x.transform_values(&rec)
in Array
x.map(&rec)
else
x
end
end
rec.call(model)
end
end

# @api public
#
# Returns the raw value associated with the given key, if found. Otherwise, nil is
Expand Down Expand Up @@ -349,6 +382,14 @@ def to_h = @data

alias_method :to_hash, :to_h

# @api public
#
# In addition to the behaviour of `#to_h`, this method will recursively call
# `#to_h` on nested models.
#
# @return [Hash{Symbol=>Object}]
def deep_to_h = self.class.recursively_to_h(@data, convert: false)

# @param keys [Array<Symbol>, nil]
#
# @return [Hash{Symbol=>Object}]
Expand All @@ -364,29 +405,6 @@ def deconstruct_keys(keys)
.to_h
end

class << self
# @api private
#
# @param model [Increase::Internal::Type::BaseModel]
#
# @return [Hash{Symbol=>Object}]
def walk(model)
walk = ->(x) do
case x
in Increase::Internal::Type::BaseModel
walk.call(x.to_h)
in Hash
x.transform_values(&walk)
in Array
x.map(&walk)
else
x
end
end
walk.call(model)
end
end

# @api public
#
# @param a [Object]
Expand Down Expand Up @@ -432,12 +450,15 @@ def inspect(depth: 0)
# @api public
#
# @return [String]
def to_s = self.class.walk(@data).to_s
def to_s = deep_to_h.to_s

# @api private
#
# @return [String]
def inspect = "#<#{self.class}:0x#{object_id.to_s(16)} #{self}>"
def inspect
converted = self.class.recursively_to_h(self, convert: true)
"#<#{self.class}:0x#{object_id.to_s(16)} #{converted}>"
end

define_sorbet_constant!(:KnownField) do
T.type_alias { {mode: T.nilable(Symbol), required: T::Boolean, nilable: T::Boolean} }
Expand Down
2 changes: 1 addition & 1 deletion lib/increase/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Increase
VERSION = "0.1.0.pre.alpha.22"
VERSION = "0.1.0.pre.alpha.23"
end
2 changes: 1 addition & 1 deletion rbi/increase/errors.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module Increase
request: NilClass,
response: NilClass,
message: T.nilable(String)
).returns(T.self_type)
).returns(T.attached_class)
end
def self.for(url:, status:, body:, request:, response:, message: nil)
end
Expand Down
21 changes: 21 additions & 0 deletions rbi/increase/internal/transport/base_client.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,27 @@ module Increase
end
end

sig { returns(URI::Generic) }
attr_reader :base_url

sig { returns(Float) }
attr_reader :timeout

sig { returns(Integer) }
attr_reader :max_retries

sig { returns(Float) }
attr_reader :initial_retry_delay

sig { returns(Float) }
attr_reader :max_retry_delay

sig { returns(T::Hash[String, String]) }
attr_reader :headers

sig { returns(T.nilable(String)) }
attr_reader :idempotency_header

# @api private
sig { returns(Increase::Internal::Transport::PooledNetRequester) }
attr_reader :requester
Expand Down
29 changes: 18 additions & 11 deletions rbi/increase/internal/type/base_model.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ module Increase
end
end

class << self
# @api private
sig do
params(
model: Increase::Internal::Type::BaseModel,
convert: T::Boolean
).returns(Increase::Internal::AnyHash)
end
def recursively_to_h(model, convert:)
end
end

# Returns the raw value associated with the given key, if found. Otherwise, nil is
# returned.
#
Expand Down Expand Up @@ -233,6 +245,12 @@ module Increase
def to_hash
end

# In addition to the behaviour of `#to_h`, this method will recursively call
# `#to_h` on nested models.
sig { overridable.returns(Increase::Internal::AnyHash) }
def deep_to_h
end

sig do
params(keys: T.nilable(T::Array[Symbol])).returns(
Increase::Internal::AnyHash
Expand All @@ -241,17 +259,6 @@ module Increase
def deconstruct_keys(keys)
end

class << self
# @api private
sig do
params(model: Increase::Internal::Type::BaseModel).returns(
Increase::Internal::AnyHash
)
end
def walk(model)
end
end

sig { params(a: T.anything).returns(String) }
def to_json(*a)
end
Expand Down
Loading
Loading