Sha256: bcd36fe40dfb072f294a40fc674e83aa762c8610bc3a48b1f5b4624d02eee28e

Contents?: true

Size: 1.13 KB

Versions: 15

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Uffizzi
  module ResponseHelper
    class << self
      def created?(response)
        response[:code] == Net::HTTPCreated
      end

      def unprocessable_entity?(response)
        response[:code] == Net::HTTPUnprocessableEntity
      end

      def not_found?(response)
        response[:code] == Net::HTTPNotFound
      end

      def forbidden?(response)
        response[:code] == Net::HTTPForbidden
      end

      def no_content?(response)
        response[:code] == Net::HTTPNoContent
      end

      def ok?(response)
        response[:code] == Net::HTTPOK
      end

      def handle_failed_response(response)
        print_errors(response[:body][:errors])
      end

      def handle_invalid_compose_response(response)
        print_errors(response[:body][:compose_file][:payload][:errors])
      end

      private

      def print_errors(errors)
        errors.each_key do |key|
          if errors[key].is_a?(Array)
            errors[key].each { |error_message| Uffizzi.ui.say(error_message) }
          else
            Uffizzi.ui.say(errors[key])
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
uffizzi-cli-0.6.0 lib/uffizzi/response_helper.rb
uffizzi-cli-0.5.2 lib/uffizzi/response_helper.rb
uffizzi-cli-0.5.1 lib/uffizzi/response_helper.rb
uffizzi-cli-0.5.0 lib/uffizzi/response_helper.rb
uffizzi-cli-0.4.0 lib/uffizzi/response_helper.rb
uffizzi-cli-0.3.8 lib/uffizzi/response_helper.rb
uffizzi-cli-0.3.7 lib/uffizzi/response_helper.rb
uffizzi-cli-0.3.6 lib/uffizzi/response_helper.rb
uffizzi-cli-0.3.5 lib/uffizzi/response_helper.rb
uffizzi-cli-0.3.4 lib/uffizzi/response_helper.rb
uffizzi-cli-0.3.3 lib/uffizzi/response_helper.rb
uffizzi-cli-0.3.2 lib/uffizzi/response_helper.rb
uffizzi-cli-0.2.2 lib/uffizzi/response_helper.rb
uffizzi-cli-0.2.1 lib/uffizzi/response_helper.rb
uffizzi-cli-0.2.0 lib/uffizzi/response_helper.rb