Sha256: 2b16b659a61ad0722398521799bf0d65f22216e5d7d60cb2f35dafb80615257a

Contents?: true

Size: 673 Bytes

Versions: 2

Compression:

Stored size: 673 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 BadApiKey
      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)
      raise "Don't know how to handle #{body.inspect}"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
technicalpickles-daywalker-0.1.1 lib/daywalker/base.rb
technicalpickles-daywalker-0.1.2 lib/daywalker/base.rb