Class: Rundeck::Request
- Inherits:
-
Object
- Object
- Rundeck::Request
- Includes:
- HTTParty
- Defined in:
- lib/rundeck/request.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api_token ⇒ Object
Returns the value of attribute api_token.
Instance Method Summary collapse
- #delete(path, options = {}) ⇒ Object
- #get(path, options = {}) ⇒ Object
- #post(path, options = {}) ⇒ Object
- #put(path, options = {}) ⇒ Object
-
#set_request_defaults(endpoint, api_token) ⇒ Object
Sets a base_uri and default_params for requests.
-
#validate(response) ⇒ Object
Checks the response code for common errors.
Instance Attribute Details
#api_token ⇒ Object
Returns the value of attribute api_token.
10 11 12 |
# File 'lib/rundeck/request.rb', line 10 def api_token @api_token end |
Instance Method Details
#delete(path, options = {}) ⇒ Object
27 28 29 30 |
# File 'lib/rundeck/request.rb', line 27 def delete(path, = {}) request_settings() validate self.class.delete(path, ) end |
#get(path, options = {}) ⇒ Object
12 13 14 15 |
# File 'lib/rundeck/request.rb', line 12 def get(path, = {}) request_settings() validate self.class.get(path, ) end |
#post(path, options = {}) ⇒ Object
17 18 19 20 |
# File 'lib/rundeck/request.rb', line 17 def post(path, = {}) request_settings(, path) validate self.class.post(path, ) end |
#put(path, options = {}) ⇒ Object
22 23 24 25 |
# File 'lib/rundeck/request.rb', line 22 def put(path, = {}) request_settings() validate self.class.put(path, ) end |
#set_request_defaults(endpoint, api_token) ⇒ Object
Sets a base_uri and default_params for requests.
52 53 54 55 56 57 58 59 |
# File 'lib/rundeck/request.rb', line 52 def set_request_defaults(endpoint, api_token) unless endpoint fail Error::MissingCredentials, 'Please set an endpoint to API' end @api_token = api_token self.class.base_uri endpoint end |
#validate(response) ⇒ Object
Checks the response code for common errors. Returns parsed response for successful requests.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rundeck/request.rb', line 34 def validate(response) case response.code when 400 then fail Error::BadRequest, (response) when 401 then fail Error::, (response) when 403 then fail Error::Forbidden, (response) when 404 then fail Error::NotFound, (response) when 405 then fail Error::MethodNotAllowed, (response) when 409 then fail Error::Conflict, (response) when 500 then fail Error::InternalServerError, (response) when 502 then fail Error::BadGateway, (response) when 503 then fail Error::ServiceUnavailable, (response) end response.parsed_response end |