CamelCase vs. snake_case

179 views
Skip to first unread message

Robert Rawlins

unread,
Feb 15, 2013, 5:23:15 AM2/15/13
to postmark-ap...@googlegroups.com
Hello Guys,

I'm doing some Rails integration with Postmark Inbound at the moment, and one bone of contention at the moment is related to casing of attribute names.

According to best practice, Rails apps are built on snake_casing for it's attribute names, all lowercase and underscores for spaces.

However, the inbound JSON from postmark is CamelCased.

This means that I'm unable to use handy features like mass-assignment within the webhook to populate an active record with the inbound information as Rails is unable to pair 'From' with 'from' etc.

Is anyone able to offer a suggestion on how they're dealing with this?

Thanks,

Rob

Milan Gornik

unread,
Feb 15, 2013, 6:51:48 AM2/15/13
to postmark-ap...@googlegroups.com

Hi Rob,

I'm not too handy with Rails practices, so I can suggest something else which could be done on Postmark side. If the easiest solution is to change the format that Postmark posts, we can introduce per-server switch that would regulate which casing convention to use. So, if it is set to default, it would use current CamelCase, and if it is set to alternative value it could produce JSONs with snake_casing. You would define this once, after creating a server in Postmark and all JSONs posted to your web app would follow the selected convention. Let me know what you think. Any other suggestions are welcome, as well.

Regards,
Milan Gornik
Postmark developer, Wildbit

Robert Rawlins

unread,
Feb 15, 2013, 7:23:39 AM2/15/13
to postmark-ap...@googlegroups.com
Hi Milan,

Thanks for getting back to me. I like the idea of being able to choose the formatting within PM, however, I wonder if that's creating your guys a lot of work for little gain on our end? I'm probably quite a niche use-case.

For the moment I'm augmenting the incoming parameters to match the case I require before populating the object, like so:


This leans on another gist to snake_case all of the parameters.


Although this feels a little jacky it actually seems to work quite nicely.

--
You received this message because you are subscribed to the Google Groups "Postmark API Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to postmark-api-deve...@googlegroups.com.
To post to this group, send email to postmark-ap...@googlegroups.com.
Visit this group at http://groups.google.com/group/postmark-api-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Artem Chistyakov

unread,
Feb 17, 2013, 10:14:03 PM2/17/13
to postmark-ap...@googlegroups.com
Hi Robert,

I think your current solution is totally fine. There is a whole world with its own naming conventions outside Rails. However this is something we could add to our ruby gem, so I created an issue on Github: https://github.com/wildbit/postmark-gem/issues/28.

Thanks,
Artem Chistyakov,

To unsubscribe from this group and stop receiving emails from it, send an email to postmark-api-developers+unsub...@googlegroups.com.

Robert Rawlins

unread,
Feb 18, 2013, 9:34:17 AM2/18/13
to postmark-ap...@googlegroups.com
Thanks Artem,

I appreciate the input. I've been using my implementation in testing and it seems to work quite nicely so I'm happy with that approach for now.

If I get time I'll fork the gem, patch and send you a pull request some time later this week.

Thanks,

Robert
To unsubscribe from this group and stop receiving emails from it, send an email to postmark-api-deve...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages