Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
lint:
name: lint
runs-on: ubuntu-latest


steps:
- uses: actions/checkout@v4
- name: Set up Ruby
Expand All @@ -29,7 +27,6 @@ jobs:
test:
name: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
Expand Down
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.8"
".": "0.1.0-alpha.9"
}
4 changes: 2 additions & 2 deletions .solargraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include:
- 'Rakefile'
- 'examples/**/*.rb'
- 'lib/**/*.rb'
- 'test/finch-api/resource_namespaces.rb'
- 'test/finch-api/test_helper.rb'
- 'test/finch_api/resource_namespaces.rb'
- 'test/finch_api/test_helper.rb'
exclude:
- 'rbi/**/*'
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 46
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-14d375aab89e6b212fe459805a42d6ea7d7da8eae2037ae710a187d06911be1d.yml
openapi_spec_hash: 08b86ecbec3323717d48e4aaee48ed54
config_hash: ce10384813f68ba3fed61c7b601b396b
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/finch%2Ffinch-bf858f37d7ab420841ddc6329dad8c46377308b6a5c8e935908011d0f9845e22.yml
openapi_spec_hash: 2523952a32436e3c7fd3b55508c2e7ee
config_hash: 53778a0b839c4f6ad34fbba051f5e8a6
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Changelog

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

Full Changelog: [v0.1.0-alpha.8...v0.1.0-alpha.9](https://github.com/Finch-API/finch-api-ruby/compare/v0.1.0-alpha.8...v0.1.0-alpha.9)

### Features

* **api:** add models for hrs benefits individuals async responses ([7492eec](https://github.com/Finch-API/finch-api-ruby/commit/7492eec6cc2c2b3434126b3f6e79291d5badebaa))
* **api:** api update ([#136](https://github.com/Finch-API/finch-api-ruby/issues/136)) ([e1bd1b5](https://github.com/Finch-API/finch-api-ruby/commit/e1bd1b517f2ef5acba32de6490c581cde6b5a88f))
* **api:** benefits mutation API endpoints (create benefit, update benefit, enroll individual, unenroll individual) now properly return async response types ([#139](https://github.com/Finch-API/finch-api-ruby/issues/139)) ([f6b269c](https://github.com/Finch-API/finch-api-ruby/commit/f6b269cdc764e317bf5c3622bac66d625222d1db))
* use Pathname alongside raw IO handles for file uploads ([#132](https://github.com/Finch-API/finch-api-ruby/issues/132)) ([ca140ed](https://github.com/Finch-API/finch-api-ruby/commit/ca140ed7e0ba64dab0532c07e54c1fd3c74ee887))


### Bug Fixes

* **internal:** update release-please to use ruby strategy for README.md ([#137](https://github.com/Finch-API/finch-api-ruby/issues/137)) ([8a2f9b4](https://github.com/Finch-API/finch-api-ruby/commit/8a2f9b4b2ee02513530d25a86eff44ee66b6c47d))
* raise connection error for errors that result from HTTP transports ([#133](https://github.com/Finch-API/finch-api-ruby/issues/133)) ([908b8ba](https://github.com/Finch-API/finch-api-ruby/commit/908b8bab442d72e3061461b66b130f852e09949d))


### Chores

* add README docs for using solargraph when installing gem from git ([#131](https://github.com/Finch-API/finch-api-ruby/issues/131)) ([7bec93f](https://github.com/Finch-API/finch-api-ruby/commit/7bec93f44da855671b5c1be8ca11cb57f30d5cc7))
* ensure readme.md is bumped when release please updates versions ([#135](https://github.com/Finch-API/finch-api-ruby/issues/135)) ([52953bd](https://github.com/Finch-API/finch-api-ruby/commit/52953bd7d499b595d8632c67db0a2c4ec418be7d))
* fix lsp configuration file for local development ([ff3d47c](https://github.com/Finch-API/finch-api-ruby/commit/ff3d47c157613223fdafd0f953f5ab72f647a30a))
* fix typo ([48e4f10](https://github.com/Finch-API/finch-api-ruby/commit/48e4f106285126601f9b60296d589f82b775e19b))
* fix typo ([#140](https://github.com/Finch-API/finch-api-ruby/issues/140)) ([176f00b](https://github.com/Finch-API/finch-api-ruby/commit/176f00bd5ce8b85cec38d381b0c8c68a144060cf))
* **internal:** expand CI branch coverage ([#138](https://github.com/Finch-API/finch-api-ruby/issues/138)) ([e699355](https://github.com/Finch-API/finch-api-ruby/commit/e699355e6db0fbf1853fdb7d9769eec8f6043fca))
* **internal:** reduce CI branch coverage ([ff0aa81](https://github.com/Finch-API/finch-api-ruby/commit/ff0aa81561a53763a8ac6fdf373969991b193580))
* **internal:** version bump ([508a2f6](https://github.com/Finch-API/finch-api-ruby/commit/508a2f6cc90a990e2ef220e9dcf41afde861f464))
* loosen const and integer coercion rules ([#134](https://github.com/Finch-API/finch-api-ruby/issues/134)) ([954fa16](https://github.com/Finch-API/finch-api-ruby/commit/954fa162fb447df7392082c5b7676f205701b18a))

## 0.1.0-alpha.8 (2025-04-08)

Full Changelog: [v0.1.0-alpha.7...v0.1.0-alpha.8](https://github.com/Finch-API/finch-api-ruby/compare/v0.1.0-alpha.7...v0.1.0-alpha.8)
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:
finch-api (0.1.0.pre.alpha.7)
finch-api (0.1.0.pre.alpha.8)
connection_pool

GEM
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ To use this gem, install via Bundler by adding the following to your application
<!-- x-release-please-start-version -->

```ruby
gem "finch-api", "~> 0.1.0.pre.alpha.7"
gem "finch-api", "~> 0.1.0.pre.alpha.9"
```

<!-- x-release-please-end -->
Expand Down Expand Up @@ -140,6 +140,13 @@ After Solargraph is installed, **you must populate its index** either via the pr
bundle exec solargraph gems
```

Note: if you had installed the gem either using a `git:` or `github:` URL, or had vendored the gem using bundler, you will need to set up your [`.solargraph.yml`](https://solargraph.org/guides/configuration) to include the path to the gem's `lib` directory.

```yaml
include:
- 'vendor/bundle/ruby/*/gems/finch-api-*/lib/**/*.rb'
```

Otherwise Solargraph will not be able to provide type information or auto-completion for any non-indexed libraries.

### Sorbet
Expand Down
6 changes: 4 additions & 2 deletions lib/finch_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
require_relative "finch_api/internal/type/converter"
require_relative "finch_api/internal/type/unknown"
require_relative "finch_api/internal/type/boolean"
require_relative "finch_api/internal/type/io_like"
require_relative "finch_api/internal/type/enum"
require_relative "finch_api/internal/type/union"
require_relative "finch_api/internal/type/array_of"
Expand Down Expand Up @@ -79,15 +80,16 @@
require_relative "finch_api/models/hris/benefit_frequency"
require_relative "finch_api/models/hris/benefit_list_params"
require_relative "finch_api/models/hris/benefit_list_supported_benefits_params"
require_relative "finch_api/models/hris/benefit_list_supported_benefits_response"
require_relative "finch_api/models/hris/benefit_retrieve_params"
require_relative "finch_api/models/hris/benefits/enrolled_individual"
require_relative "finch_api/models/hris/benefits/enrolled_individual_benefit_response"
require_relative "finch_api/models/hris/benefits/individual_benefit"
require_relative "finch_api/models/hris/benefits/individual_enrolled_ids_params"
require_relative "finch_api/models/hris/benefits/individual_enrolled_ids_response"
require_relative "finch_api/models/hris/benefits/individual_enroll_many_params"
require_relative "finch_api/models/hris/benefits/individual_retrieve_many_benefits_params"
require_relative "finch_api/models/hris/benefits/individual_unenroll_many_params"
require_relative "finch_api/models/hris/benefits/unenrolled_individual"
require_relative "finch_api/models/hris/benefits/unenrolled_individual_benefit_response"
require_relative "finch_api/models/hris/benefits_support"
require_relative "finch_api/models/hris/benefit_type"
require_relative "finch_api/models/hris/benefit_update_params"
Expand Down
2 changes: 1 addition & 1 deletion lib/finch_api/internal/transport/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def initialize(
in (400..) | FinchAPI::Errors::APIConnectionError
self.class.reap_connection!(status, stream: stream)

delay = retry_delay(response, retry_count: retry_count)
delay = retry_delay(response || {}, retry_count: retry_count)
sleep(delay)

send_request(
Expand Down
19 changes: 14 additions & 5 deletions lib/finch_api/internal/transport/pooled_net_requester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def calibrate_socket_timeout(conn, deadline)
# @param blk [Proc]
#
# @yieldparam [String]
# @return [Net::HTTPGenericRequest]
# @return [Array(Net::HTTPGenericRequest, Proc)]
def build_request(request, &blk)
method, url, headers, body = request.fetch_values(:method, :url, :headers, :body)
req = Net::HTTPGenericRequest.new(
Expand All @@ -75,12 +75,12 @@ def build_request(request, &blk)
in StringIO
req["content-length"] ||= body.size.to_s unless req["transfer-encoding"]
req.body_stream = FinchAPI::Internal::Util::ReadIOAdapter.new(body, &blk)
in IO | Enumerator
in Pathname | IO | Enumerator
req["transfer-encoding"] ||= "chunked" unless req["content-length"]
req.body_stream = FinchAPI::Internal::Util::ReadIOAdapter.new(body, &blk)
end

req
[req, req.body_stream&.method(:close)]
end
end

Expand Down Expand Up @@ -123,13 +123,17 @@ def build_request(request, &blk)
def execute(request)
url, deadline = request.fetch_values(:url, :deadline)

req = nil
eof = false
finished = false
closing = nil

# rubocop:disable Metrics/BlockLength
enum = Enumerator.new do |y|
with_pool(url, deadline: deadline) do |conn|
next if finished

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

Expand All @@ -154,8 +158,11 @@ def execute(request)
end
end
rescue Timeout::Error
raise FinchAPI::Errors::APITimeoutError
raise FinchAPI::Errors::APITimeoutError.new(url: url, request: req)
rescue StandardError
raise FinchAPI::Errors::APIConnectionError.new(url: url, request: req)
end
# rubocop:enable Metrics/BlockLength

conn, _, response = enum.next
body = FinchAPI::Internal::Util.fused_enum(enum, external: true) do
Expand All @@ -165,7 +172,9 @@ def execute(request)
rescue StopIteration
nil
end
ensure
conn.finish if !eof && conn&.started?
closing&.call
end
[Integer(response.code), response, (response.body = body)]
end
Expand Down
8 changes: 6 additions & 2 deletions lib/finch_api/internal/type/array_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ def coerce(value, state:)
#
# @param value [Array<Object>, Object]
#
# @param state [Hash{Symbol=>Object}] .
#
# @option state [Boolean] :can_retry
#
# @return [Array<Object>, Object]
def dump(value)
def dump(value, state:)
target = item_type
if value.is_a?(Array)
value.map do
FinchAPI::Internal::Type::Converter.dump(target, _1)
FinchAPI::Internal::Type::Converter.dump(target, _1, state: state)
end
else
super
Expand Down
14 changes: 9 additions & 5 deletions lib/finch_api/internal/type/base_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,12 @@ def coerce(value, state:)
#
# @param value [FinchAPI::Internal::Type::BaseModel, Object]
#
# @param state [Hash{Symbol=>Object}] .
#
# @option state [Boolean] :can_retry
#
# @return [Hash{Object=>Object}, Object]
def dump(value)
def dump(value, state:)
unless (coerced = FinchAPI::Internal::Util.coerce_hash(value)).is_a?(Hash)
return super
end
Expand All @@ -271,15 +275,15 @@ def dump(value)
name = key.is_a?(String) ? key.to_sym : key
case (field = known_fields[name])
in nil
acc.store(name, super(val))
acc.store(name, super(val, state: state))
else
api_name, mode, type_fn = field.fetch_values(:api_name, :mode, :type_fn)
case mode
in :coerce
next
else
target = type_fn.call
acc.store(api_name, FinchAPI::Internal::Type::Converter.dump(target, val))
acc.store(api_name, FinchAPI::Internal::Type::Converter.dump(target, val, state: state))
end
end
end
Expand Down Expand Up @@ -344,12 +348,12 @@ def deconstruct_keys(keys)
# @param a [Object]
#
# @return [String]
def to_json(*a) = self.class.dump(self).to_json(*a)
def to_json(*a) = FinchAPI::Internal::Type::Converter.dump(self.class, self).to_json(*a)

# @param a [Object]
#
# @return [String]
def to_yaml(*a) = self.class.dump(self).to_yaml(*a)
def to_yaml(*a) = FinchAPI::Internal::Type::Converter.dump(self.class, self).to_yaml(*a)

# Create a new instance of a model.
#
Expand Down
6 changes: 5 additions & 1 deletion lib/finch_api/internal/type/boolean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ def coerce(value, state:)
# #
# # @param value [Boolean, Object]
# #
# # @param state [Hash{Symbol=>Object}] .
# #
# # @option state [Boolean] :can_retry
# #
# # @return [Boolean, Object]
# def dump(value) = super
# def dump(value, state:) = super
end
end
end
Expand Down
59 changes: 42 additions & 17 deletions lib/finch_api/internal/type/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@ def coerce(value, state:) = (raise NotImplementedError)
#
# @param value [Object]
#
# @param state [Hash{Symbol=>Object}] .
#
# @option state [Boolean] :can_retry
#
# @return [Object]
def dump(value)
def dump(value, state:)
case value
in Array
value.map { FinchAPI::Internal::Type::Unknown.dump(_1) }
value.map { FinchAPI::Internal::Type::Unknown.dump(_1, state: state) }
in Hash
value.transform_values { FinchAPI::Internal::Type::Unknown.dump(_1) }
value.transform_values { FinchAPI::Internal::Type::Unknown.dump(_1, state: state) }
in FinchAPI::Internal::Type::BaseModel
value.class.dump(value)
value.class.dump(value, state: state)
in StringIO
value.string
in Pathname | IO
state[:can_retry] = false if value.is_a?(IO)
FinchAPI::Internal::Util::SerializationAdapter.new(value)
else
value
end
Expand Down Expand Up @@ -140,9 +149,9 @@ def coerce(
if value.is_a?(Integer)
exactness[:yes] += 1
return value
elsif strictness == :strong
elsif strictness == :strong && Integer(value, exception: false) != value
message = "no implicit conversion of #{value.class} into #{target.inspect}"
raise TypeError.new(message)
raise value.is_a?(Numeric) ? ArgumentError.new(message) : TypeError.new(message)
else
Kernel.then do
return Integer(value).tap { exactness[:maybe] += 1 }
Expand Down Expand Up @@ -182,18 +191,26 @@ def coerce(
rescue ArgumentError, TypeError => e
raise e if strictness == :strong
end
in -> { _1 <= IO } if value.is_a?(String)
in -> { _1 <= StringIO } if value.is_a?(String)
exactness[:yes] += 1
return StringIO.new(value.b)
else
end
in Symbol
if (value.is_a?(Symbol) || value.is_a?(String)) && value.to_sym == target
exactness[:yes] += 1
return target
elsif strictness == :strong
message = "cannot convert non-matching #{value.class} into #{target.inspect}"
raise ArgumentError.new(message)
case value
in Symbol | String
if value.to_sym == target
exactness[:yes] += 1
return target
else
exactness[:maybe] += 1
return value
end
else
if strictness == :strong
message = "cannot convert non-matching #{value.class} into #{target.inspect}"
raise ArgumentError.new(message)
end
end
else
end
Expand All @@ -207,13 +224,21 @@ def coerce(
# @api private
#
# @param target [FinchAPI::Internal::Type::Converter, Class]
#
# @param value [Object]
#
# @param state [Hash{Symbol=>Object}] .
#
# @option state [Boolean] :can_retry
#
# @return [Object]
def dump(target, value)
# rubocop:disable Layout/LineLength
target.is_a?(FinchAPI::Internal::Type::Converter) ? target.dump(value) : FinchAPI::Internal::Type::Unknown.dump(value)
# rubocop:enable Layout/LineLength
def dump(target, value, state: {can_retry: true})
case target
in FinchAPI::Internal::Type::Converter
target.dump(value, state: state)
else
FinchAPI::Internal::Type::Unknown.dump(value, state: state)
end
end
end
end
Expand Down
Loading
Loading