Avoid repeating headers
This commit is contained in:
parent
7a5777c4f7
commit
a553a53b51
1 changed files with 15 additions and 18 deletions
|
|
@ -1,13 +1,19 @@
|
||||||
class MailblusterManager
|
class MailblusterManager
|
||||||
include HTTParty
|
include HTTParty
|
||||||
base_uri 'https://api.mailbluster.com/api/leads/'
|
base_uri 'https://api.mailbluster.com/api/leads/'
|
||||||
|
@@auth_headers = {
|
||||||
|
headers: {
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Authorization' => ENV['MAILBLUSTER_API_KEY']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def query_api(method, user, body)
|
||||||
|
#TODO
|
||||||
|
end
|
||||||
|
|
||||||
def self.create_lead(user)
|
def self.create_lead(user)
|
||||||
options = {
|
options = @@auth_headers.merge({
|
||||||
headers: {
|
|
||||||
'Content-Type' => 'application/json',
|
|
||||||
'Authorization' => ENV['MAILBLUSTER_API_KEY']
|
|
||||||
},
|
|
||||||
body: {
|
body: {
|
||||||
'email' => user.email,
|
'email' => user.email,
|
||||||
'firstName' => user.name,
|
'firstName' => user.name,
|
||||||
|
|
@ -15,35 +21,26 @@ class MailblusterManager
|
||||||
'subscribed' => true,
|
'subscribed' => true,
|
||||||
'tags' => [ENV['OSEM_NAME'] || 'snapcon']
|
'tags' => [ENV['OSEM_NAME'] || 'snapcon']
|
||||||
}.to_json
|
}.to_json
|
||||||
}
|
})
|
||||||
post('/', options).parsed_response
|
post('/', options).parsed_response
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.edit_lead(user, add_tags: [], remove_tags: [], old_email: nil)
|
def self.edit_lead(user, add_tags: [], remove_tags: [], old_email: nil)
|
||||||
options = {
|
options = @@auth_headers.merge({
|
||||||
headers: {
|
|
||||||
'Content-Type' => 'application/json',
|
|
||||||
'Authorization' => ENV['MAILBLUSTER_API_KEY']
|
|
||||||
},
|
|
||||||
body: {
|
body: {
|
||||||
'email' => user.email,
|
'email' => user.email,
|
||||||
'firstName' => user.name,
|
'firstName' => user.name,
|
||||||
'addTags' => add_tags,
|
'addTags' => add_tags,
|
||||||
'removeTags' => remove_tags
|
'removeTags' => remove_tags
|
||||||
}.to_json
|
}.to_json
|
||||||
}
|
})
|
||||||
email_hash = Digest::MD5.hexdigest(old_email.presence || user.email)
|
email_hash = Digest::MD5.hexdigest(old_email.presence || user.email)
|
||||||
put("/#{email_hash}", options).parsed_response
|
put("/#{email_hash}", options).parsed_response
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.delete_lead(user)
|
def self.delete_lead(user)
|
||||||
email_hash = Digest::MD5.hexdigest user.email
|
email_hash = Digest::MD5.hexdigest user.email
|
||||||
options = {
|
options = @@auth_headers
|
||||||
headers: {
|
|
||||||
'Content-Type' => 'application/json',
|
|
||||||
'Authorization' => ENV['MAILBLUSTER_API_KEY']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete("/#{email_hash}", options).parsed_response
|
delete("/#{email_hash}", options).parsed_response
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue