Sha256: b59662d22a6a466176c77c147854e40448cd91b3a248b2a693ed5c4f0a759511

Contents?: true

Size: 688 Bytes

Versions: 3

Compression:

Stored size: 688 Bytes

Contents

require 'httparty'

module CampusBooks
  class Base
    include HTTParty
    base_uri 'http://api.campusbooks.com/3/rest'
    format :xml

    protected
      def self.get_response(path, options={})
        res = self.get(path, options)
        case res['response']['status']
          when 'ok'
            return res['response']

          when 'error'
            err_count = res['response']['errors']['error'].length
            raise Error, err_count == 1 ? 'An error' : "#{err_count} errors" +
              " occured while getting path '#{path}' with options #{options.inspect}:\n  " +
              res['response']['errors']['error'].join("\n  ")
        end
      end

  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
mroch-campusbooks-0.1.0 lib/campusbooks/base.rb
mroch-campusbooks-0.2.0 lib/campusbooks/base.rb
campusbooks-0.2.0 lib/campusbooks/base.rb