Skip to content

Instantly share code, notes, and snippets.

@juliend2
Created August 10, 2012 17:00
Show Gist options
  • Save juliend2/3315624 to your computer and use it in GitHub Desktop.
Save juliend2/3315624 to your computer and use it in GitHub Desktop.
def update_cakemail(user,nom,prenom,email,listid,postalcode)
#Find the user in the list to see if he already exist
findPars = CakeLibrary::CakeHash.new()
findPars['client_id'] = CLIENT_ID
findPars["user_key"] = user["user_key"].to_s
findPars["list_id"] = listid
findPars["limit"] = 1
findPars["offset"] = 0
findPars["query"] = '`email` LIKE "%' + email + '"'
res = CakeLibrary::CakeList.Search(findPars)
if(res["records"])
record_id = res["records"][0]["id"]
# Update the postalcode
upPars = CakeLibrary::CakeHash.new()
upPars["user_key"] = user["user_key"].to_s
upPars['client_id'] = CLIENT_ID
upPars["list_id"] = listid
upPars["record_id"] = record_id
upPars["data"] = CakeLibrary::CakeHash.new()
upPars["data"]["codepostal"] = postalcode
record = CakeLibrary::CakeList.UpdateRecord(upPars)
else
# Create the user the list
listPars = CakeLibrary::CakeHash.new()
listPars["user_key"] = user["user_key"].to_s
listPars['client_id'] = CLIENT_ID
listPars["list_id"] = listid
listPars["record"] = CakeLibrary::CakeHash.new()
listPars["record"][0] = CakeLibrary::CakeHash.new()
listPars["record"][0]["prenom"] = prenom
listPars["record"][0]["nom"] = nom
listPars["record"][0]["email"] = email
listPars["record"][0]["codepostal"] = postalcode
listPars["record"][0]["key"] = Digest::MD5.hexdigest(email)
list = CakeLibrary::CakeList.Import(listPars)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment