Sha256: b8be18982d4ce29d284f17da681fc17dc1985dabbd512768a4a35359dfb7eb76

Contents?: true

Size: 845 Bytes

Versions: 2

Compression:

Stored size: 845 Bytes

Contents

module OpenAmplify

  class NotAcceptable < StandardError; end
  class NotSupported  < StandardError; end
  class Forbidden     < StandardError; end


  def self.validate_client!(client)
    raise ArgumentError, "missing api key" if client.api_key.blank?
    raise ArgumentError, "missing api url" if client.api_url.blank?
  end

  def self.validate_response!(response)
    case response.code.to_i
      when 403
        raise Forbidden, "(#{response.code}: #{response.message}) #{response.body}"
      when 405
        raise NotSupported, "(#{response.code}: #{response.message}) #{response.body}"
      when 406
        raise NotAcceptable, "(#{response.code}: #{response.message}) #{response.body}" 
    end
  end


end

class String
  def blank?
    nil? || empty? || strip.empty? 
  end
end

class NilClass
  def blank?
    nil?
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
openamplify-0.2.3 lib/openamplify/validations.rb
openamplify-0.2.2 lib/openamplify/validations.rb