[Question] Why did the API change the way the TO field works?
Sending a single email to multiple recipients. (I've almost completed a rewrite from 1.1.6 to 4.0.4). In 1.1.6 I used to be able to pass an array of emails to the TO field and each recipient received an email without seeing each recipient.
This functionality is still available using personalizations, I had to read the source code to understand what was happening the assignment of personalizations does not make it obvious as to how it works.
recipients.each do |recipient|
p = Personalization.new
p.to = Email.new(email: "[email protected]", name: "Example")
mail.personalizations = p # Pushing onto an array, confusing when using equals assignment
end
Closing this question for now but edited to include example.
Chiming in to agree that appending via = is unusual at best, confusing at worst.
If I'm being honest, I have never seen = overloaded this way in Ruby, and I would instead expect it to perform a wholesale replacement of the value of the personalizations attribute.
The idiomatic operator for push, across the standard library and any gem I've used, is <<, commonly nicknamed the "shovel operator". For instance, Ruby's Array and IO classes.
@danieldraper @swifthand,
I will add your votes to this issue: https://github.com/sendgrid/sendgrid-ruby/issues/95
Thanks!