Class: Workarea::Api::Curl

Inherits:
Struct
  • Object
show all
Defined in:
lib/workarea/api/curl.rb

Overview

This class stolen from Rspec Api Documentation

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



4
5
6
# File 'lib/workarea/api/curl.rb', line 4

def data
  @data
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



4
5
6
# File 'lib/workarea/api/curl.rb', line 4

def headers
  @headers
end

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/workarea/api/curl.rb', line 5

def host
  @host
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



4
5
6
# File 'lib/workarea/api/curl.rb', line 4

def method
  @method
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



4
5
6
# File 'lib/workarea/api/curl.rb', line 4

def path
  @path
end

Instance Method Details

#deleteObject



29
30
31
# File 'lib/workarea/api/curl.rb', line 29

def delete
  "curl \"#{url}\" #{post_data} -X DELETE #{headers}"
end

#getObject



17
18
19
# File 'lib/workarea/api/curl.rb', line 17

def get
  "curl -g \"#{url}#{get_data}\" -X GET #{headers}"
end

#get_dataObject



51
52
53
# File 'lib/workarea/api/curl.rb', line 51

def get_data
  "?#{data}" unless data.blank?
end

#headObject



21
22
23
# File 'lib/workarea/api/curl.rb', line 21

def head
  "curl \"#{url}#{get_data}\" -X HEAD #{headers}"
end

#output(config_host, config_headers_to_filer = nil) ⇒ Object



7
8
9
10
11
# File 'lib/workarea/api/curl.rb', line 7

def output(config_host, config_headers_to_filer = nil)
  self.host = config_host
  @config_headers_to_filer = Array(config_headers_to_filer)
  send(method.downcase)
end

#patchObject



33
34
35
# File 'lib/workarea/api/curl.rb', line 33

def patch
  "curl \"#{url}\" #{post_data} -X PATCH #{headers}"
end

#postObject



13
14
15
# File 'lib/workarea/api/curl.rb', line 13

def post
  "curl \"#{url}\" #{post_data} -X POST #{headers}"
end

#post_dataObject



55
56
57
58
# File 'lib/workarea/api/curl.rb', line 55

def post_data
  escaped_data = data.to_s.gsub("'", '\\u0027')
  "-d '#{escaped_data}'"
end

#putObject



25
26
27
# File 'lib/workarea/api/curl.rb', line 25

def put
  "curl \"#{url}\" #{post_data} -X PUT #{headers}"
end

#urlObject



37
38
39
# File 'lib/workarea/api/curl.rb', line 37

def url
  "#{host}#{path}"
end