Pcore-API-Majestic

 view release on metacpan or  search on metacpan

lib/Pcore/API/Majestic.pm  view on Meta::CPAN

our $EXPORT = { CONST => [qw[$MAJESTIC_INDEX_FRESH $MAJESTIC_INDEX_HISTORIC]] };

const our $MAJESTIC_INDEX_FRESH    => 1;
const our $MAJESTIC_INDEX_HISTORIC => 2;

has username => ( is => 'ro', isa => Str );
has password => ( is => 'ro', isa => Str );

has api_key              => ( is => 'ro', isa => Maybe [Str] );    # direct access to the API, access is restricted by IP address
has openapp_access_token => ( is => 'ro', isa => Maybe [Str] );    # OpenApp access, user key, identify user
has openapp_private_key  => ( is => 'ro', isa => Maybe [Str] );    # OpenApp access, application vendor key, identify application
has bind_ip              => ( is => 'ro', isa => Maybe [Str] );

has _cookies        => ( is => 'ro', isa => HashRef,  init_arg => undef );
has _cookies_time   => ( is => 'ro', isa => Int,      init_arg => undef );
has _login_requests => ( is => 'ro', isa => ArrayRef, init_arg => undef );

sub get_subscription_info ( $self, $cb ) {
    my $url_params = {
        cmd        => 'GetSubscriptionInfo',
        datasource => 'historic',

lib/Pcore/API/Majestic.pm  view on Meta::CPAN

        }
    );

    return;
}

sub _request ( $self, $url_params, $cb ) {
    if ( $self->api_key ) {
        $url_params->{app_api_key} = $self->api_key;
    }
    elsif ( $self->openapp_private_key && $self->openapp_access_token ) {
        $url_params->{accesstoken} = $self->openapp_access_token;

        $url_params->{privatekey} = $self->openapp_private_key;
    }
    else {
        die q["api_key" or "openapp_private_key" and "openapp_access_token" are missed];
    }

    my $url = 'http://api.majestic.com/api/json?' . P->data->to_uri($url_params);

    P->http->get(
        $url,
        timeout    => 60,
        persistent => 30,
        bind_ip    => $self->bind_ip,
        on_finish  => sub ($res) {



( run in 0.270 second using v1.01-cache-2.11-cpan-4d50c553e7e )