Sha256: 45470d421310e4cf95a6739a2fec479a953aa3d53f51ddb1cccabb5b3c560837

Contents?: true

Size: 781 Bytes

Versions: 3

Compression:

Stored size: 781 Bytes

Contents

require 'json'

module Qualtrics
	class Response

    def initialize(raw_response)
      @raw_response = raw_response
      if status != 200
        raise Qualtrics::ServerErrorEncountered, error_message
      end
    end

    def success?
      body['Meta'].nil? ? false : body['Meta']['Status'] == 'Success'
    end

    def result
      body['Result'].nil? ? {} : body['Result']
    end

    def status
      @raw_response.status
    end

    protected

    def body
      if @body.nil?
        if @raw_response.body == ''
          @body = {}
        else
          @body = JSON.parse(@raw_response.body)
        end
      end
      @body
    end

    private
    def error_message
      body['Meta'].nil? ? 'No error message' : body['Meta']['ErrorMessage']
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
qualtrics-0.5.7 lib/qualtrics/response.rb
qualtrics-0.5.6 lib/qualtrics/response.rb
qualtrics-0.5.5 lib/qualtrics/response.rb