Sha256: 77639500a0a62772d9599d2f48250fe178d8d2f697bdc06f44cc82c48134f3ae

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

module Exlibris
  module Aleph
    require 'httparty'
    class Rest
      include HTTParty
      format :xml
      def initialize(uri)
        @uri = uri
        raise "Initialization error in #{self.class}. Missing URI." if @uri.nil?
      end
      def error
        return nil if reply_code == "0000" 
        return "#{reply_text}"
      end
      def reply_code
        return "No response." if @response.nil?
        return (not @response.first.last.kind_of?(Hash) or @response.first.last["reply_code"].nil?) ? "Unexpected response hash." : @response.first.last["reply_code"] if @response.instance_of?(Hash)
        response_match = @response.match(/\<reply-code\>(.+)\<\/reply-code\>/) if @response.instance_of?(String)
        return (response_match.nil?) ? "Unexpected response string." : response_match[1] if @response.instance_of?(String)
        return "Unexpected response type."
      end
      def reply_text
        return "No response." if @response.nil?
        return (not @response.first.last.kind_of?(Hash) or @response.first.last["reply_text"].nil?) ? "Unexpected response hash." : @response.first.last["reply_text"] if @response.instance_of?(Hash)
        response_match = @response.match(/\<reply-text\>(.+)\<\/reply-text\>/) if @response.instance_of?(String)
        return (response_match.nil?) ? "Unexpected response string." : response_match[1] if @response.instance_of?(String)
        return "Unexpected response type."
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
exlibris-aleph-0.0.2 lib/exlibris/aleph/rest.rb
exlibris-aleph-0.0.1 lib/exlibris/aleph/rest.rb