lib/j7w1/sns_push_client.rb in j7w1-0.0.16 vs lib/j7w1/sns_push_client.rb in j7w1-0.0.17
- old
+ new
@@ -95,10 +95,17 @@
message_value.merge!(sound: sound) unless sound.blank?
payload = payload_for(message_value, platform)
sns_client ||= create_sns_client(sns_configuration || J7W1.configuration)
- sns_client.client.publish(
+ client = sns_client.client
+
+ enabled = (client.get_endpoint_attributes(endpoint_arn: endpoint_arn)[:attributes]['Enabled'] == 'true')
+ unless enabled
+ client.set_endpoint_attributes endpoint_arn: endpoint_arn, attributes: {'Enabled' => 'true'}
+ end
+
+ client.publish(
target_arn: endpoint_arn,
message: payload.to_json,
message_structure: 'json',
)
end