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

Add usage to raw_request call #1433

Merged
merged 1 commit into from
Jul 11, 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: 3 additions & 3 deletions lib/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def initialize
@opts = {}
end

def execute(method, url, params = {}, opts = {})
resp, = execute_resource_request(method, url, params, opts)
def execute(method, url, params = {}, opts = {}, usage = [])
resp, = execute_resource_request(method, url, params, opts, usage)

resp
end
Expand All @@ -135,7 +135,7 @@ def execute(method, url, params = {}, opts = {})
# Sends a request to Stripe REST API
def self.raw_request(method, url, params = {}, opts = {})
req = RawRequest.new
req.execute(method, url, params, opts)
req.execute(method, url, params, opts, ["raw_request"])
end

def self.deserialize(data)
Expand Down
17 changes: 17 additions & 0 deletions test/stripe/raw_request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,22 @@ class RawRequestTest < Test::Unit::TestCase
assert_equal "application/x-www-form-urlencoded", req.headers["Content-Type"]
assert_equal Stripe::ApiVersion::CURRENT, req.headers["Stripe-Version"]
end

should "report usage" do
expected_body = "{\"id\": \"acc_123\"}"
telemetry_header = nil

Stripe.enable_telemetry = true

stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_124")
.with { |request| telemetry_header = request.headers["X-Stripe-Client-Telemetry"] }
.to_return(body: expected_body)

Stripe.raw_request(:get, "/v1/accounts/acc_123", {}, {})
Stripe.raw_request(:get, "/v1/accounts/acc_124", {}, {})
parsed_telemetry_header = JSON.parse(telemetry_header)

assert(parsed_telemetry_header["last_request_metrics"]["usage"] == ["raw_request"])
end
end
end
Loading