Acme-Coinbase

 view release on metacpan or  search on metacpan

bin/coinbase.pl  view on Meta::CPAN

        $ua->default_headers->push_header( ACCESS_NONCE => $nonce );
        $ua->default_headers->push_header( Host         => "coinbase.com" );
        $ua->default_headers->push_header( Connection   => "close" );
        $ua->default_headers->push_header( "Content-Type" => "application/json" );

        # add ACCESS_SIGNATURE in a request_prepare handler so we can set it knowing the request content
        # ... it doesn't matter for GETs though because the content should be blank (like we see in our code)
        $ua->add_handler( 
            request_prepare => sub { 
                my($request, $ua, $h) = @_; 
                my $content = $request->decoded_content();  # empty string.
                $content = "" unless defined($content);

                my $to_hmac = $nonce . $url . $content;
                my $sig = hmac_sha256_hex( $to_hmac, $api_secret ); 
                print "$prog: in callback, str=$to_hmac, ACCESS_SIGNATURE => $sig\n";
                $request->headers->push_header( ACCESS_SIGNATURE => $sig );
            }
        );

        if ($verbose) {

bin/coinbase.pl  view on Meta::CPAN

                    #print "$prog: verbose mode: BEGIN dump of request object: ***********\n";
                    #shift->dump; 
                    #print "$prog: verbose mode: END dump of request object: *************\n";
                    return 
                });
        }

        my $response = $ua->get( $url );

        my $noun = $response->is_success() ? "Success" : "Error";
        #print ("$prog: $noun " . $response->status_line . ", content: " . $response->decoded_content . "\n");
        print ("$prog: $noun " . $response->status_line . ", content: " . $response->content . "\n");
    }
}

# this is an example of a header used on the coinbase API, from their docs;
# GET /api/v1/account/balance HTTP/1.1
# Accept: */*
# User-Agent: Ruby
# ACCESS_KEY: <YOUR-API-KEY>
# ACCESS_SIGNATURE: <YOUR-COMPUTED-SIGNATURE>

bin/coinbase.pl.bak  view on Meta::CPAN

        $ua->default_headers->push_header( ACCESS_NONCE => $nonce );
        $ua->default_headers->push_header( Host         => "coinbase.com" );
        $ua->default_headers->push_header( Connection   => "close" );
        $ua->default_headers->push_header( "Content-Type" => "application/json" );

        # add ACCESS_SIGNATURE in a request_prepare handler so we can set it knowing the request content
        # ... it doesn't matter for GETs though because the content should be blank (like we see in our code)
        $ua->add_handler( 
            request_prepare => sub { 
                my($request, $ua, $h) = @_; 
                my $content = $request->decoded_content();  # empty string.
                $content = "" unless defined($content);

                my $to_hmac = $nonce . $url . $content;
                my $sig = hmac_sha256_hex( $to_hmac, $api_secret ); 
                print "$prog: in callback, str=$to_hmac, ACCESS_SIGNATURE => $sig\n";
                $request->headers->push_header( ACCESS_SIGNATURE => $sig );
            }
        );

        if ($verbose) {

bin/coinbase.pl.bak  view on Meta::CPAN

                    #print "$prog: verbose mode: BEGIN dump of request object: ***********\n";
                    #shift->dump; 
                    #print "$prog: verbose mode: END dump of request object: *************\n";
                    return 
                });
        }

        my $response = $ua->get( $url );

        my $noun = $response->is_success() ? "Success" : "Error";
        #print ("$prog: $noun " . $response->status_line . ", content: " . $response->decoded_content . "\n");
        print ("$prog: $noun " . $response->status_line . ", content: " . $response->content . "\n");
    }
}

# this is an example of a header used on the coinbase API, from their docs;
# GET /api/v1/account/balance HTTP/1.1
# Accept: */*
# User-Agent: Ruby
# ACCESS_KEY: <YOUR-API-KEY>
# ACCESS_SIGNATURE: <YOUR-COMPUTED-SIGNATURE>



( run in 1.588 second using v1.01-cache-2.11-cpan-26ccb49234f )