Skip to content

Commit d98e406

Browse files
authored
Merge pull request #753 from stripe/ob-proxy
Add a global proxy configuration parameter
2 parents 287a2e6 + 6e95bf4 commit d98e406

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

.rubocop_todo.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2018-07-19 14:22:24 +0200 using RuboCop version 0.50.0.
3+
# on 2019-03-25 18:32:26 -0700 using RuboCop version 0.50.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 19
9+
# Offense count: 20
1010
Metrics/AbcSize:
11-
Max: 54
11+
Max: 53
1212

13-
# Offense count: 27
13+
# Offense count: 31
1414
# Configuration parameters: CountComments, ExcludedMethods.
1515
Metrics/BlockLength:
1616
Max: 498
1717

18-
# Offense count: 8
18+
# Offense count: 9
1919
# Configuration parameters: CountComments.
2020
Metrics/ClassLength:
21-
Max: 670
21+
Max: 673
2222

23-
# Offense count: 11
23+
# Offense count: 12
2424
Metrics/CyclomaticComplexity:
2525
Max: 15
2626

27-
# Offense count: 278
27+
# Offense count: 364
2828
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
2929
# URISchemes: http, https
3030
Metrics/LineLength:
@@ -35,7 +35,7 @@ Metrics/LineLength:
3535
Metrics/ParameterLists:
3636
Max: 7
3737

38-
# Offense count: 5
38+
# Offense count: 7
3939
Metrics/PerceivedComplexity:
4040
Max: 17
4141

@@ -45,6 +45,6 @@ Style/ClassVars:
4545
- 'lib/stripe/stripe_object.rb'
4646
- 'test/stripe/api_resource_test.rb'
4747

48-
# Offense count: 56
48+
# Offense count: 78
4949
Style/Documentation:
5050
Enabled: false

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ end
114114
puts resp.request_id
115115
```
116116

117+
### Configuring a proxy
118+
119+
A proxy can be configured with `Stripe.proxy`:
120+
121+
```ruby
122+
Stripe.proxy = "https://user:[email protected]:1234"
123+
```
124+
117125
### Configuring an API Version
118126

119127
By default, the library will use the API version pinned to the account making

lib/stripe.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ module Stripe
121121
@log_level = nil
122122
@logger = nil
123123

124+
@proxy = nil
125+
124126
@max_network_retries = 0
125127
@max_network_retry_delay = 2
126128
@initial_network_retry_delay = 0.5
@@ -136,7 +138,7 @@ module Stripe
136138

137139
class << self
138140
attr_accessor :stripe_account, :api_key, :api_base, :verify_ssl_certs, :api_version, :client_id, :connect_base, :uploads_base,
139-
:open_timeout, :read_timeout
141+
:open_timeout, :read_timeout, :proxy
140142

141143
attr_reader :max_network_retry_delay, :initial_network_retry_delay
142144
end

lib/stripe/stripe_client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ def self.default_conn
4545
end
4646
end
4747

48+
conn.proxy = Stripe.proxy if Stripe.proxy
49+
4850
if Stripe.verify_ssl_certs
4951
conn.ssl.verify = true
5052
conn.ssl.cert_store = Stripe.ca_store

test/stripe/stripe_client_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,25 @@ class StripeClientTest < Test::Unit::TestCase
750750
end
751751
end
752752

753+
context "#proxy" do
754+
should "run the request through the proxy" do
755+
begin
756+
Thread.current[:stripe_client_default_conn] = nil
757+
758+
Stripe.proxy = "http://localhost:8080"
759+
760+
client = StripeClient.new
761+
client.request {}
762+
763+
assert_equal "http://localhost:8080", Stripe::StripeClient.default_conn.proxy.uri.to_s
764+
ensure
765+
Stripe.proxy = nil
766+
767+
Thread.current[:stripe_client_default_conn] = nil
768+
end
769+
end
770+
end
771+
753772
context "#telemetry" do
754773
teardown do
755774
# make sure to always set telemetry back to false

0 commit comments

Comments
 (0)