mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-11-29 00:01:18 -05:00
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:
parent
13766d190c
commit
192d5bee13
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user