Re: [Mojolicious] using mojolicious to make a batch request to google api

2018-09-18 Thread Steve Dondley
Thanks. Yeah, I got that working somehow. When I tried it before I got an 
error. I'm now getting a 400 error from google, however. Here's the $tx 
object now:

$VAR1 = bless( {
 'req' => bless( {
   'method' => 'POST',
   'content' => bless( {
 'parts' => [
  bless( 
{

   'asset' => bless( {

   'content' => 'GET 
/gmail/v1/users/m...@gmail.com/messages/165eb111fcf21503'

 }, 'Mojo::Asset::Memory' ),

   'headers' => bless( {

 'headers' => {

'content-type' => [


'application/http'

  ]

  }

   }, 'Mojo::Headers' ),

   'events' => {

 'read' => [

 sub { "DUMMY" }

   ]

   },

   'read' => $VAR1->{'req'}{'content'}{'parts'}[0]{'events'}{'read'}[0]

 }, 'Mojo::Content::Single' )
],
 'events' => {
   
'read' => [

   sub { "DUMMY" }

 ]
 },
 'headers' => bless( 
{

   'headers' => {

  'accept-encoding' => [

 'gzip'

   ],

  'content-type' => [

  'mulitpart/mixed'

],

  'authorization' => [

   'Bearer REAL_TOKEN_HERE'

 ],

  'user-agent' => [

'Mojolicious (Perl)'

  ]

}

 }, 'Mojo::Headers' )
   }, 
'Mojo::Content::MultiPart' ),
   'url' => bless( {

Re: [Mojolicious] using mojolicious to make a batch request to google api

2018-09-17 Thread Dan Book
You want the multipart content generator. Scroll down to the very last
example in https://metacpan.org/pod/Mojo::UserAgent::Transactor#tx

-Dan

On Mon, Sep 17, 2018 at 10:22 PM Steve Dondley  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/
> m...@gmail.com/messages/165e91c27e4af0be',
>   'Content-Type' => 'application/http',
> },
> {
>   content => 'GET /gmail/v1/users/
> m...@gmail.com/messages/165e94ce49900df2',
>   'Content-Type' => 'application/http',
> }
>   ];
>
>
>   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 );
>
>
>
>
> This results in a tranaction object that looks like this:
>
>
> $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\\/m...@gmail.com\\/messages\\/165e91c27e4af0be"},{"Content-Type":"application\\/http","content":"GET
> \\/gmail\\/v1\\/users\\/m...@gmail.com\\/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
>
> Fiddling with the content type settings doesn't help make this go away.
>
> --
> 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 mojolicious+unsubscr...@googlegroups.com.
> To post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] using mojolicious to make a batch request to google api

2018-09-17 Thread Stefan Adams
On Mon, Sep 17, 2018 at 9:56 PM Steve Dondley  wrote:

> 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."
>

"boundary"...  that sounds like you should be using the multipart generator?

Sorry, I'm completely out of my league here...

I assume I can get rid of those and Mojolicious will handle that for me?


I generally find that I can assume anything with Mojolicious and it'll Do
The Right Thing.  ;D  No of course that's not true, just plugging how well
designed it is.  :D

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] using mojolicious to make a batch request to google api

2018-09-17 Thread Steve Dondley
$httpMethod is set to "post". I forgot to add that in.

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  > 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/
>> m...@gmail.com/messages/165e91c27e4af0be',
>>   'Content-Type' => 'application/http',
>> },
>> {
>>   content => 'GET /gmail/v1/users/
>> m...@gmail.com/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\\/m...@gmail.com 
>> 

Re: [Mojolicious] using mojolicious to make a batch request to google api

2018-09-17 Thread Steve Dondley
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  > 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/
>> m...@gmail.com/messages/165e91c27e4af0be',
>>   'Content-Type' => 'application/http',
>> },
>> {
>>   content => 'GET /gmail/v1/users/
>> m...@gmail.com/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
>> ( {
>>   

Re: [Mojolicious] using mojolicious to make a batch request to google api

2018-09-17 Thread Stefan Adams
On Mon, Sep 17, 2018 at 9:22 PM Steve Dondley  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/
> m...@gmail.com/messages/165e91c27e4af0be',
>   'Content-Type' => 'application/http',
> },
> {
>   content => 'GET /gmail/v1/users/
> m...@gmail.com/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\\/m...@gmail.com\\/messages\\/165e91c27e4af0be"},{"Content-Type":"application\\/http","content":"GET
> \\/gmail\\/v1\\/users\\/m...@gmail.com\\/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 

[Mojolicious] using mojolicious to make a batch request to google api

2018-09-17 Thread Steve Dondley
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/m...@gmail.com/messages/165e91c27e4af0be',
  'Content-Type' => 'application/http',
},
{
  content => 'GET 
/gmail/v1/users/m...@gmail.com/messages/165e94ce49900df2',
  'Content-Type' => 'application/http',
}
  ];


  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 
);




This results in a tranaction object that looks like this:


$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\\/m...@gmail.com\\/messages\\/165e91c27e4af0be"},{"Content-Type":"application\\/http","content":"GET
 
\\/gmail\\/v1\\/users\\/m...@gmail.com\\/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

Fiddling with the content type settings doesn't help make