DRY query_api in mailbluster_manager
This commit is contained in:
parent
a553a53b51
commit
6b108043e1
1 changed files with 14 additions and 17 deletions
|
|
@ -8,39 +8,36 @@ class MailblusterManager
|
|||
}
|
||||
}
|
||||
|
||||
def query_api(method, user, body)
|
||||
def query_api(method, path, body)
|
||||
#TODO
|
||||
options = @@auth_headers.merge({
|
||||
body: body.to_json
|
||||
})
|
||||
method(path, options).parsed_response
|
||||
end
|
||||
|
||||
def self.create_lead(user)
|
||||
options = @@auth_headers.merge({
|
||||
body: {
|
||||
'email' => user.email,
|
||||
'firstName' => user.name,
|
||||
'overrideExisting' => true,
|
||||
'subscribed' => true,
|
||||
'tags' => [ENV['OSEM_NAME'] || 'snapcon']
|
||||
}.to_json
|
||||
query_api(post, '/', {
|
||||
'email' => user.email,
|
||||
'firstName' => user.name,
|
||||
'overrideExisting' => true,
|
||||
'subscribed' => true,
|
||||
'tags' => [ENV['OSEM_NAME'] || 'snapcon']
|
||||
})
|
||||
post('/', options).parsed_response
|
||||
end
|
||||
|
||||
def self.edit_lead(user, add_tags: [], remove_tags: [], old_email: nil)
|
||||
options = @@auth_headers.merge({
|
||||
body: {
|
||||
email_hash = Digest::MD5.hexdigest(old_email.presence || user.email)
|
||||
query_api(put, "/#{email_hash}", {
|
||||
'email' => user.email,
|
||||
'firstName' => user.name,
|
||||
'addTags' => add_tags,
|
||||
'removeTags' => remove_tags
|
||||
}.to_json
|
||||
})
|
||||
email_hash = Digest::MD5.hexdigest(old_email.presence || user.email)
|
||||
put("/#{email_hash}", options).parsed_response
|
||||
end
|
||||
|
||||
def self.delete_lead(user)
|
||||
email_hash = Digest::MD5.hexdigest user.email
|
||||
options = @@auth_headers
|
||||
delete("/#{email_hash}", options).parsed_response
|
||||
query_api(delete, "/#{email_hash}", {})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue