Add a global proxy configuration parameter

This commit is contained in:
Olivier Bellone 2019-03-25 18:34:12 -07:00
parent 287a2e6979
commit 6e95bf45f9
5 changed files with 42 additions and 11 deletions

View File

@ -1,30 +1,30 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-07-19 14:22:24 +0200 using RuboCop version 0.50.0.
# on 2019-03-25 18:32:26 -0700 using RuboCop version 0.50.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 19
# Offense count: 20
Metrics/AbcSize:
Max: 54
Max: 53
# Offense count: 27
# Offense count: 31
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 498
# Offense count: 8
# Offense count: 9
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 670
Max: 673
# Offense count: 11
# Offense count: 12
Metrics/CyclomaticComplexity:
Max: 15
# Offense count: 278
# Offense count: 364
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
@ -35,7 +35,7 @@ Metrics/LineLength:
Metrics/ParameterLists:
Max: 7
# Offense count: 5
# Offense count: 7
Metrics/PerceivedComplexity:
Max: 17
@ -45,6 +45,6 @@ Style/ClassVars:
- 'lib/stripe/stripe_object.rb'
- 'test/stripe/api_resource_test.rb'
# Offense count: 56
# Offense count: 78
Style/Documentation:
Enabled: false

View File

@ -114,6 +114,14 @@ end
puts resp.request_id
```
### Configuring a proxy
A proxy can be configured with `Stripe.proxy`:
```ruby
Stripe.proxy = "https://user:pass@example.com:1234"
```
### Configuring an API Version
By default, the library will use the API version pinned to the account making

View File

@ -121,6 +121,8 @@ module Stripe
@log_level = nil
@logger = nil
@proxy = nil
@max_network_retries = 0
@max_network_retry_delay = 2
@initial_network_retry_delay = 0.5
@ -136,7 +138,7 @@ module Stripe
class << self
attr_accessor :stripe_account, :api_key, :api_base, :verify_ssl_certs, :api_version, :client_id, :connect_base, :uploads_base,
:open_timeout, :read_timeout
:open_timeout, :read_timeout, :proxy
attr_reader :max_network_retry_delay, :initial_network_retry_delay
end

View File

@ -45,6 +45,8 @@ module Stripe
end
end
conn.proxy = Stripe.proxy if Stripe.proxy
if Stripe.verify_ssl_certs
conn.ssl.verify = true
conn.ssl.cert_store = Stripe.ca_store

View File

@ -750,6 +750,25 @@ module Stripe
end
end
context "#proxy" do
should "run the request through the proxy" do
begin
Thread.current[:stripe_client_default_conn] = nil
Stripe.proxy = "http://localhost:8080"
client = StripeClient.new
client.request {}
assert_equal "http://localhost:8080", Stripe::StripeClient.default_conn.proxy.uri.to_s
ensure
Stripe.proxy = nil
Thread.current[:stripe_client_default_conn] = nil
end
end
end
context "#telemetry" do
teardown do
# make sure to always set telemetry back to false