Module: Pebblebed::Http

Defined in:
lib/pebblebed/http.rb

Defined Under Namespace

Classes: CurlResult

Class Method Summary collapse

Class Method Details

.delete(url, params, &block) ⇒ Object



74
75
76
77
# File 'lib/pebblebed/http.rb', line 74

def self.delete(url, params, &block)
  url, params = url_and_params_from_args(url, params, &block)      
  handle_curl_response(Curl::Easy.http_delete(url_with_params(url, params)))
end

.get(url = nil, params = nil, &block) ⇒ Object



51
52
53
54
# File 'lib/pebblebed/http.rb', line 51

def self.get(url = nil, params = nil, &block)
  url, params = url_and_params_from_args(url, params, &block)      
  handle_curl_response(Curl::Easy.perform(url_with_params(url, params)))
end

.post(url, params, &block) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/pebblebed/http.rb', line 56

def self.post(url, params, &block)
  url, params = url_and_params_from_args(url, params, &block)
  content_type, body = serialize_params(params)
  handle_curl_response(Curl::Easy.http_post(url.to_s, body) do |curl|
    curl.headers['Accept'] = 'application/json'
    curl.headers['Content-Type'] = content_type
  end)
end

.put(url, params, &block) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/pebblebed/http.rb', line 65

def self.put(url, params, &block)
  url, params = url_and_params_from_args(url, params, &block)      
  content_type, body = serialize_params(params)
  handle_curl_response(Curl::Easy.http_put(url.to_s, body) do |curl|
    curl.headers['Accept'] = 'application/json'
    curl.headers['Content-Type'] = content_type
  end)
end