PERF: only require aws-sdk-sns gem when it's being used

PERF: only require aws-sdk-sns gem when it’s being used

diff --git a/app/jobs/regular/confirm_sns_subscription.rb b/app/jobs/regular/confirm_sns_subscription.rb
index 8019ea6..f4815df 100644
--- a/app/jobs/regular/confirm_sns_subscription.rb
+++ b/app/jobs/regular/confirm_sns_subscription.rb
@@ -1,5 +1,3 @@
-require "aws-sdk-sns"
-
 module Jobs
 
   class ConfirmSnsSubscription < Jobs::Base
@@ -8,8 +6,9 @@ module Jobs
     def execute(args)
       return unless raw  = args[:raw].presence
       return unless json = args[:json].presence
-
       return unless subscribe_url = json["SubscribeURL"].presence
+
+      require "aws-sdk-sns"
       return unless Aws::SNS::MessageVerifier.new.authentic?(raw)
 
       # confirm subscription by visiting the URL
diff --git a/app/jobs/regular/process_sns_notification.rb b/app/jobs/regular/process_sns_notification.rb
index feb65b6..7a3eadb 100644
--- a/app/jobs/regular/process_sns_notification.rb
+++ b/app/jobs/regular/process_sns_notification.rb
@@ -1,5 +1,3 @@
-require "aws-sdk-sns"
-
 module Jobs
 
   class ProcessSnsNotification < Jobs::Base
@@ -14,6 +12,7 @@ module Jobs
       return unless message_id = message.dig("mail", "messageId").presence
       return unless bounce_type = message.dig("bounce", "bounceType").presence
 
+      require "aws-sdk-sns"
       return unless Aws::SNS::MessageVerifier.new.authentic?(raw)
 
       message.dig("bounce", "bouncedRecipients").each do |r|

GitHub sha: fc14847c

1 Like