Created
May 1, 2017 11:11
-
-
Save poctek/32d032c243257b04ef1e8d74dad3d6f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Subscriber < ActiveRecord::Base | |
include ActiveModel::Model | |
attr_accessor :email | |
def subscribed? | |
SendpulseClient::Email.get(email).is_a? Array | |
end | |
def subscribe!(book_id = nil) | |
book_id = SendpulseClient::Addressbook.all.first['id'] unless book_id | |
SendpulseClient::Addressbook.add_clients(book_id, [email]) | |
end | |
def unsubscribe!(book_id = nil) | |
subscriptions = SendpulseClient::Email.get(email) | |
return unless subscriptions.is_a? Array | |
book_id = subscriptions[0]['book_id'] unless book_id | |
SendpulseClient::Addressbook.remove_clients(book_id, [email]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment