Skip to content

Instantly share code, notes, and snippets.

@poctek
Created May 1, 2017 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poctek/32d032c243257b04ef1e8d74dad3d6f5 to your computer and use it in GitHub Desktop.
Save poctek/32d032c243257b04ef1e8d74dad3d6f5 to your computer and use it in GitHub Desktop.
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