Class: Papertrail::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/papertrail/http_client.rb

Constant Summary collapse

ESCAPE_RE =
/[^a-zA-Z0-9 .~_-]/

Instance Method Summary collapse

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(, pass)
  @headers['Authorization'] = 'Basic ' + ["#{}:#{pass}"].pack('m').delete("\r\n")
end

#delete(path) ⇒ Object



56
57
58
# File 'lib/papertrail/http_client.rb', line 56

def delete(path)
  on_complete(https.delete(request_uri(path), @headers))
end

#get(path, params = {}) ⇒ Object



41
42
43
44
45
46
# File 'lib/papertrail/http_client.rb', line 41

def get(path, params = {})
  if params.size > 0
    path = "#{path}?#{build_nested_query(params)}"
  end
  on_complete(https.get(request_uri(path), @headers))
end

#post(path, params) ⇒ Object



52
53
54
# File 'lib/papertrail/http_client.rb', line 52

def post(path, params)
  on_complete(https.post(request_uri(path), build_nested_query(params), @headers))
end

#put(path, params) ⇒ Object



48
49
50
# File 'lib/papertrail/http_client.rb', line 48

def put(path, params)
  on_complete(https.put(request_uri(path), build_nested_query(params), @headers))
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