NAME

Circle::Common - the common module for Circle::Chain SDK

VERSION

Version 0.03

SYNOPSIS

use Circle::Common;
my $url = build_url_template('user', 'getBlockHashList', {
  baseHeight => 0,
});
my $response = http_json_get($url);
if ($response->{status} == 200) {
  my $data = $response->{data};
  # process data here.
}

my $logout_url = build_url_template('user', 'logout', {});
$response = http_json_post($logout_url);
if ($response->{status} == 200) {
  my $data = $response->{data};
  # check the logout success here.
}

DESCRIPTION

The Circle::Common is common module which provides common functions: http restful api get, http restful api post and build url template etc.

METHODS

build_url_template

  my $url = build_url_template('user', 'getBlockHashList', {
    baseHeight => 10,
  });

Builds user's getBlockHashList url.

  my $url = build_url_template($buz, $path, $params_for);

$buz stands for: 'user', 'block', 'wallet' business modules.
$path stands for the key of the variant urls.
$params_for stands for the request query map.

load_config

my $config = load_config();
# process the config data here.

get_session_key

my $session_key = get_session_key();
# process the session key here.

In fact, you needn't set session key when you post apis. In SDK we set the session key in the post/get headers after you logged successfully.

http_json_get

my $response = http_json_get($url);

Invokes the http json get request to circle chain server. the response data contains three fields: status, message and data:

my $response = http_json_get($url);
if ($response->{status} == 200) {
  my $data = $response->{data};
  # process you data here.
}

http_json_post

my $response = http_json_post($url, $body);

Invokes the http json post request to circle chain server. the response data contains three fields: status, message and data:

my $body = {
  ...
};
my $response = http_json_post($url, $body);
if ($response->{status} == 200) {
  my $data = $response->{data};
  # process your data here.
}

SEE ALSO

See Circle::User for circle user module.

See Circle::Wallet for circle wallet module.

See Circle::Block for circle block module.

COPYRIGHT AND LICENSE

Copyright 2024-2030 Charles li

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.