lib/openamplify/validations.rb in openamplify-0.2.1 vs lib/openamplify/validations.rb in openamplify-0.2.2

- old
+ new

@@ -1,34 +1,27 @@ module OpenAmplify - class Client - - private - - def validate - raise ArgumentError, "missing api key" if self.api_key.blank? - raise ArgumentError, "missing api url" if self.api_url.blank? - end - end - - class NotAcceptable < StandardError; end class NotSupported < StandardError; end class Forbidden < StandardError; end - class Response - def self.validate(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 + 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?