Skip to content

Commit

Permalink
Add usage to raw request call (#1433)
Browse files Browse the repository at this point in the history
  • Loading branch information
helenye-stripe authored Jul 11, 2024
1 parent 816fe0d commit aa49a46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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

0 comments on commit aa49a46

Please sign in to comment.