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.6"
".": "0.1.0-alpha.7"
}
14 changes: 9 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Layout/LineLength:
AllowedPatterns:
- "^\\s*#.*$"
- ^require(_relative)?
- "FinchAPI::(Models|Resources)::"
- "FinchAPI::Internal::Type::BaseModel$"
- "^\\s*[A-Z0-9_]+ = :"
- "FinchAPI::(Models|Resources|Test)::"
Max: 110

Layout/MultilineArrayLineBreaks:
Expand Down Expand Up @@ -109,8 +111,7 @@ Metrics/MethodLength:
Enabled: false

Metrics/ModuleLength:
Exclude:
- "**/*.rbi"
Enabled: false

Metrics/ParameterLists:
Enabled: false
Expand All @@ -122,9 +123,9 @@ Metrics/PerceivedComplexity:
Naming/BlockForwarding:
Enabled: false

# Underscores are generally useful for disambiguation.
Naming/ClassAndModuleCamelCase:
Exclude:
- "**/*.rbi"
Enabled: false

Naming/MethodParameterName:
Enabled: false
Expand Down Expand Up @@ -202,6 +203,9 @@ Style/MethodCallWithArgsParentheses:
Exclude:
- "**/*.gemspec"

Style/MultilineBlockChain:
Enabled: false

# Perfectly fine.
Style/MultipleComparison:
Enabled: false
Expand Down
1 change: 1 addition & 0 deletions .solargraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include:
- 'Rakefile'
- 'examples/**/*.rb'
- 'lib/**/*.rb'
- 'test/finch-api/resource_namespaces.rb'
- 'test/finch-api/test_helper.rb'
exclude:
- 'rbi/**/*'
2 changes: 1 addition & 1 deletion .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: 2bca9e6b32f742acb077cf8822ec9e23
config_hash: ce10384813f68ba3fed61c7b601b396b
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Changelog

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

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

### Features

* allow all valid `JSON` types to be encoded ([#119](https://github.com/Finch-API/finch-api-ruby/issues/119)) ([a67519c](https://github.com/Finch-API/finch-api-ruby/commit/a67519c5f2039cccce94f069ad1eeb40252290c1))
* support query, header, and body params that have identical names ([#118](https://github.com/Finch-API/finch-api-ruby/issues/118)) ([4fa584a](https://github.com/Finch-API/finch-api-ruby/commit/4fa584ab9a22689faa9b218f508a38188d5847d3))


### Bug Fixes

* converter should transform stringio into string where applicable ([#121](https://github.com/Finch-API/finch-api-ruby/issues/121)) ([432e28e](https://github.com/Finch-API/finch-api-ruby/commit/432e28e92b9704f9692937315a5bb129fccb9ed5))


### Chores

* always fold up method bodies in sorbet type definitions ([#125](https://github.com/Finch-API/finch-api-ruby/issues/125)) ([ff97af2](https://github.com/Finch-API/finch-api-ruby/commit/ff97af205ffe88a190d05f6ecaf63d73794b39c0))
* document LSP support in read me ([#117](https://github.com/Finch-API/finch-api-ruby/issues/117)) ([469c82c](https://github.com/Finch-API/finch-api-ruby/commit/469c82c13e10eff05dc59148195e41a8060c660f))
* **internal:** misc small improvements ([#122](https://github.com/Finch-API/finch-api-ruby/issues/122)) ([9817037](https://github.com/Finch-API/finch-api-ruby/commit/981703710cff8afcdedc0c133457f54480f0cd7e))
* **internal:** more concise handling of parameter naming conflicts ([#127](https://github.com/Finch-API/finch-api-ruby/issues/127)) ([81414ea](https://github.com/Finch-API/finch-api-ruby/commit/81414ea8318e9f7fef2fece402c9e31088a62c99))
* **internal:** rubocop rules ([#124](https://github.com/Finch-API/finch-api-ruby/issues/124)) ([7e59465](https://github.com/Finch-API/finch-api-ruby/commit/7e59465247659dac04e33e608c8308c56fea8d58))
* **internal:** run rubocop linter in parallel ([#123](https://github.com/Finch-API/finch-api-ruby/issues/123)) ([53b1156](https://github.com/Finch-API/finch-api-ruby/commit/53b1156d97634b97ad54330a2860b9cdbe996947))
* **internal:** version bump ([#113](https://github.com/Finch-API/finch-api-ruby/issues/113)) ([14b68c9](https://github.com/Finch-API/finch-api-ruby/commit/14b68c95d5b50abe3d46745a86054d81e80684c1))
* misc sdk polish ([#116](https://github.com/Finch-API/finch-api-ruby/issues/116)) ([9af5943](https://github.com/Finch-API/finch-api-ruby/commit/9af5943664bddedd57feab75609521ccfbf3afbd))
* rename confusing `Type::BooleanModel` to `Type::Boolean` ([#120](https://github.com/Finch-API/finch-api-ruby/issues/120)) ([4295175](https://github.com/Finch-API/finch-api-ruby/commit/429517572c98a1ccc9851a6cb16e875546b637ee))
* simplify internal utils ([#114](https://github.com/Finch-API/finch-api-ruby/issues/114)) ([0745cc7](https://github.com/Finch-API/finch-api-ruby/commit/0745cc74ce9ef4c0fa2c391ac62b155188110990))
* update yard comment formatting ([#126](https://github.com/Finch-API/finch-api-ruby/issues/126)) ([695363a](https://github.com/Finch-API/finch-api-ruby/commit/695363a4a80ebae5104a0a01c9427abfc277afb0))

## 0.1.0-alpha.6 (2025-04-04)

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

GEM
Expand Down
30 changes: 25 additions & 5 deletions 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.5"
gem "finch-api", "~> 0.1.0.pre.alpha.6"
```

<!-- x-release-please-end -->
Expand Down Expand Up @@ -126,9 +126,23 @@ finch.hris.directory.list(request_options: {timeout: 5})

## LSP Support

### Sorbet
### Solargraph

This library includes [Solargraph](https://solargraph.org) support for both auto completion and go to definition.

```ruby
gem "solargraph", group: :development
```

After Solargraph is installed, **you must populate its index** either via the provided editor command, or by running the following in your terminal:

```sh
bundle exec solargraph gems
```

**This library emits an intentional warning under the [`tapioca` toolchain](https://github.com/Shopify/tapioca)**. This is normal, and does not impact functionality.
Otherwise Solargraph will not be able to provide type information or auto-completion for any non-indexed libraries.

### Sorbet

This library is written with [Sorbet type definitions](https://sorbet.org/docs/rbi). However, there is no runtime dependency on the `sorbet-runtime`.

Expand All @@ -139,11 +153,17 @@ Due to limitations with the Sorbet type system, where a method otherwise can tak
Please follow Sorbet's [setup guides](https://sorbet.org/docs/adopting) for best experience.

```ruby
model = FinchAPI::Models::HRIS::DirectoryListParams.new
params = FinchAPI::Models::HRIS::DirectoryListParams.new

finch.hris.directory.list(**model)
finch.hris.directory.list(**params)
```

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

### Ruby LSP

The Ruby LSP has [best effort support](https://shopify.github.io/ruby-lsp/#guessed-types) for inferring type information from Ruby code, and as such it may not always be able to provide accurate type information.

## Advanced

### Making custom/undocumented requests
Expand Down
16 changes: 7 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ require "rubocop/rake_task"

CLEAN.push(*%w[.idea/ .ruby-lsp/ .yardoc/])

xargs = %w[xargs --no-run-if-empty --null --max-procs=0 --max-args=300 --]

multitask(default: [:test])

multitask(:test) do
Expand All @@ -22,17 +20,17 @@ multitask(:test) do
ruby(*%w[-w -e], rb, verbose: false) { fail unless _1 }
end

RuboCop::RakeTask.new(:rubocop) do |t|
t.options = %w[--fail-level E]
if ENV.key?("CI")
t.options += %w[--format github]
end
rubo_find = %w[find ./lib ./test ./rbi -type f -and ( -name *.rb -or -name *.rbi ) -print0]
xargs = %w[xargs --no-run-if-empty --null --max-procs=0 --max-args=300 --]

multitask(:rubocop) do
lint = xargs + %w[rubocop --fail-level E] + (ENV.key?("CI") ? %w[--format github] : [])
sh("#{rubo_find.shelljoin} | #{lint.shelljoin}")
end

multitask(:ruboformat) do
find = %w[find ./lib ./test ./rbi -type f -and ( -name *.rb -or -name *.rbi ) -print0]
fmt = xargs + %w[rubocop --fail-level F --autocorrect --format simple --]
sh("#{find.shelljoin} | #{fmt.shelljoin}")
sh("#{rubo_find.shelljoin} | #{fmt.shelljoin}")
end

multitask(:syntax_tree) do
Expand Down
2 changes: 1 addition & 1 deletion lib/finch_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
require_relative "finch_api/internal/util"
require_relative "finch_api/internal/type/converter"
require_relative "finch_api/internal/type/unknown"
require_relative "finch_api/internal/type/boolean_model"
require_relative "finch_api/internal/type/boolean"
require_relative "finch_api/internal/type/enum"
require_relative "finch_api/internal/type/union"
require_relative "finch_api/internal/type/array_of"
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 @@ -393,7 +393,7 @@ def initialize(
end

# Execute the request specified by `req`. This is the method that all resource
# methods call into.
# methods call into.
#
# @overload request(method, path, query: {}, headers: {}, body: nil, unwrap: nil, page: nil, stream: nil, model: FinchAPI::Internal::Type::Unknown, options: {})
#
Expand Down
2 changes: 1 addition & 1 deletion lib/finch_api/internal/transport/pooled_net_requester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Transport
# @api private
class PooledNetRequester
# from the golang stdlib
# https://github.com/golang/go/blob/c8eced8580028328fde7c03cbfcb720ce15b2358/src/net/http/transport.go#L49
# https://github.com/golang/go/blob/c8eced8580028328fde7c03cbfcb720ce15b2358/src/net/http/transport.go#L49
KEEP_ALIVE_TIMEOUT = 30

class << self
Expand Down
35 changes: 19 additions & 16 deletions lib/finch_api/internal/type/base_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class << self
# @api private
#
# Assumes superclass fields are totally defined before fields are accessed /
# defined on subclasses.
# defined on subclasses.
#
# @return [Hash{Symbol=>Hash{Symbol=>Object}}]
def known_fields
Expand Down Expand Up @@ -150,7 +150,7 @@ def optional(name_sym, type_info, spec = {})
# @api private
#
# `request_only` attributes not excluded from `.#coerce` when receiving responses
# even if well behaved servers should not send them
# even if well behaved servers should not send them
#
# @param blk [Proc]
private def request_only(&blk)
Expand All @@ -175,7 +175,9 @@ def optional(name_sym, type_info, spec = {})
# @param other [Object]
#
# @return [Boolean]
def ==(other) = other.is_a?(Class) && other <= FinchAPI::Internal::Type::BaseModel && other.fields == fields
def ==(other)
other.is_a?(Class) && other <= FinchAPI::Internal::Type::BaseModel && other.fields == fields
end
end

# @param other [Object]
Expand Down Expand Up @@ -271,7 +273,7 @@ def dump(value)
in nil
acc.store(name, super(val))
else
mode, api_name, type_fn = field.fetch_values(:mode, :api_name, :type_fn)
api_name, mode, type_fn = field.fetch_values(:api_name, :mode, :type_fn)
case mode
in :coerce
next
Expand All @@ -283,7 +285,7 @@ def dump(value)
end

known_fields.each_value do |field|
mode, api_name, const = field.fetch_values(:mode, :api_name, :const)
api_name, mode, const = field.fetch_values(:api_name, :mode, :const)
next if mode == :coerce || acc.key?(api_name) || const == FinchAPI::Internal::OMIT
acc.store(api_name, const)
end
Expand All @@ -293,11 +295,11 @@ def dump(value)
end

# Returns the raw value associated with the given key, if found. Otherwise, nil is
# returned.
# returned.
#
# It is valid to lookup keys that are not in the API spec, for example to access
# undocumented features. This method does not parse response data into
# higher-level types. Lookup by anything other than a Symbol is an ArgumentError.
# It is valid to lookup keys that are not in the API spec, for example to access
# undocumented features. This method does not parse response data into
# higher-level types. Lookup by anything other than a Symbol is an ArgumentError.
#
# @param key [Symbol]
#
Expand All @@ -312,12 +314,12 @@ def [](key)

# Returns a Hash of the data underlying this object. O(1)
#
# Keys are Symbols and values are the raw values from the response. The return
# value indicates which values were ever set on the object. i.e. there will be a
# key in this hash if they ever were, even if the set value was nil.
# Keys are Symbols and values are the raw values from the response. The return
# value indicates which values were ever set on the object. i.e. there will be a
# key in this hash if they ever were, even if the set value was nil.
#
# This method is not recursive. The returned value is shared by the object, so it
# should not be mutated.
# This method is not recursive. The returned value is shared by the object, so it
# should not be mutated.
#
# @return [Hash{Symbol=>Object}]
def to_h = @data
Expand Down Expand Up @@ -357,15 +359,16 @@ def initialize(data = {})
in Hash => coerced
@data = coerced
else
raise ArgumentError.new("Expected a #{Hash} or #{FinchAPI::Internal::Type::BaseModel}, got #{data.inspect}")
message = "Expected a #{Hash} or #{FinchAPI::Internal::Type::BaseModel}, got #{data.inspect}"
raise ArgumentError.new(message)
end
end

# @return [String]
def inspect
rows = self.class.known_fields.keys.map do
"#{_1}=#{@data.key?(_1) ? public_send(_1) : ''}"
rescue FinchAPI::ConversionError
rescue FinchAPI::Errors::ConversionError
"#{_1}=#{@data.fetch(_1)}"
end
"#<#{self.class.name}:0x#{object_id.to_s(16)} #{rows.join(' ')}>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Type
# @abstract
#
# Ruby has no Boolean class; this is something for models to refer to.
class BooleanModel
class Boolean
extend FinchAPI::Internal::Type::Converter

# @param other [Object]
Expand All @@ -19,7 +19,7 @@ def self.===(other) = other == true || other == false
# @param other [Object]
#
# @return [Boolean]
def self.==(other) = other.is_a?(Class) && other <= FinchAPI::Internal::Type::BooleanModel
def self.==(other) = other.is_a?(Class) && other <= FinchAPI::Internal::Type::Boolean

class << self
# @api private
Expand Down
Loading
Loading