API-Intis

 view release on metacpan or  search on metacpan

API/Intis/lib/API/Intis.pm  view on Meta::CPAN


package API::Intis::APIGrab;
use YAML::Tiny;
use WWW::Mechanize;
use Crypt::SSLeay;
use Digest::Perl::MD5 'md5_hex';
use JSON;
use error_codes;


sub readConfig {
    my $conf = YAML::Tiny->read( 'config.yaml' );
    return (login => $conf->[0]->{APIconnector}->{login}, APIkey => $conf->[0]->{APIconnector}->{APIkey}, host => $conf->[0]->{APIconnector}->{host});
};

sub build_signature {
    my (%params) = @_;
    delete $params{host};
    my $APIkey = delete $params{APIkey};
    my @ssignature;
    foreach my $key(sort keys %params){
        say "$key => $params{$key}";
        push @ssignature, $params{$key};
    };
    return md5_hex join('', @ssignature).$APIkey;
};

sub connect {
    my ($method, $other_params) = @_;
    my $ua = WWW::Mechanize->new(ssl_opts => { verify_hostname => 0 } );
    $ua->cookie_jar(HTTP::Cookies->new());
    $ua->agent_alias('Linux Mozilla');
    my %config = &readConfig();
    my $timestamp = $ua->get('https://go.intistele.com/external/get/timestamp.php')->content( raw => 1 );
    my %timestamp = (timestamp => $timestamp);
    my $output_format;
    if ($other_params ne '') {
        my %other_params = %{$other_params};

API/Intis/lib/API/Intis.pm  view on Meta::CPAN

    if ($r->{error}) {
        @error = &error_codes::get_name_from_code($r->{error});
    } else {
        @error = &error_codes::get_name_from_code();
    };
    return (request_json => $request_json, error => \@error, request_xml => $request_xml, request_object => \%{$r}, out_format => !defined $output_format ? 'json' : $output_format );
};

package API::Intis::APIRequest;
use JSON;
sub new {
    my($class, $method, $other_params) = @_;
    my %request_params;
    if (defined $other_params) {
        %request_params = &API::Intis::APIGrab::connect($method, $other_params);
    } else {
        %request_params = &API::Intis::APIGrab::connect($method, '');
    };
    my $self = {
        name => 'API::Intis::APIRequest',
        version => '1.0',

API/Intis/lib/API/error_codes.pm  view on Meta::CPAN

package error_codes;
use Modern::Perl;
use Switch;

sub get_name_from_code  {
    my $code = shift;
    my $descr;
    switch ($code // "")
    {
        #        code keys
        case "000"       { $descr = 'Service unavailable'; }
        case "1"         { $descr = 'Signature not specified';  }
        case "2"         { $descr = 'Login not specified';  }
        case "3"         { $descr = 'Text not specified';  }
        case "4"         { $descr = 'Phone number not specified';  }



( run in 0.929 second using v1.01-cache-2.11-cpan-a5abf4f5562 )