mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-08-14 00:02:11 -04:00
Compare commits
No commits in common. "420218c7a1ce844fef236995efe6c686d726559e" and "a0b5b50bc10923838f655421e72a7087a8bd4701" have entirely different histories.
420218c7a1
...
a0b5b50bc1
@ -120,35 +120,16 @@ module Stripe
|
||||
}
|
||||
end
|
||||
|
||||
class Preview
|
||||
PREVIEW_API_VERSION = "20230509T165653"
|
||||
|
||||
def self._get_default_opts(opts)
|
||||
{ stripe_version: PREVIEW_API_VERSION, encoding: :json }.merge(opts)
|
||||
end
|
||||
|
||||
def self.get(url, opts = {})
|
||||
Stripe.raw_request(:get, url, {}, _get_default_opts(opts))
|
||||
end
|
||||
|
||||
def self.post(url, params = {}, opts = {})
|
||||
Stripe.raw_request(:post, url, params, _get_default_opts(opts))
|
||||
end
|
||||
|
||||
def self.delete(url, opts = {})
|
||||
Stripe.raw_request(:delete, url, {}, _get_default_opts(opts))
|
||||
end
|
||||
end
|
||||
|
||||
class RawRequest
|
||||
include Stripe::APIOperations::Request
|
||||
|
||||
def initialize
|
||||
def initialize()
|
||||
@opts = {}
|
||||
end
|
||||
|
||||
def execute(method, url, params = {}, opts = {})
|
||||
resp, = execute_resource_request(method, url, params, opts)
|
||||
resp, _ = execute_resource_request(method, url, params, opts)
|
||||
|
||||
resp
|
||||
end
|
||||
|
@ -459,9 +459,6 @@ module Stripe
|
||||
|
||||
headers = request_headers(api_key, method)
|
||||
.update(Util.normalize_headers(headers))
|
||||
|
||||
headers.delete("Content-Type") if encoding == :json && body_params.nil?
|
||||
|
||||
url = api_url(path, api_base)
|
||||
|
||||
# Merge given query parameters with any already encoded in the path.
|
||||
@ -888,7 +885,7 @@ module Stripe
|
||||
headers = {
|
||||
"User-Agent" => user_agent,
|
||||
"Authorization" => "Bearer #{api_key}",
|
||||
"Content-Type" => "application/x-www-form-urlencoded", # TODO: (major) don't set if method is not post
|
||||
"Content-Type" => "application/x-www-form-urlencoded",
|
||||
}
|
||||
|
||||
if config.enable_telemetry? && !@last_request_metrics.nil?
|
||||
|
@ -146,6 +146,7 @@ class StripeTest < Test::Unit::TestCase
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||
.to_return(body: expected_body)
|
||||
|
||||
|
||||
resp = Stripe.raw_request(:get, "/v1/accounts/acc_123")
|
||||
|
||||
assert_equal resp.http_body, expected_body
|
||||
@ -162,6 +163,7 @@ class StripeTest < Test::Unit::TestCase
|
||||
assert_equal resp.http_body, expected_body
|
||||
end
|
||||
|
||||
|
||||
should "send post request with json body and return a response" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||
@ -176,29 +178,16 @@ class StripeTest < Test::Unit::TestCase
|
||||
should "send post request with json body and headers and return a response" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||
.with(body: "{\"p1\":1,\"p2\":\"string\"}", headers: { "Stripe-Account" => "bar" , "Content-Type" => "application/json"})
|
||||
.with(body: "{\"p1\":1,\"p2\":\"string\"}", headers: { "Stripe-Account" => "bar" })
|
||||
.to_return(body: expected_body)
|
||||
|
||||
resp = Stripe.raw_request(:post, "/v1/accounts/acc_123", { p1: 1, p2: "string" }, { encoding: :json, "Stripe-Account": "bar" })
|
||||
|
||||
assert_equal expected_body, resp.http_body
|
||||
end
|
||||
|
||||
should "send get request with json body" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
req = nil
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||
.with { |request| req = request; true }
|
||||
.to_return(body: expected_body)
|
||||
|
||||
resp = Stripe.raw_request(:get, "/v1/accounts/acc_123", {}, { encoding: :json, "Stripe-Account": "bar" })
|
||||
|
||||
assert_not_equal req.headers["Content-Type"], "application/x-www-form-urlencoded"
|
||||
assert_equal resp.http_body, expected_body
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "deserialize" do
|
||||
should "deserializes string into known object" do
|
||||
expected_body = "{\"id\": \"acc_123\", \"object\": \"account\"}"
|
||||
@ -219,7 +208,7 @@ class StripeTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
should "deserializes hash into known object" do
|
||||
expected_body = { "id" => "acc_123", "object" => "account" }
|
||||
expected_body = {"id" => "acc_123", "object" => "account"}
|
||||
|
||||
obj = Stripe.deserialize(expected_body)
|
||||
|
||||
@ -228,7 +217,7 @@ class StripeTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
should "deserializes hash into unknown object" do
|
||||
expected_body = { "id" => "acc_123", "object" => "unknown" }
|
||||
expected_body = {"id" => "acc_123", "object" => "unknown"}
|
||||
|
||||
obj = Stripe.deserialize(expected_body)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user