Laurielounge has asked for the wisdom of the Perl Monks concerning the following question:

Hi gang, I'm trying to automate some google analytics stuff here. For this request:
$req = $analytics->new_request( realtime => "true", ids => "ga:12345678", dimensions =>"rt:country,rt:city,rt:pagePath, rt:latitude, rt:longitude", metrics =>"rt:activeUsers", filters =>"rt:country==England", );
I'm using a database query to determine what the request parameters should be for this query. The multi line result set looks like

 select * from query_builder where query_no = 14; Result set of the query looks like
Record 1 realtime => "true", Record 2 ids => "ga:12345678", Record 3 dimensions =>"rt:country,rt:city,rt:pagePath,rt:latitude,rt:l +ongitude", Record 4 metrics =>"rt:activeUsers", Record 5 filters =>"rt:country==England",
Or to show it another way:
realtime => "true", ids => "ga:12345678", dimensions =>"rt:country,rt:city,rt:pagePath,rt:latitude,rt:longitude" +, metrics =>"rt:activeUsers", filters =>"rt:country==England",
So. If I created a string along the lines of
$qry_str = 'realtime => "true", ids => "ga:12345678", dimensions =>"rt:country,rt:city,rt:pagePath,rt:latitude,rt:longitude +", metrics =>"rt:activeUsers", filters =>"rt:country==England",';
(in reality it's
while ( @row = $sth->fetchrow_array() ) { $qry_str .= $row[0]; }
)
How can I do a
$req = $analytics->new_request( $qry_str );
Any thoughts?

Replies are listed 'Best First'.
Re: Passing API params via string
by LanX (Saint) on Sep 11, 2017 at 23:17 UTC
    You don't have to pass a string but named parameters.

    That is something like

     $req = $analytics->new_request( %qry_hash );

    should do.

    Your DB structure is not obvious for me but check out DBI ->fetchrow_hashref to get what you need as a $hashref.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      Perfect. Problem solved.
      Thanks so much