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.9"
".": "0.1.0-alpha.10"
}
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ Style/SafeNavigation:
Style/SignalException:
Exclude:
- Rakefile
- "**/*.rake"

# We use these sparingly, where we anticipate future branches for the
# inner conditional.
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: 199
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/increase%2Fincrease-55c174581a08cabdf3fcf2fc66d480d497c5f77ab8f0f5e776cc7113b4960037.yml
openapi_spec_hash: 8f70d88f00c9c15ebd8e9049e9f65063
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/increase%2Fincrease-1044f3fb430b9b4019ec3adeaa8b37e6615264fddb273a48b1d9ddd7c2b7b854.yml
openapi_spec_hash: c2526b64321711688cada903e7b4397d
config_hash: 20a463ecd33bd32b7b9bc6f4990907ac
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Changelog

## 0.1.0-alpha.10 (2025-04-15)

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

### Features

* **api:** api update ([f6c5568](https://github.com/Increase/increase-ruby/commit/f6c5568f67ff3b44fa3c27569cafbb99e48cc71d))


### Chores

* **internal:** always run post-processing when formatting when syntax_tree ([0ee8912](https://github.com/Increase/increase-ruby/commit/0ee8912f81636d5f74a736e4c8d1707b204e395a))
* **internal:** loosen internal type restrictions ([56e169c](https://github.com/Increase/increase-ruby/commit/56e169c9fcc2a898d8671e591dec0c606f4ce24c))
* **internal:** minor touch ups on sdk internals ([ed29ff6](https://github.com/Increase/increase-ruby/commit/ed29ff6868a89b11bea12c07b6cd834b6769cb41))
* **internal:** mostly README touch ups ([23519d3](https://github.com/Increase/increase-ruby/commit/23519d3197bf59ba73812fda30d28101a6c5f40f))
* make internal types pretty print ([18c33c5](https://github.com/Increase/increase-ruby/commit/18c33c5f6fe4bb1a0e0fac9083dac8b1f063fdd1))


### Documentation

* update documentation links to be more uniform ([b1f42d9](https://github.com/Increase/increase-ruby/commit/b1f42d9ef89f3a8d3db9f97e9267690e49826d2e))

## 0.1.0-alpha.9 (2025-04-12)

Full Changelog: [v0.1.0-alpha.8...v0.1.0-alpha.9](https://github.com/Increase/increase-ruby/compare/v0.1.0-alpha.8...v0.1.0-alpha.9)
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.9)
increase (0.1.0.pre.alpha.10)
connection_pool

GEM
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ The Increase Ruby library provides convenient access to the Increase REST API fr

## Documentation

Documentation for released of this gem can be found [on RubyDoc](https://gemdocs.org/gems/increase).
Documentation for releases of this gem can be found [on RubyDoc](https://gemdocs.org/gems/increase).

The underlying REST API documentation can be found on [increase.com](https://increase.com/documentation).
The REST API documentation can be found on [increase.com](https://increase.com/documentation).

## Installation

Expand All @@ -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.9"
gem "increase", "~> 0.1.0.pre.alpha.10"
```

<!-- x-release-please-end -->
Expand Down
9 changes: 8 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,19 @@ multitask(:syntax_tree) do
# 2. at label `l1`, join previously annotated line with `class | module` information.
pst = sed + [subst, "--"]

success = false

# transform class aliases to type aliases, which syntax tree has no trouble with
sh("#{find.shelljoin} | #{pre.shelljoin}")
# run syntax tree to format `*.rbs` files
sh("#{find.shelljoin} | #{fmt.shelljoin}")
sh("#{find.shelljoin} | #{fmt.shelljoin}") do
success = _1
end
# transform type aliases back to class aliases
sh("#{find.shelljoin} | #{pst.shelljoin}")

# always run post-processing to remove comment marker
fail unless success
end

multitask(format: [:ruboformat, :syntax_tree])
Expand Down
6 changes: 5 additions & 1 deletion lib/increase/internal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
module Increase
# @api private
module Internal
OMIT = Object.new.freeze
OMIT =
Object.new.tap do
_1.define_singleton_method(:inspect) { "#<#{Increase::Internal}::OMIT>" }
end
.freeze
end
end
50 changes: 25 additions & 25 deletions lib/increase/internal/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,6 @@ class Page
# @return [String, nil]
attr_accessor :next_cursor

# @api private
#
# @param client [Increase::Internal::Transport::BaseClient]
# @param req [Hash{Symbol=>Object}]
# @param headers [Hash{String=>String}, Net::HTTPHeader]
# @param page_data [Hash{Symbol=>Object}]
def initialize(client:, req:, headers:, page_data:)
super
model = req.fetch(:model)

case page_data
in {data: Array | nil => data}
@data = data&.map { Increase::Internal::Type::Converter.coerce(model, _1) }
else
end

case page_data
in {next_cursor: String | nil => next_cursor}
@next_cursor = next_cursor
else
end
end

# @return [Boolean]
def next_page?
!next_cursor.nil?
Expand All @@ -69,17 +46,40 @@ def auto_paging_each(&blk)
unless block_given?
raise ArgumentError.new("A block must be given to ##{__method__}")
end

page = self
loop do
page.data&.each { blk.call(_1) }
page.data&.each(&blk)

break unless page.next_page?
page = page.next_page
end
end

# @api private
#
# @param client [Increase::Internal::Transport::BaseClient]
# @param req [Hash{Symbol=>Object}]
# @param headers [Hash{String=>String}, Net::HTTPHeader]
# @param page_data [Hash{Symbol=>Object}]
def initialize(client:, req:, headers:, page_data:)
super

case page_data
in {data: Array | nil => data}
@data = data&.map { Increase::Internal::Type::Converter.coerce(@model, _1) }
else
end
@next_cursor = page_data[:next_cursor]
end

# @api private
#
# @return [String]
def inspect
"#<#{self.class}:0x#{object_id.to_s(16)} data=#{data.inspect} next_cursor=#{next_cursor.inspect}>"
model = Increase::Internal::Type::Converter.inspect(@model, depth: 1)

"#<#{self.class}[#{model}]:0x#{object_id.to_s(16)} next_cursor=#{next_cursor.inspect}>"
end
end
end
Expand Down
16 changes: 13 additions & 3 deletions lib/increase/internal/transport/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,23 @@ def follow_redirect(request, status:, response_headers:)
URI.join(url, response_headers["location"])
rescue ArgumentError
message = "Server responded with status #{status} but no valid location header."
raise Increase::Errors::APIConnectionError.new(url: url, message: message)
raise Increase::Errors::APIConnectionError.new(
url: url,
response: response_headers,
message: message
)
end

request = {**request, url: location}

case [url.scheme, location.scheme]
in ["https", "http"]
message = "Tried to redirect to a insecure URL"
raise Increase::Errors::APIConnectionError.new(url: url, message: message)
raise Increase::Errors::APIConnectionError.new(
url: url,
response: response_headers,
message: message
)
else
nil
end
Expand Down Expand Up @@ -350,7 +358,7 @@ def initialize(
self.class.reap_connection!(status, stream: stream)

message = "Failed to complete the request within #{self.class::MAX_REDIRECTS} redirects."
raise Increase::Errors::APIConnectionError.new(url: url, message: message)
raise Increase::Errors::APIConnectionError.new(url: url, response: response, message: message)
in 300..399
self.class.reap_connection!(status, stream: stream)

Expand Down Expand Up @@ -460,6 +468,8 @@ def request(req)
end
end

# @api private
#
# @return [String]
def inspect
# rubocop:disable Layout/LineLength
Expand Down
19 changes: 17 additions & 2 deletions lib/increase/internal/type/array_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module Type
class ArrayOf
include Increase::Internal::Type::Converter

private_class_method :new

# @overload [](type_info, spec = {})
#
# @param type_info [Hash{Symbol=>Object}, Proc, Increase::Internal::Type::Converter, Class]
#
# @param spec [Hash{Symbol=>Object}] .
Expand All @@ -24,7 +28,7 @@ class ArrayOf
# @option spec [Proc] :union
#
# @option spec [Boolean] :"nil?"
def self.[](type_info, spec = {}) = new(type_info, spec)
def self.[](...) = new(...)

# @param other [Object]
#
Expand Down Expand Up @@ -120,7 +124,18 @@ def dump(value, state:)
# @option spec [Boolean] :"nil?"
def initialize(type_info, spec = {})
@item_type_fn = Increase::Internal::Type::Converter.type_info(type_info || spec)
@nilable = spec[:nil?]
@nilable = spec.fetch(:nil?, false)
end

# @api private
#
# @param depth [Integer]
#
# @return [String]
def inspect(depth: 0)
items = Increase::Internal::Type::Converter.inspect(item_type, depth: depth.succ)

"#{self.class}[#{[items, nilable? ? 'nil' : nil].compact.join(' | ')}]"
end
end
end
Expand Down
38 changes: 33 additions & 5 deletions lib/increase/internal/type/base_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def fields

setter = "#{name_sym}="
api_name = info.fetch(:api_name, name_sym)
nilable = info[:nil?]
nilable = info.fetch(:nil?, false)
const = if required && !nilable
info.fetch(
:const,
Expand Down Expand Up @@ -368,14 +368,42 @@ def initialize(data = {})
end
end

class << self
# @api private
#
# @param depth [Integer]
#
# @return [String]
def inspect(depth: 0)
return super() if depth.positive?

depth = depth.succ
deferred = fields.transform_values do |field|
type, required, nilable = field.fetch_values(:type, :required, :nilable)
-> do
[
Increase::Internal::Type::Converter.inspect(type, depth: depth),
!required || nilable ? "nil" : nil
].compact.join(" | ")
end
.tap { _1.define_singleton_method(:inspect) { call } }
end

"#{name}[#{deferred.inspect}]"
end
end

# @api private
#
# @return [String]
def inspect
rows = self.class.known_fields.keys.map do
"#{_1}=#{@data.key?(_1) ? public_send(_1) : ''}"
rows = @data.map do
"#{_1}=#{self.class.known_fields.key?(_1) ? public_send(_1).inspect : ''}"
rescue Increase::Errors::ConversionError
"#{_1}=#{@data.fetch(_1)}"
"#{_1}=#{_2.inspect}"
end
"#<#{self.class.name}:0x#{object_id.to_s(16)} #{rows.join(' ')}>"

"#<#{self.class}:0x#{object_id.to_s(16)} #{rows.join(' ')}>"
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/increase/internal/type/base_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def to_enum = super(:auto_paging_each)
def initialize(client:, req:, headers:, page_data:)
@client = client
@req = req
@model = req.fetch(:model)
super()
end

Expand Down
2 changes: 2 additions & 0 deletions lib/increase/internal/type/boolean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module Type
class Boolean
extend Increase::Internal::Type::Converter

private_class_method :new

# @param other [Object]
#
# @return [Boolean]
Expand Down
24 changes: 24 additions & 0 deletions lib/increase/internal/type/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ def dump(value, state:)
end
end

# @api private
#
# @param depth [Integer]
#
# @return [String]
def inspect(depth: 0)
super()
end

# rubocop:enable Lint/UnusedMethodArgument

class << self
Expand Down Expand Up @@ -240,6 +249,21 @@ def dump(target, value, state: {can_retry: true})
Increase::Internal::Type::Unknown.dump(value, state: state)
end
end

# @api private
#
# @param target [Object]
# @param depth [Integer]
#
# @return [String]
def inspect(target, depth:)
case target
in Increase::Internal::Type::Converter
target.inspect(depth: depth.succ)
else
target.inspect
end
end
end
end
end
Expand Down
Loading