Skip to content

Commit

Permalink
Merge pull request #80 from Mangopay/timeout-support
Browse files Browse the repository at this point in the history
Add HTTP timeout support
  • Loading branch information
mickaelpois authored Jun 27, 2017
2 parents 1a06580 + 02b5882 commit 289887b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ MangoPay.configure do |c|
c.client_id = 'YOUR_CLIENT_ID'
c.client_passphrase = 'YOUR_CLIENT_PASSWORD'
c.log_file = File.join('mypath', 'mangopay.log')
c.http_timeout = 10000
end


Expand Down
8 changes: 6 additions & 2 deletions lib/mangopay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module MangoPay
class Configuration
attr_accessor :preproduction, :root_url,
:client_id, :client_passphrase,
:temp_dir, :log_file
:temp_dir, :log_file, :http_timeout

def preproduction
@preproduction || false
Expand All @@ -56,6 +56,10 @@ def preproduction
def root_url
@root_url || (@preproduction == true ? "https://api.sandbox.mangopay.com" : "https://api.mangopay.com")
end

def http_timeout
@http_timeout || 10000
end
end

class << self
Expand Down Expand Up @@ -128,7 +132,7 @@ def request(method, url, params={}, filters={}, headers_or_idempotency_key = nil
headers['Idempotency-Key'] = headers_or_idempotency_key if headers_or_idempotency_key != nil
end

res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, :read_timeout => configuration.http_timeout) do |http|
req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, headers)
req.body = JSON.dump(params)
before_request_proc.call(req) if before_request_proc
Expand Down

0 comments on commit 289887b

Please sign in to comment.