Closed pkayokay closed 2 years ago
The idiomatic ruby way is snake_case
and the defaults at Zoho are Class_Camel_Snake_Case
or what have you, which is super annoying, especially when you add abbreviations to the mix -- is it pdf_url
or Pdf_Url
or PDF_URL
?
I have created a huge entry in attribute_translations
spelling out my bindings manually and agree we need a better way to control the default output here -- at a minimum I'd want access to the attr_to_zoho_key
on a per-class basis that can be overridden or disabled --
So you say you would like a method to override the default key case translation and keep whatever comes from Zoho?
Yea another method would be nice, or a parameter we can pass to the method to make this optional. I have hundreds of api names I would need to change otherwise...
@pkayokay can you purpose a way so solve this? Otherwise I'll see what I can do.
I base a lot of my opinions on the architecture of https://github.com/emberjs/data -- in their paradigm they've got a pipeline that goes something like api -> adapter -> serializer -> transform -> model and along the way they offer hooks for one to override the default behaviour -- a lot of it is focused on getting camelCase
attributes into the model layer no matter what the API layer actually looks like --
In this paradigm, they offer a method called pathForType and another called keyForAttribute, among oh-so-many others to cover the myriad of edge and corner cases one can encounter with JSON and REST apis
I'd say in terms of a data pipeline, this albeit Javascript layer (which was originally designed by members of the Rails core team) has every hook one would possibly want when dealing with data between API <-> Model concerns, which is the reason I'm suggesting making the attr_to_zoho_key
protected or public, as it carries the same function as keyForAttribute
and pathForType
mentioned above
@pkayokay for now I don't see an easy solution for this, so you can use the attribute_translation
method in your class to solve this.
You have an example here: https://github.com/rikas/zoho_hub/blob/master/examples/models/potential.rb
Zoho module API names are always capitalized: https://github.com/rikas/zoho_hub/blob/master/lib/zoho_hub/with_attributes.rb#L48
Example: Account Name ->
Account_Name
will work withBut what if we have a custom field (or many which is my case), that are named as Account Valid ->
Account_valid
(instead ofAccount_Valid
on our custom API name)None of the formats above will work unless written exactly as is. I would rather not assume that custom field API names are always formatted with caps.
Errors because it can't find a valid custom field due to capitalization.
We should leave it to the user making the API call to match the API name 🤔
I can do a PR to remove it or if anyone thinks there's a better solution let me know.