Class: Workarea::Api::Curl
- Inherits:
-
Struct
- Object
- Struct
- Workarea::Api::Curl
- Defined in:
- lib/workarea/api/curl.rb
Overview
This class stolen from Rspec Api Documentation
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#host ⇒ Object
Returns the value of attribute host.
-
#method ⇒ Object
Returns the value of attribute method.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #delete ⇒ Object
- #get ⇒ Object
- #get_data ⇒ Object
- #head ⇒ Object
- #output(config_host, config_headers_to_filer = nil) ⇒ Object
- #patch ⇒ Object
- #post ⇒ Object
- #post_data ⇒ Object
- #put ⇒ Object
- #url ⇒ Object
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data
4 5 6 |
# File 'lib/workarea/api/curl.rb', line 4 def data @data end |
#headers ⇒ Object
Returns the value of attribute headers
4 5 6 |
# File 'lib/workarea/api/curl.rb', line 4 def headers @headers end |
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/workarea/api/curl.rb', line 5 def host @host end |
#method ⇒ Object
Returns the value of attribute method
4 5 6 |
# File 'lib/workarea/api/curl.rb', line 4 def method @method end |
#path ⇒ Object
Returns the value of attribute path
4 5 6 |
# File 'lib/workarea/api/curl.rb', line 4 def path @path end |
Instance Method Details
#delete ⇒ Object
29 30 31 |
# File 'lib/workarea/api/curl.rb', line 29 def delete "curl \"#{url}\" #{post_data} -X DELETE #{headers}" end |
#get ⇒ Object
17 18 19 |
# File 'lib/workarea/api/curl.rb', line 17 def get "curl -g \"#{url}#{get_data}\" -X GET #{headers}" end |
#get_data ⇒ Object
51 52 53 |
# File 'lib/workarea/api/curl.rb', line 51 def get_data "?#{data}" unless data.blank? end |
#head ⇒ Object
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 |
#patch ⇒ Object
33 34 35 |
# File 'lib/workarea/api/curl.rb', line 33 def patch "curl \"#{url}\" #{post_data} -X PATCH #{headers}" end |
#post ⇒ Object
13 14 15 |
# File 'lib/workarea/api/curl.rb', line 13 def post "curl \"#{url}\" #{post_data} -X POST #{headers}" end |
#post_data ⇒ Object
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 |
#put ⇒ Object
25 26 27 |
# File 'lib/workarea/api/curl.rb', line 25 def put "curl \"#{url}\" #{post_data} -X PUT #{headers}" end |
#url ⇒ Object
37 38 39 |
# File 'lib/workarea/api/curl.rb', line 37 def url "#{host}#{path}" end |