I could be missing something obvious, but I can't seem to figure out how to update an existing subscriber name in a CreateSend client list using Ruby.
All list details are correct, here's what I have (subscriber already exists in the list):
@subscriber = CreateSend::Subscriber.get(
{:api_key => ENV['CM_API_KEY']}, ENV['CM_LIST_ID'], "me@me.com"
)
According to the tests the update() method should have 4 params:
@subscriber.update("me@me.com", "Name of Person", [], true)
Calling this results in an ArgumentError error: wrong number of arguments (4 for 1).
So, I try calling update by passing in a hash of the updated attributes:
@subscriber.update({"Name" => "New Name"})
No errors occur and the returned @subscriber object contains all the updated fields until you reload it from the API - it's back to the original state.
Reference to the test code:
I've found the answer to this if anyone else experiences the same issue.
CreateSend::Subscriber.get
returns an instance of the Hashie class
, where the update
methods expects one parameter containing a hash. This does not actually update the subscriber details, but only the attributes of the local Hashie instance variable.
CreateSend::Subscriber.new
will return an instance of the Subscriber class where the update
method expects 4 parameters. Calling the update method in this instance will actually perform the update correctly.