redirect_to mailing_lists_path, alert: "Failed to unsubscribe. Please try again later."
end
end
+
+ def resync_from_buttondown
+ result = ButtondownService.new.resync_user(current_user)
+ if result
+ redirect_to mailing_lists_path, notice: "Successfully resynced your information from Buttondown."
+ else
+ redirect_to mailing_lists_path, alert: "Failed to resync from Buttondown. Please try again later."
+ end
+ end
def sync_status
result = ButtondownService.new.update_subscriber(current_user)
user.update(buttondown_status: 'unactivated') if response.success?
response.success?
end
+
+ def resync_user(user)
+ response = self.class.get("/subscribers/#{user.email}", @options)
+
+ if response.success?
+ subscriber_data = JSON.parse(response.body)
+ update_user_from_buttondown(user, subscriber_data)
+ true
+ else
+ false
+ end
+ end
private
user.buttondown_status
end
end
+
+ def update_user_from_buttondown(user, subscriber_data)
+ user.update(
+ buttondown_status: subscriber_data['type'],
+ # Add any other fields you want to sync from Buttondown
+ # For example:
+ # last_buttondown_sync: Time.current,
+ # buttondown_notes: subscriber_data['notes'],
+ # etc.
+ )
+ end
def update_user_buttondown_status(user, response)
buttondown_data = JSON.parse(response.body)
<% end %>
<%= button_to "Unsubscribe", unsubscribe_mailing_lists_path, method: :delete, class: "button danger", data: { confirm: "Are you sure you want to unsubscribe?" } %>
+
+ <%= button_to "Resync from Buttondown", resync_from_buttondown_mailing_lists_path, method: :post, class: "button" %>
<% end %>
<% if @is_paid_user && @buttondown_status != 'gifted' %>
end
end
- resources :mailing_lists, only: [:index] do
+resources :mailing_lists, only: [:index] do
collection do
post 'subscribe'
delete 'unsubscribe'
post 'sync_status'
+ post 'resync_from_buttondown'
end
end
resources :subscriptions, only: [:new, :create, :index]