Closed map7 closed 9 months ago
Thanks for the submission. I'm just getting back from vacation so give me a day or two to review.
What do you mean exactly when you refer to returning a "path" e.g. find_by_id, find_base_path, find_by_total?
find_base_path returns the path to the nested key in the hash object.
Here is my test for the find_base_path;
def test_find_base_path_row_id
file=File.expand_path(File.join('../data', 'pl_current.json'), __FILE__)
current = JSON.parse(File.read(file))
result=@report.find_base_path("49",current)
assert_equal ["Rows","Row",0,"Rows","Row",2,"Rows","Row",0,"Rows","Row",1],result
end
Given an 'id' it searches the nested hash and returns how to get there in an array. This array could be used as a splat in a dig command so that I can modify / add to the nested component. I find it handy.
So these are methods dealing with the different report's endpoints then?
I'm not going to approve any PRs dealing with the Reports API JSON jungle.
Reports API returned JSON is just an awful mess and I'll leave it to each developer to handle that.
Personally, I use the Hashie gem, principally DeepFetch
and DeepLocate
to mow down that JSON jungle.
Yes it's dealing with different reports endpoints.
No problem, it was worth asking before I sent in a PR :).
I'll check out Hashie to deal with the jungle. I agree it's not the greatest of JSON out there.
Would it be worth mentioning 'Hashie' in the readme just to point people in the right direction?
No problem, it was worth asking before I sent in a PR :).
Exactly, well done!.
Would it be worth mentioning 'Hashie' in the readme just to point people in the right direction?
Hmm. Yeah, I guess so.
I've got a few methods I use to traverse and manipulate the JSON returned by qbo_api such as;
find_by_id - given an id it returns the full path in the hash find_parent_id - given an id it finds the parent of that child find_base_path - given an id it returns the base path such as ["Rows","Row",0] find_by_total - given the title such as "Total Job Materials" it will return the path
These have been handy for me to merge reports or manipulate the reports to suit our needs.
Would these be within the scope of qbo_api or do you suggest making another gem to handle these methods, maybe something related like qbo_api_tools or something?
Or better still does something already exist or is there a better approach to this before I start adding/creating a gem?