Class: Papertrail::HttpClient
- Inherits:
-
Object
- Object
- Papertrail::HttpClient
- Defined in:
- lib/papertrail/http_client.rb
Constant Summary collapse
- ESCAPE_RE =
/[^a-zA-Z0-9 .~_-]/
Instance Method Summary collapse
- #basic_auth(login, pass) ⇒ Object
- #delete(path) ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(ssl) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(path, params) ⇒ Object
- #put(path, params) ⇒ Object
- #token_auth(token) ⇒ Object
Constructor Details
#initialize(ssl) ⇒ HttpClient
Returns a new instance of HttpClient.
28 29 30 31 |
# File 'lib/papertrail/http_client.rb', line 28 def initialize(ssl) @ssl = ssl @headers = {} end |
Instance Method Details
#basic_auth(login, pass) ⇒ Object
33 34 35 |
# File 'lib/papertrail/http_client.rb', line 33 def basic_auth(login, pass) @headers['Authorization'] = 'Basic ' + ["#{login}:#{pass}"].pack('m').delete("\r\n") end |
#delete(path) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/papertrail/http_client.rb', line 78 def delete(path) attempts = 0 begin on_complete(https.delete(request_uri(path), @headers)) rescue SystemCallError, Net::HTTPFatalError => e attempts += 1 retry if (attempts < 3) raise e end end |
#get(path, params = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/papertrail/http_client.rb', line 41 def get(path, params = {}) if params.size > 0 path = "#{path}?#{build_nested_query(params)}" end attempts = 0 begin on_complete(https.get(request_uri(path), @headers)) rescue SystemCallError, Net::HTTPFatalError => e sleep 5.0 attempts += 1 retry if (attempts < 3) raise e end end |
#post(path, params) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/papertrail/http_client.rb', line 67 def post(path, params) attempts = 0 begin on_complete(https.post(request_uri(path), build_nested_query(params), @headers)) rescue SystemCallError, Net::HTTPFatalError => e attempts += 1 retry if (attempts < 3) raise e end end |
#put(path, params) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/papertrail/http_client.rb', line 56 def put(path, params) attempts = 0 begin on_complete(https.put(request_uri(path), build_nested_query(params), @headers)) rescue SystemCallError, Net::HTTPFatalError => e attempts += 1 retry if (attempts < 3) raise e end end |
#token_auth(token) ⇒ Object
37 38 39 |
# File 'lib/papertrail/http_client.rb', line 37 def token_auth(token) @headers['X-Papertrail-Token'] = token end |