Sha256: d325f66dde567eb2e14537233c214ebbb1813ee9f62d44f44e27644f0e20da51

Contents?: true

Size: 729 Bytes

Versions: 2

Compression:

Stored size: 729 Bytes

Contents

module HaravanTheme
  class APIChecker
    class APIResult
      OK = 200
      UNAUTHORIZED = 401
      SERVER_ERROR_CODES = (500..599)
      
      attr_reader :response
      def initialize(http_response)
        @response = http_response
      end

      def accessed_api?
        response.code == OK
      end

      def cannot_access_api?
        !accessed_api?
      end

      def invalid_config?
        response.code == UNAUTHORIZED
      end

      def api_down?
        SERVER_ERROR_CODES.include?(response.code)
      end
    end

    def initialize(client)
      @client = client
    end

    def test_connectivity
      return APIResult.new(client.get_index)
    end

    private
    attr_reader :client
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
haravan_theme-0.0.26 lib/haravan_theme/api_checker.rb
haravan_theme-0.0.25 lib/haravan_theme/api_checker.rb