Make body argument for query_api more clear

This commit is contained in:
CactusPuppy 2021-04-01 23:10:43 -07:00
parent 9361f0bfd5
commit d780c2a6b3
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82

View file

@ -8,33 +8,33 @@ class MailblusterManager
}
}
def self.query_api(method, path, body)
def self.query_api(method, path, body: {})
options = @auth_headers.merge(body: body.to_json)
send(method, path, options).parsed_response
end
def self.create_lead(user)
query_api(:post, '/',
'email' => user.email,
'firstName' => user.name,
'overrideExisting' => true,
'subscribed' => true,
'tags' => [ENV['OSEM_NAME'] || 'snapcon']
)
query_api(:post, '/', body: {
'email' => user.email,
'firstName' => user.name,
'overrideExisting' => true,
'subscribed' => true,
'tags' => [ENV['OSEM_NAME'] || 'snapcon']
})
end
def self.edit_lead(user, add_tags: [], remove_tags: [], old_email: nil)
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
)
query_api(:put, "/#{email_hash}", body: {
'email' => user.email,
'firstName' => user.name,
'addTags' => add_tags,
'removeTags' => remove_tags
})
end
def self.delete_lead(user)
email_hash = Digest::MD5.hexdigest user.email
query_api(:delete, "/#{email_hash}", {})
query_api(:delete, "/#{email_hash}")
end
end