My bad. Where it says $optional_data, that is actually the $options 
variable. That bit was pasted from a different function. Thanks for getting 
back.

The Google API example shows a "boundary" in the "Content-Type" and a 
"Content-Length." I assume I can get rid of those and Mojolicious will 
handle that for me?

On Monday, September 17, 2018 at 10:51:02 PM UTC-4, Stefan Adams wrote:
>
>
>
> On Mon, Sep 17, 2018 at 9:22 PM Steve Dondley <[email protected] 
> <javascript:>> wrote:
>
>> I'm trying to hack a perl module that uses mojolicious to make api calls 
>> to google's api so that it can make batch api call as documented here: 
>> https://developers.google.com/gmail/api/guides/batch
>>
>> I've made various attempts but no calls are resulting in a successful 
>> response. Here's what I'm currently trying.
>>
>>       my $options =
>>           [
>>             {
>>               content => 'GET /gmail/v1/users/
>> [email protected]/messages/165e91c27e4af0be',
>>               'Content-Type' => 'application/http',
>>             },
>>             {
>>               content => 'GET /gmail/v1/users/
>> [email protected]/messages/165e94ce49900df2',
>>               'Content-Type' => 'application/http',
>>             }
>>           ];
>>
>>
>>
> I don't see $options being used in your sample code.  Also it seems 
> weird.  Admittedly, I haven't read (or even looked at) the api guide you 
> referenced.
> I personally have never seen content type application/http -- perhaps I 
> live under a rock.  
>  
>
>>       my $path = 'https://www.googleapis.com/batch/' . $s->api . '/' . $s
>> ->version;
>>
>>
>>       my $headers = {'Authorization' => 'Bearer TOKEN_HERE'};
>>
>>
>>
>>
>>       $tx = $self->ua->build_tx(
>>             uc $http_method => $path => $headers => json => 
>> $optional_data );
>>
>>
> What is $http_method and what is $optional_data?  These are used but 
> undefined, in your sample.
>
> This results in a tranaction object that looks like this:
>>
>
> It may not be what you want, but the object looks assembled correctly to 
> me.  Can you point out anything in particular that doesn't look the way you 
> think it should?  Fishiest looking thing I see is the content body (req -> 
> content -> asset -> content).  I assume your intentionally removed your 
> bearer token for this extract.
>  
>
>> $VAR1 = bless( {
>>                  'req' => bless( {
>>                                    'content' => bless( {
>>                                                          'headers' => 
>> bless( {
>>                                                                           
>>      'headers' => {
>>                                                                           
>>                     'content-type' => [
>>                                                                           
>>                                         'application/json'
>>                                                                           
>>                                       ],
>>                                                                           
>>                     'authorization' => [
>>                                                                           
>>                                          'Bearer TOKEN_HERE'
>>                                                                           
>>                                        ],
>>                                                                           
>>                     'accept-encoding' => [
>>                                                                           
>>                                            'gzip'
>>                                                                           
>>                                          ],
>>                                                                           
>>                     'user-agent' => [
>>                                                                           
>>                                       'Mojolicious (Perl)'
>>                                                                           
>>                                     ]
>>                                                                           
>>                   }
>>                                                                           
>>    }, 'Mojo::Headers' ),
>>                                                          'events' => {
>>                                                                        
>> 'read' => [
>>                                                                           
>>          sub { "DUMMY" }
>>                                                                           
>>        ]
>>                                                                      },
>>                                                          'read' => $VAR1
>> ->{'req'}{'content'}{'events'}{'read'}[0],
>>                                                          'asset' => bless
>> ( {
>>                                                                           
>>    'content' => '[{"Content-Type":"application\\/http","content":"GET 
>> \\/gmail\\/v1\\/u
>> sers\\/[email protected] 
>> <javascript:>\\/messages\\/165e91c27e4af0be"},{"Content-Type":"application\\/http","content":"GET
>>  
>> \\/gmail\\/v1\\/users\\/[email protected]\\/messag
>> es\\/165e94ce49900df2"}]'
>>                                                                           
>>  }, 'Mojo::Asset::Memory' )
>>                                                        }, 
>> 'Mojo::Content::Single' ),
>>                                    'url' => bless( {
>>                                                      'scheme' => 'https',
>>                                                      'host' => '
>> www.googleapis.com',
>>                                                      'path' => bless( {
>>                                                                         
>> 'path' => '/batch/gmail/v1'
>>                                                                       }, 
>> 'Mojo::Path' )
>>                                                    }, 'Mojo::URL' ),
>>                                    'method' => 'POST'
>>                                  }, 'Mojo::Message::Request' )
>>                }, 'Mojo::Transaction::HTTP' );
>>
>>
>>
>> Trying anything other than json for the generator results in an error:
>>  Use of uninitialized value $cb in method lookup
>>
>
> Is that because $optional_data isn't defined?
>  
>
>> Fiddling with the content type settings doesn't help make this go away.
>>
>
> content-type in $headers, or in $options?  The json generator is 
> correctly generating the correct application/json content type -- I assume 
> (hope) you are wanting json?  What's with the funny business of the content 
> type in $options?  It seems that would be a google api -specific thing, 
> which I can't comment on (didn't open the api spec).
>
> I don't expect to be of any direct help, but hopefully I got you thinking.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to