Sha256: 7083b9fdca2d74194dea2586fe9d2bd11b7937739ee2a308d0e5e5f66c84851e

Contents?: true

Size: 452 Bytes

Versions: 8

Compression:

Stored size: 452 Bytes

Contents

require 'json'

module Bowser
  module HTTP
    class Response
      def initialize xhr
        @xhr = xhr
      end

      def code
        `#@xhr.status`
      end

      def body
        `#@xhr.response`
      end

      def json
        body = self.body
        @json ||= JSON.parse(body) if `body !== undefined`
      end

      def success?
        (200...400).cover? code
      end

      def fail?
        !success?
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bowser-0.2.0 opal/bowser/http/response.rb
bowser-0.1.6 opal/bowser/http/response.rb
bowser-0.1.5 opal/bowser/http/response.rb
bowser-0.1.4 opal/bowser/http/response.rb
bowser-0.1.3 opal/bowser/http/response.rb
bowser-0.1.2 opal/bowser/http/response.rb
bowser-0.1.1 opal/bowser/http/response.rb
bowser-0.1.0 opal/bowser/http/response.rb