minimul / qbo_api

Ruby JSON-only client for QuickBooks Online API v3. Built on top of the Faraday gem.
MIT License
85 stars 45 forks source link

FEATURE: quickbook hash manipulation methods #129

Closed map7 closed 9 months ago

map7 commented 9 months ago

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?

minimul commented 9 months ago

Thanks for the submission. I'm just getting back from vacation so give me a day or two to review.

minimul commented 9 months ago

What do you mean exactly when you refer to returning a "path" e.g. find_by_id, find_base_path, find_by_total?

map7 commented 9 months ago

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.

minimul commented 9 months ago

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.

map7 commented 9 months ago

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.

map7 commented 9 months ago

Would it be worth mentioning 'Hashie' in the readme just to point people in the right direction?

minimul commented 9 months ago

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.