You are viewing a single comment's thread from:

RE: Howto write a perl package to interact with steemit

in #utopian-io7 years ago (edited)

Hmm, guess not. Got everything installed, but now when I try running the example client script (bin/steemit_client.pl), I get this error:

Initialized Steemit client with url steemd.minnowsupportproject.org
Malformed JSON: Expected string, array, object, number, boolean or null at line 0, offset 0 at /home/steemitdev/projects/example.com/steemit/Steemit/bin/../lib/Steemit.pm line 13.

Below is my entire lib/Steemit.pm. Note that line 13 is the second line in the sub _request -- it's the "my $result = decode_json [...]" line.

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 $result = decode_json $self->ua->get( $self->url, json => {                                                        
      jsonrpc => '2.0',                                                                                                  
      method  => 'call',                                                                                                 
      params  => [$api,$method,[@params]],                                                                               
      id      => int rand 100,                                                                                           
   })->result->body;                                                                                                     
                                                                                                                         
   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;

I'm unclear on why it's failing. I'll try "taking apart" the code, so it's doing one thing at a time and see if I can find it.

Okay, I've updated the module and will reproduce the new version below as well, and the new output -- which is telling me that perhaps the URL needs to be changed?

[Oops! While hitting "`" three times, then Enter, I typoed and hit Tab for one of them -- and then the "Enter" posted this! So, I'll continue it in a child comment.]

Sort:  
Loading...

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.029
BTC 60808.14
ETH 2392.92
USDT 1.00
SBD 2.63