diff --git a/lib/generators/vero_generator.rb b/lib/generators/vero_generator.rb index 9d71519..caf4a9f 100644 --- a/lib/generators/vero_generator.rb +++ b/lib/generators/vero_generator.rb @@ -1,34 +1,12 @@ # frozen_string_literal: true class VeroGenerator < Rails::Generators::Base - class_option :heroku - class_option :api_key - class_option :api_secret - def create_initializer_file - type = options[:heroku] || "standard" - - abort("You must provide an API KEY and API SECRET to proceed.") if options[:heroku].blank? && (options[:api_key].blank? || options[:api_secret].blank?) - create_file "config/initializers/vero.rb", send(:"#{type}_initializer_content") - end - - private - - def standard_initializer_content - <<~END_TEXT - Vero::App.init do |config| - config.api_key = '#{options[:api_key]}' - config.secret = '#{options[:api_secret]}' - end - END_TEXT - end - - def heroku_initializer_content - <<~END_TEXT + create_file("config/initializers/vero.rb", <<~INITIALIZER) Vero::App.init do |config| config.api_key = ENV['VERO_API_KEY'] config.secret = ENV['VERO_API_SECRET'] end - END_TEXT + INITIALIZER end end diff --git a/lib/vero.rb b/lib/vero.rb index 9b8abb4..f22b2ac 100644 --- a/lib/vero.rb +++ b/lib/vero.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "rest-client" -require "vero/utility/ext" module Vero autoload :Config, "vero/config" diff --git a/lib/vero/api/events/track_api.rb b/lib/vero/api/events/track_api.rb index f6850b1..b06d482 100644 --- a/lib/vero/api/events/track_api.rb +++ b/lib/vero/api/events/track_api.rb @@ -14,7 +14,7 @@ def request end def validate! - raise ArgumentError, "Missing :event_name" if options[:event_name].to_s.blank? + raise ArgumentError, "Missing :event_name" if options[:event_name].to_s.empty? raise ArgumentError, ":data must be either nil or a Hash" unless options[:data].nil? || options[:data].is_a?(Hash) end end diff --git a/lib/vero/api/users/delete_api.rb b/lib/vero/api/users/delete_api.rb index e2ce59d..23727f5 100644 --- a/lib/vero/api/users/delete_api.rb +++ b/lib/vero/api/users/delete_api.rb @@ -14,7 +14,7 @@ def request end def validate! - raise ArgumentError, "Missing :id" if options[:id].to_s.blank? + raise ArgumentError, "Missing :id" if options[:id].to_s.empty? end end end diff --git a/lib/vero/api/users/edit_api.rb b/lib/vero/api/users/edit_api.rb index 3ee551f..54dcafb 100644 --- a/lib/vero/api/users/edit_api.rb +++ b/lib/vero/api/users/edit_api.rb @@ -14,7 +14,7 @@ def request end def validate! - raise ArgumentError, "Missing :id or :email" if options[:id].to_s.blank? && options[:email].to_s.blank? + raise ArgumentError, "Missing :id or :email" if options[:id].to_s.empty? && options[:email].to_s.empty? raise ArgumentError, ":changes must be a Hash" unless options[:changes].is_a?(Hash) end end diff --git a/lib/vero/api/users/edit_tags_api.rb b/lib/vero/api/users/edit_tags_api.rb index 3b10f60..37463d5 100644 --- a/lib/vero/api/users/edit_tags_api.rb +++ b/lib/vero/api/users/edit_tags_api.rb @@ -14,7 +14,7 @@ def request end def validate! - raise ArgumentError, "Missing :id or :email" if options[:id].to_s.blank? && options[:email].to_s.blank? + raise ArgumentError, "Missing :id or :email" if options[:id].to_s.empty? && options[:email].to_s.empty? raise ArgumentError, ":add must an Array if present" unless options[:add].nil? || options[:add].is_a?(Array) raise ArgumentError, ":remove must an Array if present" unless options[:remove].nil? || options[:remove].is_a?(Array) raise ArgumentError, "Either :add or :remove must be present" if options[:remove].nil? && options[:add].nil? diff --git a/lib/vero/api/users/reidentify_api.rb b/lib/vero/api/users/reidentify_api.rb index 4893881..0c49949 100644 --- a/lib/vero/api/users/reidentify_api.rb +++ b/lib/vero/api/users/reidentify_api.rb @@ -14,8 +14,8 @@ def request end def validate! - raise ArgumentError, "Missing :id" if options[:id].to_s.blank? - raise ArgumentError, "Missing :new_id" if options[:new_id].to_s.blank? + raise ArgumentError, "Missing :id" if options[:id].to_s.empty? + raise ArgumentError, "Missing :new_id" if options[:new_id].to_s.empty? end end end diff --git a/lib/vero/api/users/resubscribe_api.rb b/lib/vero/api/users/resubscribe_api.rb index 683a948..8dca017 100644 --- a/lib/vero/api/users/resubscribe_api.rb +++ b/lib/vero/api/users/resubscribe_api.rb @@ -14,7 +14,7 @@ def request end def validate! - raise ArgumentError, "Missing :id or :email" if options[:id].to_s.blank? && options[:email].to_s.blank? + raise ArgumentError, "Missing :id or :email" if options[:id].to_s.empty? && options[:email].to_s.empty? end end end diff --git a/lib/vero/api/users/track_api.rb b/lib/vero/api/users/track_api.rb index 6e0dee4..8158036 100644 --- a/lib/vero/api/users/track_api.rb +++ b/lib/vero/api/users/track_api.rb @@ -14,7 +14,7 @@ def request end def validate! - raise ArgumentError, "Missing :id or :email" if options[:id].to_s.blank? && options[:email].to_s.blank? + raise ArgumentError, "Missing :id or :email" if options[:id].to_s.empty? && options[:email].to_s.empty? raise ArgumentError, ":data must be either nil or a Hash" unless options[:data].nil? || options[:data].is_a?(Hash) end end diff --git a/lib/vero/api/users/unsubscribe_api.rb b/lib/vero/api/users/unsubscribe_api.rb index ec309ef..ba2bc1c 100644 --- a/lib/vero/api/users/unsubscribe_api.rb +++ b/lib/vero/api/users/unsubscribe_api.rb @@ -14,7 +14,7 @@ def request end def validate! - raise ArgumentError, "Missing :id or :email" if options[:id].to_s.blank? && options[:email].to_s.blank? + raise ArgumentError, "Missing :id or :email" if options[:id].to_s.empty? && options[:email].to_s.empty? end end end diff --git a/lib/vero/config.rb b/lib/vero/config.rb index 80132e3..b14fdaa 100644 --- a/lib/vero/config.rb +++ b/lib/vero/config.rb @@ -27,10 +27,11 @@ def request_params end def domain - if @domain.blank? + if @domain.nil? || @domain.empty? "https://api.getvero.com" else - %r{https?://.+}.match?(@domain) ? @domain : "http://#{@domain}" + a_domain = @domain.to_s + %r{https?://.+}.match?(a_domain) ? a_domain : "http://#{a_domain}" end end diff --git a/lib/vero/utility/ext.rb b/lib/vero/utility/ext.rb deleted file mode 100644 index d66bf3f..0000000 --- a/lib/vero/utility/ext.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class Object - def blank? - respond_to?(:empty?) ? empty? : !self - end -end