lib/esp_sdk/api.rb in esp_sdk-1.0.5 vs lib/esp_sdk/api.rb in esp_sdk-1.0.6
- old
+ new
@@ -1,12 +1,12 @@
module EspSdk
class Api
attr_reader :end_points, :config
def initialize(options = {})
- fail MissingAttribute, 'Missing required email' if options[:email].blank?
- fail MissingAttribute, 'Missing required password or token' if options[:password].blank? && options[:token].blank?
+ options[:email] ||= options_errors(:email)
+ options_errors(:password) if options[:token].blank? && options[:password].blank?
@config = Configure.new(options)
@end_points = []
define_methods
end
@@ -22,8 +22,12 @@
instance_variable_set(:"@#{name}", EspSdk::EndPoints.const_get(end_point).new(config))
end
@end_points << send(name)
end
+ end
+
+ def options_errors(option)
+ ENV["ESP_#{option.upcase}"] || fail(EspSdk::MissingAttribute, "Missing required #{option}") # rubocop:disable all
end
end
end