Class: Rundeck::Request

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/rundeck/request.rb

Direct Known Subclasses

API

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_tokenObject

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, options = {})
  request_settings(options)
  validate self.class.delete(path, options)
end

#get(path, options = {}) ⇒ Object



12
13
14
15
# File 'lib/rundeck/request.rb', line 12

def get(path, options = {})
  request_settings(options)
  validate self.class.get(path, options)
end

#post(path, options = {}) ⇒ Object



17
18
19
20
# File 'lib/rundeck/request.rb', line 17

def post(path, options = {})
  request_settings(options, path)
  validate self.class.post(path, options)
end

#put(path, options = {}) ⇒ Object



22
23
24
25
# File 'lib/rundeck/request.rb', line 22

def put(path, options = {})
  request_settings(options)
  validate self.class.put(path, options)
end

#set_request_defaults(endpoint, api_token) ⇒ Object

Sets a base_uri and default_params for requests.

Raises:



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, error_message(response)
  when 401 then fail Error::Unauthorized, error_message(response)
  when 403 then fail Error::Forbidden, error_message(response)
  when 404 then fail Error::NotFound, error_message(response)
  when 405 then fail Error::MethodNotAllowed, error_message(response)
  when 409 then fail Error::Conflict, error_message(response)
  when 500 then fail Error::InternalServerError, error_message(response)
  when 502 then fail Error::BadGateway, error_message(response)
  when 503 then fail Error::ServiceUnavailable, error_message(response)
  end

  response.parsed_response
end