Module: Uffizzi::ResponseHelper
- Defined in:
- lib/uffizzi/response_helper.rb
Class Method Summary collapse
- .created?(response) ⇒ Boolean
- .forbidden?(response) ⇒ Boolean
- .get_response_errors(response) ⇒ Object
- .handle_failed_response(response, addtional_errors = []) ⇒ Object
- .handle_invalid_compose_response(response) ⇒ Object
- .no_content?(response) ⇒ Boolean
- .not_found?(response) ⇒ Boolean
- .ok?(response) ⇒ Boolean
- .unprocessable_entity?(response) ⇒ Boolean
Class Method Details
.created?(response) ⇒ Boolean
6 7 8 |
# File 'lib/uffizzi/response_helper.rb', line 6 def created?(response) response[:code] == Net::HTTPCreated end |
.forbidden?(response) ⇒ Boolean
18 19 20 |
# File 'lib/uffizzi/response_helper.rb', line 18 def forbidden?(response) response[:code] == Net::HTTPForbidden end |
.get_response_errors(response) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/uffizzi/response_helper.rb', line 47 def get_response_errors(response) return response if response.is_a?(Array) return [response.to_s] unless response.is_a?(Hash) body = response.fetch(:body, response.to_s) return [body.to_s] unless body.is_a?(Hash) errors = body.fetch(:errors, body.to_s) return [errors.to_s] unless [Hash, Array].include?(errors.class) errors end |
.handle_failed_response(response, addtional_errors = []) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/uffizzi/response_helper.rb', line 30 def handle_failed_response(response, addtional_errors = []) errors = get_response_errors(response) common_msg = errors_to_string(errors) addtional_msg = errors_to_string(addtional_errors) = [common_msg, addtional_msg] .reject { |m| m == '' } .join("\n") .concat("\n") raise Uffizzi::ServerResponseError.new() end |
.handle_invalid_compose_response(response) ⇒ Object
42 43 44 45 |
# File 'lib/uffizzi/response_helper.rb', line 42 def handle_invalid_compose_response(response) = errors_to_string(response[:body][:compose_file][:payload][:errors]) raise Uffizzi::ServerResponseError.new() end |
.no_content?(response) ⇒ Boolean
22 23 24 |
# File 'lib/uffizzi/response_helper.rb', line 22 def no_content?(response) response[:code] == Net::HTTPNoContent end |
.not_found?(response) ⇒ Boolean
14 15 16 |
# File 'lib/uffizzi/response_helper.rb', line 14 def not_found?(response) response[:code] == Net::HTTPNotFound end |
.ok?(response) ⇒ Boolean
26 27 28 |
# File 'lib/uffizzi/response_helper.rb', line 26 def ok?(response) response[:code] == Net::HTTPOK end |
.unprocessable_entity?(response) ⇒ Boolean
10 11 12 |
# File 'lib/uffizzi/response_helper.rb', line 10 def unprocessable_entity?(response) response[:code] == Net::HTTPUnprocessableEntity end |