Class: CurlHttpClient
- Inherits:
-
Object
- Object
- CurlHttpClient
- Defined in:
- lib/curl_client.rb
Class Attribute Summary collapse
-
.log ⇒ Object
Returns the value of attribute log.
-
.timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
- .curl(cmd) ⇒ Object
- .delete(url, options = {}) ⇒ Object
-
.get(url, options = {}) ⇒ Object
Even though we don’t need the options, the REST client does.
- .handle_output(output) ⇒ Object
- .logger ⇒ Object
- .post(url, data, options = {}) ⇒ Object
- .put(url, data, options = {}) ⇒ Object
Class Attribute Details
.log ⇒ Object
Returns the value of attribute log.
5 6 7 |
# File 'lib/curl_client.rb', line 5 def log @log end |
.timeout ⇒ Object
Returns the value of attribute timeout.
4 5 6 |
# File 'lib/curl_client.rb', line 4 def timeout @timeout end |
Class Method Details
.curl(cmd) ⇒ Object
30 31 32 33 34 |
# File 'lib/curl_client.rb', line 30 def self.curl(cmd) cmd = "curl -s --insecure --connect-timeout #{@timeout} #{cmd} 2>&1" @log.debug cmd if @log `#{cmd}` end |
.delete(url, options = {}) ⇒ Object
26 27 28 |
# File 'lib/curl_client.rb', line 26 def self.delete(url, ={}) handle_output(curl(%{ #{url} -XDELETE})) end |
.get(url, options = {}) ⇒ Object
Even though we don’t need the options, the REST client does. So we have this for consistency.
14 15 16 |
# File 'lib/curl_client.rb', line 14 def self.get(url, ={}) handle_output(curl(url)) end |
.handle_output(output) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/curl_client.rb', line 36 def self.handle_output(output) if output =~ /^Error/ logger.error output raise output else output end end |
.logger ⇒ Object
10 |
# File 'lib/curl_client.rb', line 10 def self.logger; @logger ||= Logger.new(STDOUT); end |
.post(url, data, options = {}) ⇒ Object
18 19 20 |
# File 'lib/curl_client.rb', line 18 def self.post(url, data, ={}) handle_output(curl(%{ #{url} -d "#{data}" })) end |
.put(url, data, options = {}) ⇒ Object
22 23 24 |
# File 'lib/curl_client.rb', line 22 def self.put(url, data, ={}) handle_output(curl(%{ #{url} -XPUT -d #{data} })) end |