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
4 changes: 3 additions & 1 deletion lib/stripe/stripe_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def request(method:, path:, base_address:, params: {}, opts: {})
path,
base_address,
params: params,
opts: RequestOptions.extract_opts_from_hash(opts)
opts: RequestOptions.extract_opts_from_hash(opts),
usage: ["stripe_client"]
)
end

Expand All @@ -25,6 +26,7 @@ def request_stream(method:, path:, base_address:, params: {}, opts: {}, &read_bo
base_address,
params: params,
opts: RequestOptions.extract_opts_from_hash(opts),
usage: ["stripe_client"],
&read_body_chunk_block
)
end
Expand Down
48 changes: 48 additions & 0 deletions test/stripe/stripe_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,53 @@ def respond_to_missing?(method, include_private = false)
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