NAME
Finance::CaVirtex::API - Perl extension for handling the CaVirtex API and IPN calls.
SYNOPSIS
use Finance::CaVirtex::API;
# all the standard CaVirtex API calls...
my $cavirtex = Finance::CaVirtex::API->new(token => $token, secret => $secret);
# access public requests...
my $ticker = $cavirtex->ticker;
# make private requests...
my $wallet = $cavirtex->wallet;
# private request with parameters...
my $withdrawal = $cavirtex->withdrawal(amount => $amount, currency => $currency, address => $address,
# access the user agent of the last request...
my $user_agent = $cavirtex->user_agent;
# the is_success() and error() methods are also useful...
if ($cavirtex->is_success) {
print 'SUCESS';
}
else {
print 'FAIL';
my $error = $cavirtex->error;
}
# A more useful example...
my $cavirtex = Finance::CaVirtex::API->new(key => $key, secret => $secret, client_id => $client_id);
my $order = $cavirtex->order(currencypair => 'USDCAD', mode => 'bid', amount => '4.5', price => '1000.00');
if ($order) {
printf "The CaVirtex invoice ID is %s. You can see it here: %s\n", @{$order}{qw(id url)};
}
else {
printf "An error occurred: %s\n", $cavirtex->error;
}
DESCRIPTION
This API module provides a quick way to access the CaVirtex API from perl without worrying about the connection, authenticatino and an errors in between.
You create an object like this:
my $caviertex = Finance::CaVirtex::API->new(token => 'YOUR TOKEN', secret => 'YOUR SECRET');
The methods you call that match the API spec are:
$cavirtex->;
$cavirtex->;
$cavirtex->;
$cavirtex->;
$cavirtex->;
$cavirtex->;
$cavirtex->;
$cavirtex->;
METHODS
new()
my $cavirtex = Finance::CaVirtex::API->new(key => $key, secret => $secret, client_id => $client_id);
Create a new Finance::CaVirtex::API object. key, secret and client_id are required. These values are provided by Bitstamp through their online administration interface.
__more_to_come__()
etc
ATTRIBUTES
token(), secret()
These are usually set during object instantiation. But you can set and retrieve them through these attributes. The last set values will always be used in the next action request. These values are obtained from CaVirtex through your account.
is_ready()
Will return true if the request is set and all conditions are met. Will return false if: - the request object does not exist - the request object requires authentication and no key is provided - the request object does not have the manditory parameters set that CaVirtex requires for that request.
error()
If the request did not work, error() will contain a hash representing the problem. The hash contains the keys: 'type' and 'message'. These are strings. ie:
print "The error type was: " . $cavirtex->error->{type};
print "The error message was: " . $cavirtex->error->{message};
user_agent()
This will contain the user agent of the last request to CaVirtex. Through this object, you may access both the HTTP Request and Response. This will allow you to do detailed inspection of exactly what was sent and the raw CaVirtex response.
request()
This will contain the Request object of the last action called on the object. It is not a HTTP Request, but rather a config file for the request URL, params and other requirements for each post to cavirtex. You will find these modules using the naming Finance::CaVirtex::API::Request::*
HOWTO DETECT ERRORS
The design is such that the action methods (invoice_create(), invoice_get(), rates() and ledger()) will return false (0) on error. On success it will contain the hash of information from the CaVirtex JSON response. Your code should just check whether or not the response exists to see if it worked. If the response does not exist, then then the module detected a problem. The simplest way to handle this is to print out $cavirtex->error. A coding example is provided above in the SYNOPSIS.
NOTES
This module does not do accessive error checking on the request or the response. It will only check for "required" parameters prior to sending a request to CaVirtex. This means that you provide a word for a 'amount' parameter, and this module will happily send that off to CaVirtex for you. In these cases we are allowing CaVirtex to decide what is and is not valid input. If the input values are invalid, we expect CaVirtex to provide an appropriate response and that is the message we will return to the caller (through $cavirtex->error).
This module does not validate the response from CaVirtex. In general it will return success when any json response is provided by Bitstamp without the 'error' key. The SSL certificate is verified automatically by LWP, so the response you will get is very likely from CaVirtex itself. If there is an 'error' key in the json response, then that error is put into the $cavirtex->error attribute. If there is an 'error' parsing the response from CaVirtex, then the decoding error from json is in the $cavirtex->error attribute. If there is a network error (not 200), then the error code and $response->error will contain the HTTP Response status_line() (a string response of what went wrong).
SEE ALSO
The CaVirtex API documentation: This project on Github: https://github.com/peawormsworth/Finance-CaVirtex-API
AUTHOR
Jeff Anderson, <peawormsworth@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2014 by Jeff Anderson
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.