Class: CurlHttpClient

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.logObject

Returns the value of attribute log.



5
6
7
# File 'lib/curl_client.rb', line 5

def log
  @log
end

.timeoutObject

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, options={}) 
  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, options={})
  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

.loggerObject



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, options={}) 
  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, options={}) 
  handle_output(curl(%{ #{url} -XPUT -d #{data} }))
end