Class: ICWS::Client
- Inherits:
-
Object
- Object
- ICWS::Client
- Defined in:
- lib/icws/icwsclient.rb
Overview
REST wrapper around the ICWS connection. This class handles setting the proper cookies and headers for each request.
Instance Method Summary collapse
-
#delete(url, headers = {}) ⇒ Object
Makes a DELETE call to the server.
-
#get(url, headers = {}) ⇒ Object
Makes a GET call to the server.
-
#initialize(connection) ⇒ Client
constructor
Creates a new ICWS Client.
-
#post(url, body, headers = {}) ⇒ Object
Makes a POST call to the server.
-
#put(url, body, headers = {}) ⇒ Object
Makes a PUT call to the server.
Constructor Details
#initialize(connection) ⇒ Client
Creates a new ICWS Client
Parameters:
- connection
-
ICWS::Connection instance
15 16 17 18 19 |
# File 'lib/icws/icwsclient.rb', line 15 def initialize(connection) @connection = connection headers = {:Cookie => @connection.,"ININ-ICWS-CSRF-Token" => @connection.token} @http_resource = RestClient::Resource.new(@connection.base_uri, :headers => headers) end |
Instance Method Details
#delete(url, headers = {}) ⇒ Object
Makes a DELETE call to the server.
Parameters:
- url
-
The Url to call the DELETE On
- headers
-
Optional additional headers to send
80 81 82 |
# File 'lib/icws/icwsclient.rb', line 80 def delete(url, headers={}) @http_resource[url].delete headers end |
#get(url, headers = {}) ⇒ Object
Makes a GET call to the server.
Parameters:
- url
-
The Url to call the GET On
- headers
-
Optional additional headers to send
Returns:
The response from the server
67 68 69 |
# File 'lib/icws/icwsclient.rb', line 67 def get(url, headers={}) JSON.parse @http_resource[url].get headers end |
#post(url, body, headers = {}) ⇒ Object
Makes a POST call to the server.
Parameters:
- url
-
The Url to call the POST On
- headers
-
Optional additional headers to send
Returns:
The response from the server
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/icws/icwsclient.rb', line 33 def post(url, body, headers={}) begin result = nil if body != nil result = @http_resource[url].post body.to_json, headers else result = @http_resource[url].post "", headers end if(result != nil && result != '') JSON.parse result else return nil end rescue => e puts e.inspect throw e end end |
#put(url, body, headers = {}) ⇒ Object
Makes a PUT call to the server.
Parameters:
- url
-
The Url to call the PUT On
- headers
-
Optional additional headers to send
Returns:
The response from the server
96 97 98 99 100 101 102 103 104 |
# File 'lib/icws/icwsclient.rb', line 96 def put(url, body, headers={}) begin @http_resource[url].put body.to_json, headers rescue => e puts e.inspect throw e end end |