Sha256: c579caba298af25aba94b1a8604646eca30e1d38ebb45d64a6eec86c61247948

Contents?: true

Size: 643 Bytes

Versions: 3

Compression:

Stored size: 643 Bytes

Contents

module VNCPostAPI
  class ResourceInvalid < ActiveResource::ClientError
    def to_s
      body = JSON.parse(response.body)
      if body["Message"]
        message = "Failed.".dup
        message << " Message: #{body["Message"]}"
        message
      else
        super
      end
    end
  end

  class Connection < ActiveResource::Connection
    private

    def request_failed?(response)
      body = JSON.parse(response.body)
      body["Result"] == 2
    rescue JSON::ParserError
      false
    end

    def handle_response(response)
      raise(ResourceInvalid.new(response)) if request_failed?(response)
      super
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vncpost_api-0.4.0 lib/vncpost_api/connection.rb
vncpost_api-0.3.1 lib/vncpost_api/connection.rb
vncpost_api-0.3.0 lib/vncpost_api/connection.rb