Closed ryanbillings closed 5 years ago
Looks good, just one comment! @ryanbillings
@ryanbillings How will this work if keyword
is an array and geo
is an array? Will it run every possible combination of keyword
and geo
?
Thanks for the PR review @pat310 !
The current implementation will run through both the geo
and keyword
arrays and run a query for each index in the array. If the arrays are mismatching lengths, we get an error (the one I posted above). To address this, I added in a validation in https://github.com/pat310/google-trends-api/pull/116/commits/30662b83578a92d3d923a1c720f6e99f93e60cd2 to make sure the arrays are the same size, along with some README updates to clarify this:
Passing `geo: ['US-CA, US-VA'], keyword: ['wine', 'peanuts']` will search for wine in California and peanuts in Virginia.
Also moved all of the cases for creating errors into a validateObj
function which gets called at the beginning of constructObj
(needed to satisfy a codeclimate failure 🙂 )
This adds support for a single keyword string with an array of geo locations.
I ran into error
SyntaxError: Unexpected token C in JSON at position 0
when running a query such as:My solution to this was to search for the same
keyword
for all regions in the case when keyword is a string whilegeo
is an array.@pat310 Let me know if you think this is a good change, thanks!