Class: Rest
- Inherits:
-
Object
- Object
- Rest
- Defined in:
- lib/cnos-rbapi/rest_utils.rb
Overview
The Rest class provides a class implementation and methods for executing REST methods such as GET, POST, PUT and DELETE
on the node. This class presents an abstraction
Class Method Summary collapse
-
.delete(conn, url, hdr) ⇒ Object
This API performs DELETE request for the given url and switch connection.
-
.get(conn, url, hdr) ⇒ Object
This API performs GET request for the given url and switch connection.
-
.post(conn, url, hdr, params) ⇒ Object
This API performs POST request for the given url and switch connection.
-
.put(conn, url, hdr, params) ⇒ Object
This API performs PUT request for the given url and switch connection.
Class Method Details
.delete(conn, url, hdr) ⇒ Object
This API performs DELETE request for the given url and switch connection.
parameters: conn - connection object to the node url - URL for the DELETE request hdr - header paramters for the DELETE request
return: JSON response
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/cnos-rbapi/rest_utils.rb', line 99 def self.delete(conn, url, hdr) begin resp = RestClient::Request.execute method: :delete, url: url, headers: hdr, user: conn.getUser, password: conn.getPassword, timeout: 20 ,:verify_ssl => false rescue RestClient::ExceptionWithResponse => err puts err puts err.response.match(/<p>(.+)<\/p>/)[1] end end |
.get(conn, url, hdr) ⇒ Object
This API performs GET request for the given url and switch connection.
parameters: conn - connection object to the node url - URL for the GET request hdr - header paramters for the GET request
return: JSON response
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cnos-rbapi/rest_utils.rb', line 32 def self.get(conn, url, hdr) begin resp = RestClient::Request.execute method: :get, url: url, headers: hdr, user: conn.getUser, password: conn.getPassword, timeout: 20 ,:verify_ssl => false response = JSON.parse(resp) response rescue RestClient::ExceptionWithResponse => err puts err puts err.response.match(/<p>(.+)<\/p>/)[1] end end |
.post(conn, url, hdr, params) ⇒ Object
This API performs POST request for the given url and switch connection.
parameters: conn - connection object to the node url - URL for the POST request hdr - header paramters for the POST request params - JSON body for POST request
return: JSON response
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cnos-rbapi/rest_utils.rb', line 77 def self.post(conn, url, hdr, params) begin resp = RestClient::Request.execute method: :post, url: url, headers: hdr, payload: params, user: conn.getUser, password: conn.getPassword, timeout: 20 ,:verify_ssl => false response = JSON.parse(resp) response rescue RestClient::ExceptionWithResponse => err puts err puts err.response.match(/<p>(.+)<\/p>/)[1] end end |
.put(conn, url, hdr, params) ⇒ Object
This API performs PUT request for the given url and switch connection.
parameters: conn - connection object to the node url - URL for the PUT request hdr - header paramters for the PUT request params - JSON body for POST request
return: JSON response
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cnos-rbapi/rest_utils.rb', line 55 def self.put(conn, url, hdr, params) begin resp = RestClient::Request.execute method: :put, url: url, headers: hdr, payload: params, user: conn.getUser, password: conn.getPassword, timeout: 20 ,:verify_ssl => false response = JSON.parse(resp) response rescue RestClient::ExceptionWithResponse => err puts err puts err.response.match(/<p>(.+)<\/p>/)[1] end end |