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 a global proxy configuration parameter #753

Merged
merged 1 commit into from
Mar 26, 2019
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
20 changes: 10 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -35,7 +35,7 @@ Metrics/LineLength:
Metrics/ParameterLists:
Max: 7

# Offense count: 5
# Offense count: 7
Metrics/PerceivedComplexity:
Max: 17

Expand All @@ -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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]:1234"
```

### Configuring an API Version

By default, the library will use the API version pinned to the account making
Expand Down
4 changes: 3 additions & 1 deletion lib/stripe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/stripe/stripe_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def self.default_conn
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
Expand Down
19 changes: 19 additions & 0 deletions test/stripe/stripe_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,25 @@ class StripeClientTest < Test::Unit::TestCase
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
Expand Down