You are viewing a single comment's thread from:

RE: Howto write a perl package to interact with steemit

in #utopian-io7 years ago

The new module:

package Steemit;                                                                                                         
                                                                                                                         
use Modern::Perl '2017';                                                                                                 
use Mojo::Base -base;                                                                                                    
use Mojo::UserAgent;                                                                                                     
use Mojo::JSON qw(decode_json encode_json);                                                                              
                                                                                                                         
has url     => 'steemd.minnowsupportproject.org';                                                                                                             
has ua      =>  sub { Mojo::UserAgent->new };                                                                            
                                                                                                                                                                                                                                                  
sub _request {                                                                                                           
   my( $self, $api, $method, @params ) = @_;                                                                             
   my $get_result = $self->ua->get( $self->url, json => {                                                        
      jsonrpc => '2.0',                                                                                                  
      method  => 'call',                                                                                                 
      params  => [$api,$method,[@params]],                                                                               
      id      => int rand 100,                                                                                           
   })->result->body;
   print "INFO: result from get is [$get_result]\n";
   my $result = decode_json $get_result;
                                                                                                                         
   return $result->{result} if $result->{result};                                                                        
   if( my $error = $result->{error} ){                                                                                   
      die $error->{message};                                                                                             
   }                                                                                                                     
   #ok no error no result                                                                                                
   require Data::Dumper;                                                                                                 
   die "unexpected api result: ".Data::Dumper::Dumper( $result );                                                        
}    

sub get_accounts {                                                                                                       
   my( $self, @params ) = @_;                                                                                            
   return $self->_request('database_api','get_accounts',@params);                                                        
} 

1;

First, I added the "my $get_result" line, and moved the "my $result = decode_json $get_result;" to below it. This failed in the same manner, so then I added the "print" statement in between them, which gave me:

INFO: result from get is [<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.10.3 (Ubuntu)</center>
</body>
</html>
]

Note that one benefit of surrounding the variable I'm outputting with square brackets, is that I see there's a trailing CR after "". That doesn't really affect this result, but it has given me insight into what's happening, in other instances.

Anyway, it's telling me there's a bad gateway. So, let's try loading that URL in a browser, and see what happens. Okay, same result, just in web format. That URL was "steemd.minnowsupportproject.org", and I vaguely know about some API changes breaking usable work. So I tried "api.minnowsupportproject.org" but that wasn't found.

So then I went to "minnowsupportproject.org" -- and see that their home page has a bunch of broken functionality on it as well!

So I guess I'm blocked now. I'll finish tabulating the votes manually, I guess. Thanks though, this has been educational! :)

Sort:  
Loading...

Coin Marketplace

STEEM 0.15
TRX 0.15
JST 0.028
BTC 53949.09
ETH 2223.84
USDT 1.00
SBD 2.31