From 730b14968b92319ce539148582bfe9e968fe07f3 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 12 May 2025 20:25:55 +0000 Subject: [PATCH 1/6] chore: fix misc linting / minor issues --- .rubocop.yml | 7 ++++++- Rakefile | 2 +- lib/increase.rb | 2 ++ lib/increase/errors.rb | 2 +- rbi/increase/errors.rbi | 2 +- sig/increase/internal/type/array_of.rbs | 2 +- sig/increase/internal/type/base_model.rbs | 6 +++--- sig/increase/internal/type/base_page.rbs | 2 +- sig/increase/internal/type/hash_of.rbs | 2 +- 9 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 59202214a..2237fa87f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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: @@ -112,6 +112,8 @@ Metrics/AbcSize: Metrics/BlockLength: AllowedPatterns: - assert_pattern + - type_alias + - define_sorbet_constant! Exclude: - "**/*.rbi" @@ -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 diff --git a/Rakefile b/Rakefile index 8361a8b91..fe1523b8b 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/lib/increase.rb b/lib/increase.rb index e39a332ea..f072d69e2 100644 --- a/lib/increase.rb +++ b/lib/increase.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true # Standard libraries. +# rubocop:disable Lint/RedundantRequireStatement require "English" require "cgi" require "date" @@ -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. diff --git a/lib/increase/errors.rb b/lib/increase/errors.rb index 3609aa4e0..8e865ff88 100644 --- a/lib/increase/errors.rb +++ b/lib/increase/errors.rb @@ -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 = { diff --git a/rbi/increase/errors.rbi b/rbi/increase/errors.rbi index 47e40e62e..3dd72be0f 100644 --- a/rbi/increase/errors.rbi +++ b/rbi/increase/errors.rbi @@ -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 diff --git a/sig/increase/internal/type/array_of.rbs b/sig/increase/internal/type/array_of.rbs index f73fc2453..7e41c01f1 100644 --- a/sig/increase/internal/type/array_of.rbs +++ b/sig/increase/internal/type/array_of.rbs @@ -9,7 +9,7 @@ module Increase | ^-> Increase::Internal::Type::Converter::input | Increase::Internal::Type::Converter::input type_info, ?::Hash[Symbol, top] spec - ) -> self + ) -> instance def ===: (top other) -> bool diff --git a/sig/increase/internal/type/base_model.rbs b/sig/increase/internal/type/base_model.rbs index cb08e4e90..cf143392a 100644 --- a/sig/increase/internal/type/base_model.rbs +++ b/sig/increase/internal/type/base_model.rbs @@ -61,10 +61,10 @@ module Increase def self.coerce: ( Increase::Internal::Type::BaseModel | ::Hash[top, top] | top value, state: Increase::Internal::Type::Converter::coerce_state - ) -> (self | top) + ) -> (instance | top) def self.dump: ( - self | top value, + instance | top value, state: Increase::Internal::Type::Converter::dump_state ) -> (::Hash[top, top] | top) @@ -84,7 +84,7 @@ module Increase def to_yaml: (*top a) -> String - def initialize: (?::Hash[Symbol, top] | self data) -> void + def initialize: (?::Hash[Symbol, top] | instance data) -> void def self.inspect: (?depth: Integer) -> String diff --git a/sig/increase/internal/type/base_page.rbs b/sig/increase/internal/type/base_page.rbs index 962d8f5e8..a92aa296d 100644 --- a/sig/increase/internal/type/base_page.rbs +++ b/sig/increase/internal/type/base_page.rbs @@ -4,7 +4,7 @@ module Increase module BasePage[Elem] def next_page?: -> bool - def next_page: -> self + def next_page: -> instance def auto_paging_each: { (Elem arg0) -> void } -> void diff --git a/sig/increase/internal/type/hash_of.rbs b/sig/increase/internal/type/hash_of.rbs index 2e97559c3..870585e14 100644 --- a/sig/increase/internal/type/hash_of.rbs +++ b/sig/increase/internal/type/hash_of.rbs @@ -9,7 +9,7 @@ module Increase | ^-> Increase::Internal::Type::Converter::input | Increase::Internal::Type::Converter::input type_info, ?::Hash[Symbol, top] spec - ) -> self + ) -> instance def ===: (top other) -> bool From bc9b4f3e3063d52a4454084832f3b12a052a4af8 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 12 May 2025 21:24:54 +0000 Subject: [PATCH 2/6] feat: expose recursive `#to_h` conversion --- lib/increase/internal/type/base_model.rb | 71 +++++++++++++++-------- rbi/increase/internal/type/base_model.rbi | 29 +++++---- sig/increase/internal/type/base_model.rbs | 11 ++-- 3 files changed, 71 insertions(+), 40 deletions(-) diff --git a/lib/increase/internal/type/base_model.rb b/lib/increase/internal/type/base_model.rb index 65e6c18ad..6da1afb1b 100644 --- a/lib/increase/internal/type/base_model.rb +++ b/lib/increase/internal/type/base_model.rb @@ -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 @@ -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, nil] # # @return [Hash{Symbol=>Object}] @@ -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] @@ -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} } diff --git a/rbi/increase/internal/type/base_model.rbi b/rbi/increase/internal/type/base_model.rbi index dcaf5cd51..2bd6dd6d7 100644 --- a/rbi/increase/internal/type/base_model.rbi +++ b/rbi/increase/internal/type/base_model.rbi @@ -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. # @@ -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 @@ -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 diff --git a/sig/increase/internal/type/base_model.rbs b/sig/increase/internal/type/base_model.rbs index cf143392a..1ef9c1d88 100644 --- a/sig/increase/internal/type/base_model.rbs +++ b/sig/increase/internal/type/base_model.rbs @@ -68,17 +68,20 @@ module Increase state: Increase::Internal::Type::Converter::dump_state ) -> (::Hash[top, top] | top) + def self.recursively_to_h: ( + Increase::Internal::Type::BaseModel model, + convert: bool + ) -> ::Hash[Symbol, top] + def []: (Symbol key) -> top? def to_h: -> ::Hash[Symbol, top] alias to_hash to_h - def deconstruct_keys: (::Array[Symbol]? keys) -> ::Hash[Symbol, top] + def deep_to_h: -> ::Hash[Symbol, top] - def self.walk: ( - Increase::Internal::Type::BaseModel model - ) -> ::Hash[Symbol, top] + def deconstruct_keys: (::Array[Symbol]? keys) -> ::Hash[Symbol, top] def to_json: (*top a) -> String From 22199bc7e21f1c545662ae0da9934598f8c190e5 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 12 May 2025 22:20:07 +0000 Subject: [PATCH 3/6] feat: expose base client options as read only attributes --- .../internal/transport/base_client.rb | 35 ++++++++++++++++--- .../internal/transport/base_client.rbi | 21 +++++++++++ .../internal/transport/base_client.rbs | 14 ++++++++ 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/lib/increase/internal/transport/base_client.rb b/lib/increase/internal/transport/base_client.rb index 3c8099c13..3489b9c2c 100644 --- a/lib/increase/internal/transport/base_client.rb +++ b/lib/increase/internal/transport/base_client.rb @@ -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 @@ -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 @@ -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), @@ -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 diff --git a/rbi/increase/internal/transport/base_client.rbi b/rbi/increase/internal/transport/base_client.rbi index f5047782b..26a61b880 100644 --- a/rbi/increase/internal/transport/base_client.rbi +++ b/rbi/increase/internal/transport/base_client.rbi @@ -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 diff --git a/sig/increase/internal/transport/base_client.rbs b/sig/increase/internal/transport/base_client.rbs index e285abac6..b1682281e 100644 --- a/sig/increase/internal/transport/base_client.rbs +++ b/sig/increase/internal/transport/base_client.rbs @@ -56,6 +56,20 @@ module Increase stream: Enumerable[String]? ) -> void + attr_reader base_url: URI::Generic + + attr_reader timeout: Float + + attr_reader max_retries: Integer + + attr_reader initial_retry_delay: Float + + attr_reader max_retry_delay: Float + + attr_reader headers: ::Hash[String, String] + + attr_reader idempotency_header: String? + # @api private attr_reader requester: Increase::Internal::Transport::PooledNetRequester From ffe91d7b32a5d08009c2deb1d2774694b442677f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 12 May 2025 22:28:26 +0000 Subject: [PATCH 4/6] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index b5c83ac18..47691537a 100644 --- a/.stats.yml +++ b/.stats.yml @@ -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 From 4323fb58792ad85fe9109898bbf47f578cb3f43a Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 13 May 2025 14:20:01 +0000 Subject: [PATCH 5/6] fix(internal): update gemspec name --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index fe1523b8b..9e3c5de7b 100644 --- a/Rakefile +++ b/Rakefile @@ -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 From 32ec1713062fd269622dfb27946755b1f4bf587c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 13 May 2025 14:21:21 +0000 Subject: [PATCH 6/6] release: 0.1.0-alpha.23 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 19 +++++++++++++++++++ Gemfile.lock | 2 +- README.md | 2 +- lib/increase/version.rb | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index aa8487597..1c0bb8852 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-alpha.22" + ".": "0.1.0-alpha.23" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 7de45210f..313c804e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Gemfile.lock b/Gemfile.lock index 975bcfc4c..5746bb211 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/README.md b/README.md index cf16a5245..af287743c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ To use this gem, install via Bundler by adding the following to your application ```ruby -gem "increase", "~> 0.1.0.pre.alpha.22" +gem "increase", "~> 0.1.0.pre.alpha.23" ``` diff --git a/lib/increase/version.rb b/lib/increase/version.rb index dd27ba10a..dc0e0a205 100644 --- a/lib/increase/version.rb +++ b/lib/increase/version.rb @@ -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