Class: Delphix::WebRequest
- Inherits:
-
Object
- Object
- Delphix::WebRequest
- Includes:
- Utils
- Defined in:
- lib/delphix/web_request.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #add_header(name, value) ⇒ Object
-
#initialize(method, url, headers = {}, body = nil) ⇒ WebRequest
constructor
A new instance of WebRequest.
Methods included from Utils
Constructor Details
#initialize(method, url, headers = {}, body = nil) ⇒ WebRequest
Returns a new instance of WebRequest.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/delphix/web_request.rb', line 53 def initialize(method, url, headers = {}, body = nil) @method = method if (method == :get) if body.is_a?(Hash) && body.length > 0 if url.include? '?' url += '&' else url += '?' end uri = Addressable::URI.new uri.query_values = body url += uri.query end else @body = body end unless url =~ URI.regexp raise 'Invalid URL: ' + url end @url = url.gsub(/\s+/, '%20') @headers = { 'Date' => utc_httpdate, 'Request-ID' => request_id } headers.each_pair { |key, value| @headers[key.downcase] = value } Delphix.last_request = { headers: @headers, method: @method, url: @url } begin Delphix.last_request[:body] = JSON.parse(@body) if body.length > 2 rescue Exception end end |
Instance Attribute Details
#all ⇒ Object (readonly)
Returns the value of attribute all.
47 48 49 |
# File 'lib/delphix/web_request.rb', line 47 def all @all end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
43 44 45 |
# File 'lib/delphix/web_request.rb', line 43 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
38 39 40 |
# File 'lib/delphix/web_request.rb', line 38 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
30 31 32 |
# File 'lib/delphix/web_request.rb', line 30 def method @method end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
34 35 36 |
# File 'lib/delphix/web_request.rb', line 34 def url @url end |
Instance Method Details
#add_header(name, value) ⇒ Object
49 50 51 |
# File 'lib/delphix/web_request.rb', line 49 def add_header(name, value) @headers[name] = value end |