schmorrison / Zoho

Golang API for Zoho services
MIT License
35 stars 34 forks source link

'Records' type JSON or Go structs #4

Closed schmorrison closed 4 years ago

schmorrison commented 6 years ago

Currently when getting data from a 'records module', for example Leads, the user must use a struct with correct JSON tags that they created for their own use case, or a map[string]interface{} which requires alot of type assertions to use properly, resulting in very cumbersome code.

I would like users to provide examples of the JSON that is returned to them when getting records for various modules. Or using JSON-to-Go and providing the generated struct, and which module it is for. Or even writing a pull request by including the generated struct in the file crm/records_types.go.

I have done a couple, but haven't pushed them yet because Zoho returns alot of fields that are null, and JSON-to-Go uses interface{} as the fields type when the field returned could contain null. So I have had to go through each generated struct and try to figure out the data type I should be expecting, or try to infer the type by the fields name. I am also having a difficult time sorting the custom fields and fields that are related to custom modules (SalesIQ, etc.).

Printing the JSON can be accomlished by editing the file schmorrison/zoho/http.go and adding this line between ioutil.ReadAll and json.Unmarshal:

fmt.Println(string(body))
schmorrison commented 4 years ago

With the generate branch this should be a non-issue. Using the example JSON values that exist in the Zoho documentation, we will write a scheme for each endpoint, then generate the methods and structs which can be used as ever. Again, expanding the fields to be handled in JSON un/marshalling can be done in the user app by embedding the Zoho struct in a local struct and adding the required fields.