Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generated code for beta #1328

Merged
merged 6 commits into from
Feb 14, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
* [#1321](https://github.com/stripe/stripe-ruby/pull/1321) Update generated code for beta
* Release specs are identical.

## 10.8.0 - 2024-02-08
* [#1322](https://github.com/stripe/stripe-ruby/pull/1322) Update generated code
* [#1323](https://github.com/stripe/stripe-ruby/pull/1323) Extract other CRUDL api operations from mixins
* Extract more CRUDL operations, namely `create`, `delete`, `update`, and `list` into the resources. These methods will no longer rely on the APIOperation mixins.
* [#1314](https://github.com/stripe/stripe-ruby/pull/1314) Update mocha gem to 1.16

## 10.8.0-beta.1 - 2024-02-01
* [#1318](https://github.com/stripe/stripe-ruby/pull/1318) Update generated code for beta
* Add support for new resources `Entitlements.Event` and `Entitlements.Feature`
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ group :development do
# don't install on truffleruby
gem "jaro_winkler", "1.5.4" unless RUBY_ENGINE == "truffleruby"

gem "sorbet-static"
gem "tapioca"

platforms :mri do
gem "byebug"
gem "pry"
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ codegen-format:

ci-test:
bundle install && bundle exec rake test
@version=$$(ruby -e "puts RUBY_VERSION.split('.')[0..1].join.to_i"); \
if [ $$version -ge 27 ]; then \
echo "Ruby version >= 2.7, continue with srb tc"; \
bundle exec srb tc; \
else \
echo "Ruby version < 2.7, skipping srb tc"; \
fi

test: ci-test
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v810
v827
27 changes: 27 additions & 0 deletions bin/tapioca
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'tapioca' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("tapioca", "tapioca")
11 changes: 10 additions & 1 deletion lib/stripe/api_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ class APIResource < StripeObject
# for example, where this is allowed.
attr_accessor :save_with_parent

# TODO: (major) Remove OBJECT_NAME and stop using const_get here
# This is a workaround to avoid breaking users who have defined their own
# APIResource subclasses with a custom OBJECT_NAME. We should never fallback
# on this case otherwise.
OBJECT_NAME = ""
def self.object_name
const_get(:OBJECT_NAME)
end

def self.class_name
name.split("::")[-1]
end
Expand All @@ -23,7 +32,7 @@ def self.resource_url
end
# Namespaces are separated in object names with periods (.) and in URLs
# with forward slashes (/), so replace the former with the latter.
"/v1/#{self::OBJECT_NAME.downcase.tr('.', '/')}s"
"/v1/#{object_name.downcase.tr('.', '/')}s"
end

# A metaprogramming call that specifies that a field of a resource can be
Expand Down
8 changes: 6 additions & 2 deletions lib/stripe/api_resource_test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def initialize(resource)
@resource = resource
end

def self.resource_class
nil
end

# Adds a custom method to a test helper. This is used to add support for
# non-CRUDL API requests, e.g. capturing charges. custom_method takes the
# following parameters:
Expand All @@ -27,12 +31,12 @@ def initialize(resource)
# adds a `capture` class method to the resource class that, when called,
# will send a POST request to `/v1/<object_name>/capture`.
def self.custom_method(name, http_verb:, http_path: nil)
Util.custom_method self::RESOURCE_CLASS, self, name, http_verb, http_path
Util.custom_method resource_class, self, name, http_verb, http_path
end

def self.resource_url
"/v1/test_helpers/" \
"#{self::RESOURCE_CLASS::OBJECT_NAME.downcase.tr('.', '/')}s"
"#{resource_class.object_name.downcase.tr('.', '/')}s"
end

def resource_url
Expand Down
3 changes: 3 additions & 0 deletions lib/stripe/list_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class ListObject < StripeObject
include Stripe::APIOperations::Create

OBJECT_NAME = "list"
def self.object_name
"list"
end

# This accessor allows a `ListObject` to inherit various filters that were
# given to a predecessor. This allows for things like consistent limits,
Expand Down
Loading
Loading