Sha256: 1adb39f109860f356e89d41c078e4608d9683ab1fbd8176bdd2d549b8a3f5b9f

Contents?: true

Size: 769 Bytes

Versions: 3

Compression:

Stored size: 769 Bytes

Contents

module Daywalker
  class Base # :nodoc:
    include HTTParty
    base_uri 'http://services.sunlightlabs.com/api'

    protected

    def self.handle_response(response)
      case response.code.to_i
      when 403 then raise BadApiKeyError
      when 200
        begin
          parse(response.body)
        rescue => e
          raise "Error while parsing #{response.body.inspect} => #{e.inspect}"
        end

      when 400 then handle_bad_request(response.body)
      else          raise "Don't know how to handle code #{response.code.inspect}"
      end
    end

    def self.handle_bad_request(body)
      case body
      when "No Such Object Exists" then raise NotFoundError
      else raise "Don't know how to handle #{body.inspect}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
technicalpickles-daywalker-0.2.0 lib/daywalker/base.rb
technicalpickles-daywalker-0.2.1 lib/daywalker/base.rb
technicalpickles-daywalker-0.3.1 lib/daywalker/base.rb