Class: Barbeque::SNSSubscriptionService
- Inherits:
-
Object
- Object
- Barbeque::SNSSubscriptionService
- Defined in:
- app/services/barbeque/sns_subscription_service.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#subscribe(sns_subscription) ⇒ Boolean
‘true` if succeeded to subscribe.
- #unsubscribe(sns_subscription) ⇒ Object
Class Method Details
.sns_client ⇒ Object
9 10 11 |
# File 'app/services/barbeque/sns_subscription_service.rb', line 9 def self.sns_client @sns_client ||= Aws::SNS::Client.new end |
.sqs_client ⇒ Object
5 6 7 |
# File 'app/services/barbeque/sns_subscription_service.rb', line 5 def self.sqs_client @sqs_client ||= Aws::SQS::Client.new end |
Instance Method Details
#subscribe(sns_subscription) ⇒ Boolean
Returns ‘true` if succeeded to subscribe.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/services/barbeque/sns_subscription_service.rb', line 15 def subscribe(sns_subscription) if sns_subscription.valid? begin subscribe_topic!(sns_subscription) sns_subscription.save! update_sqs_policy!(sns_subscription) true rescue Aws::SNS::Errors::AuthorizationError sns_subscription.errors[:topic_arn] << 'is not authorized' false rescue Aws::SNS::Errors::NotFound sns_subscription.errors[:topic_arn] << 'is not found' false end else false end end |
#unsubscribe(sns_subscription) ⇒ Object
35 36 37 38 39 40 |
# File 'app/services/barbeque/sns_subscription_service.rb', line 35 def unsubscribe(sns_subscription) sns_subscription.destroy update_sqs_policy!(sns_subscription) unsubscribe_topic!(sns_subscription) nil end |