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
The table of contents is too big for display.
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.2"
".": "0.1.0-alpha.3"
}
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

## 0.1.0-alpha.3 (2025-04-03)

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

### ⚠ BREAKING CHANGES

* bump min supported ruby version to 3.1 (oldest non-EOL) ([#10](https://github.com/Increase/increase-ruby/issues/10))
* remove top level type aliases to relocated classes ([#9](https://github.com/Increase/increase-ruby/issues/9))

### Features

* bump min supported ruby version to 3.1 (oldest non-EOL) ([#10](https://github.com/Increase/increase-ruby/issues/10)) ([6bdbf40](https://github.com/Increase/increase-ruby/commit/6bdbf40be7f88549fdac9c50958a876b8bc21319))
* remove top level type aliases to relocated classes ([#9](https://github.com/Increase/increase-ruby/issues/9)) ([21e1d7f](https://github.com/Increase/increase-ruby/commit/21e1d7f50eeca18069b3f32cb7f1872dfc3ca8f6))


### Bug Fixes

* pre-release version string should match ruby, not semver conventions ([#12](https://github.com/Increase/increase-ruby/issues/12)) ([fda09d8](https://github.com/Increase/increase-ruby/commit/fda09d8fb2b491f9b893c340ea20d2f1d3f3e21c))


### Chores

* demonstrate how to make undocumented requests in README ([#11](https://github.com/Increase/increase-ruby/issues/11)) ([3a4e543](https://github.com/Increase/increase-ruby/commit/3a4e543eeb9b6b72559e4c7193a54f27fe006f49))
* **internal:** version bump ([#6](https://github.com/Increase/increase-ruby/issues/6)) ([99ee517](https://github.com/Increase/increase-ruby/commit/99ee5170448bca36d7773f7a443c27a4028da439))
* move private classes into internal module ([#8](https://github.com/Increase/increase-ruby/issues/8)) ([13f35d4](https://github.com/Increase/increase-ruby/commit/13f35d46ee4677f7f034afd91c6a911ec71e1ae7))

## 0.1.0-alpha.2 (2025-04-02)

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

GEM
Expand Down
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Increase Ruby API library

The Increase Ruby library provides convenient access to the Increase REST API from any Ruby 3.0.0+ application.
The Increase Ruby library provides convenient access to the Increase REST API from any Ruby 3.1.0+ application.

## Documentation

Expand All @@ -13,7 +13,7 @@ The underlying REST API documentation can be found on [increase.com](https://inc
To use this gem, install via Bundler by adding the following to your application's `Gemfile`:

```ruby
gem "increase", "~> 0.1.0.pre.alpha.1"
gem "increase", "~> 0.1.0.pre.alpha.2"
```

To fetch an initial copy of the gem:
Expand Down Expand Up @@ -134,7 +134,9 @@ increase.accounts.create(
)
```

## Sorbet Support
## LSP Support

### Sorbet

**This library emits an intentional warning under the [`tapioca` toolchain](https://github.com/Shopify/tapioca)**. This is normal, and does not impact functionality.

Expand All @@ -158,6 +160,31 @@ increase.accounts.create(**model)

## Advanced

### Making custom/undocumented requests

This library is typed for convenient access to the documented API.

If you need to access undocumented endpoints, params, or response properties, the library can still be used.

#### Undocumented request params

If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` under the `request_options:` parameter when making a requests as seen in examples above.

#### Undocumented endpoints

To make requests to undocumented endpoints, you can make requests using `client.request`. Options on the client will be respected (such as retries) when making this request.

```ruby
response =
client.request(
method: :post,
path: '/undocumented/endpoint',
query: {"dog": "woof"},
headers: {"useful-header": "interesting-value"},
body: {"he": "llo"},
)
```

### Concurrency & Connection Pooling

The `Increase::Client` instances are thread-safe, and should be re-used across multiple threads. By default, each `Client` have their own HTTP connection pool, with a maximum number of connections equal to thread count.
Expand All @@ -176,4 +203,4 @@ This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` typ

## Requirements

Ruby 3.0.0 or higher.
Ruby 3.1.0 or higher.
30 changes: 15 additions & 15 deletions lib/increase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@

# Package files.
require_relative "increase/version"
require_relative "increase/util"
require_relative "increase/type/converter"
require_relative "increase/type/unknown"
require_relative "increase/type/boolean_model"
require_relative "increase/type/enum"
require_relative "increase/type/union"
require_relative "increase/type/array_of"
require_relative "increase/type/hash_of"
require_relative "increase/type/base_model"
require_relative "increase/type/base_page"
require_relative "increase/type/request_parameters"
require_relative "increase/type"
require_relative "increase/internal/util"
require_relative "increase/internal/type/converter"
require_relative "increase/internal/type/unknown"
require_relative "increase/internal/type/boolean_model"
require_relative "increase/internal/type/enum"
require_relative "increase/internal/type/union"
require_relative "increase/internal/type/array_of"
require_relative "increase/internal/type/hash_of"
require_relative "increase/internal/type/base_model"
require_relative "increase/internal/type/base_page"
require_relative "increase/internal/type/request_parameters"
require_relative "increase/internal"
require_relative "increase/request_options"
require_relative "increase/errors"
require_relative "increase/transport/base_client"
require_relative "increase/transport/pooled_net_requester"
require_relative "increase/internal/transport/base_client"
require_relative "increase/internal/transport/pooled_net_requester"
require_relative "increase/client"
require_relative "increase/page"
require_relative "increase/internal/page"
require_relative "increase/models/account"
require_relative "increase/models/account_balance_params"
require_relative "increase/models/account_close_params"
Expand Down
2 changes: 1 addition & 1 deletion lib/increase/client.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Increase
class Client < Increase::Transport::BaseClient
class Client < Increase::Internal::Transport::BaseClient
# Default max number of retries to attempt after a failed retryable request.
DEFAULT_MAX_RETRIES = 2

Expand Down
52 changes: 1 addition & 51 deletions lib/increase/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class APIStatusError < Increase::Errors::APIError
#
# @return [Increase::Errors::APIStatusError]
def self.for(url:, status:, body:, request:, response:, message: nil)
key = Increase::Util.dig(body, :type)
key = Increase::Internal::Util.dig(body, :type)
kwargs = {
url: url,
status: status,
Expand Down Expand Up @@ -256,54 +256,4 @@ class InternalServerError < Increase::Errors::APIStatusError
TYPE = "internal_server_error"
end
end

Error = Increase::Errors::Error

ConversionError = Increase::Errors::ConversionError

APIError = Increase::Errors::APIError

APIStatusError = Increase::Errors::APIStatusError

APIConnectionError = Increase::Errors::APIConnectionError

APITimeoutError = Increase::Errors::APITimeoutError

BadRequestError = Increase::Errors::BadRequestError

AuthenticationError = Increase::Errors::AuthenticationError

PermissionDeniedError = Increase::Errors::PermissionDeniedError

NotFoundError = Increase::Errors::NotFoundError

ConflictError = Increase::Errors::ConflictError

UnprocessableEntityError = Increase::Errors::UnprocessableEntityError

RateLimitError = Increase::Errors::RateLimitError

InvalidParametersError = Increase::Errors::InvalidParametersError

MalformedRequestError = Increase::Errors::MalformedRequestError

InvalidAPIKeyError = Increase::Errors::InvalidAPIKeyError

EnvironmentMismatchError = Increase::Errors::EnvironmentMismatchError

InsufficientPermissionsError = Increase::Errors::InsufficientPermissionsError

PrivateFeatureError = Increase::Errors::PrivateFeatureError

APIMethodNotFoundError = Increase::Errors::APIMethodNotFoundError

ObjectNotFoundError = Increase::Errors::ObjectNotFoundError

IdempotencyKeyAlreadyUsedError = Increase::Errors::IdempotencyKeyAlreadyUsedError

InvalidOperationError = Increase::Errors::InvalidOperationError

RateLimitedError = Increase::Errors::RateLimitedError

InternalServerError = Increase::Errors::InternalServerError
end
8 changes: 8 additions & 0 deletions lib/increase/internal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

module Increase
# @api private
module Internal
OMIT = Object.new.freeze
end
end
82 changes: 82 additions & 0 deletions lib/increase/internal/page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# frozen_string_literal: true

module Increase
module Internal
# @example
# if page.has_next?
# page = page.next_page
# end
#
# @example
# page.auto_paging_each do |account|
# puts(account)
# end
class Page
include Increase::Internal::Type::BasePage

# @return [Array<Object>, nil]
attr_accessor :data

# @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?
end

# @raise [Increase::HTTP::Error]
# @return [Increase::Internal::Page]
def next_page
unless next_page?
message = "No more pages available. Please check #next_page? before calling ##{__method__}"
raise RuntimeError.new(message)
end

req = Increase::Internal::Util.deep_merge(@req, {query: {cursor: next_cursor}})
@client.request(req)
end

# @param blk [Proc]
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) }
break unless page.next_page?
page = page.next_page
end
end

# @return [String]
def inspect
"#<#{self.class}:0x#{object_id.to_s(16)} data=#{data.inspect} next_cursor=#{next_cursor.inspect}>"
end
end
end
end
Loading
Loading