Add stripe_client usage tracking for StripeClient (#1637)

* Add usage string for stripe_client usage

* small fixes

* rubocop on cursor code

* remove extra comments
This commit is contained in:
helenye-stripe 2025-08-25 13:43:23 -07:00 committed by GitHub
parent 13766d190c
commit 192d5bee13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 51 additions and 1 deletions

View File

@ -14,7 +14,8 @@ module Stripe
path,
base_address,
params: params,
opts: RequestOptions.extract_opts_from_hash(opts)
opts: RequestOptions.extract_opts_from_hash(opts),
usage: ["stripe_client"]
)
end
@ -25,6 +26,7 @@ module Stripe
base_address,
params: params,
opts: RequestOptions.extract_opts_from_hash(opts),
usage: ["stripe_client"],
&read_body_chunk_block
)
end

View File

@ -66,5 +66,53 @@ module Stripe
client.meter_events_bases.retrieve("foo_123")
end
end
context "usage parameter" do
should "send usage stripe_client with request" do
stub_request(:get, "#{Stripe::DEFAULT_API_BASE}/v1/test")
.to_return(body: JSON.generate(object: "test"))
requestor = APIRequestor.new("sk_test_123")
service = StripeService.new(requestor)
requestor.expects(:execute_request)
.with(:get, "/v1/test", :api,
has_entries(params: {},
usage: ["stripe_client"]))
.returns([{ object: "test" }, nil])
service.request(
method: :get,
path: "/v1/test",
base_address: :api
)
end
should "send usage stripe_client with request_stream" do
stub_request(:get, "#{Stripe::DEFAULT_API_BASE}/v1/test")
.to_return(body: "test response")
requestor = APIRequestor.new("sk_test_123")
service = StripeService.new(requestor)
requestor.expects(:execute_request_stream)
.with(:get, "/v1/test", :api,
has_entries(params: {},
usage: ["stripe_client"]))
.yields("test response")
.returns([nil, "test response"])
accumulated_body = +""
service.request_stream(
method: :get,
path: "/v1/test",
base_address: :api
) do |body_chunk|
accumulated_body << body_chunk
end
assert_equal "test response", accumulated_body
end
end
end
end