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.
35 36 37 38 |
# File 'lib/papertrail/http_client.rb', line 35 def initialize(ssl) @ssl = ssl @headers = {} end |
Instance Method Details
#basic_auth(login, pass) ⇒ Object
40 41 42 |
# File 'lib/papertrail/http_client.rb', line 40 def basic_auth(login, pass) @headers['Authorization'] = 'Basic ' + ["#{login}:#{pass}"].pack('m').delete("\r\n") end |
#delete(path) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/papertrail/http_client.rb', line 85 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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/papertrail/http_client.rb', line 48 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
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/papertrail/http_client.rb', line 74 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
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/papertrail/http_client.rb', line 63 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
44 45 46 |
# File 'lib/papertrail/http_client.rb', line 44 def token_auth(token) @headers['X-Papertrail-Token'] = token end |