API-Eulerian

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

  "CONFIGURE_REQUIRES" => {
    "ExtUtils::MakeMaker" => 0
  },
  "DISTNAME" => "API-Eulerian",
  "EXE_FILES" => [],
  "LICENSE" => "perl",
  "NAME" => "API::Eulerian",
  "PREREQ_PM" => {
    "LWP::UserAgent" => 0,
    "Encode" => 0,
    "JSON" => 0,
    "JSON::Streaming::Reader" => 0,
    "Text::CSV" => 0,
    "Time::HiRes" => 0,
    "Switch" => 0,
    "Protocol::WebSocket::Client" => 0,
    "File::Slurp" => 0,
  },
  "VERSION" => "0.6",
  "test" => {
    "TESTS" => "t/*.t"
  }

lib/API/Eulerian/EDW/Authority.pm  view on Meta::CPAN

  # Get URL used to request API::Eulerian::EDW Authority for Token.
  $status = $class->_url( $kind, $platform, $grid, $ip, $token );
  # Handle errors
  if( ! $status->error() ) {
    # Request API::Eulerian::EDW Authority
    $status = API::Eulerian::EDW::Request->get( $status->{ url } );
    # Get HTTP response
    $response = $status->{ response };
    # Get HTTP response code
    $code = $response->code;
    # We expect JSON reply data
    $json = API::Eulerian::EDW::Request->json( $response );
    if( $json && ( $code == 200 ) ) {
      $status = $json->{ error } ?
        $class->_error( $code, $json->{ error_msg } ) :
        $class->_success( $kind, $json );
    } else {
      $status = $class->_error(
        $code, $json ?
          encode_json( $json ) :
          $response->decoded_content

lib/API/Eulerian/EDW/Parser/JSON.pm  view on Meta::CPAN

# @author Thorillon Xavier:x.thorillon@eulerian.com
#
# @date 26/11/2021
#
# @version 1.0
#
###############################################################################
#
# Setup module name
#
package API::Eulerian::EDW::Parser::JSON;
#
# Enforce compilor rules
#
use strict; use warnings;
#
# Inherited interface from API::Eulerian::EDW::Parser
#
use parent 'API::Eulerian::EDW::Parser';
#
#
#
use JSON::Streaming::Reader;
#
#
#
use FileHandle;
#
# @brief
#
# @param $class - API::Eulerian::EDW::Parser class.
# @param $path - File Path.
# @param $uuid - Request UUID.

lib/API/Eulerian/EDW/Parser/JSON.pm  view on Meta::CPAN

  # Setup base class instance
  $self = $class->SUPER::new( $path, $uuid );

  # Create a new FileHandle
  $self->{ _FD } = $fd = FileHandle->new();

  # Open FileHandle
  $fd->open( "< $path" );

  # Create Json parser
  $self->{ _PARSER } = JSON::Streaming::Reader->for_stream( $fd );

  return $self;
}
#
# @brief
#
# @param $self
#
# @return
#

lib/API/Eulerian/EDW/Parser/JSON.pm  view on Meta::CPAN

sub do
{
  my ( $self, $hooks ) = @_;
  my $parser = $self->parser();
  my $depth = -1;
  my @in = ();
  my $uuid;
  my $msg;
  my $key;

  # Parse JSON stream
  $parser->process_tokens(
    # Property begin
    start_property => sub
    {
      $key = shift;
    },
    # Property end
    end_property => sub
    {
    },

lib/API/Eulerian/EDW/Peer/Rest.pm  view on Meta::CPAN

# @version 1.0
#
###############################################################################
#
# Setup module name
#
package API::Eulerian::EDW::Peer::Rest;

use strict;

use JSON();
use POSIX();
use Sys::Hostname();

use API::Eulerian::EDW::Peer();
use API::Eulerian::EDW::File();
use API::Eulerian::EDW::Bench();
use API::Eulerian::EDW::Status();
use API::Eulerian::EDW::Authority();
use API::Eulerian::EDW::Parser::JSON();
use API::Eulerian::EDW::Parser::CSV();

our @ISA = qw/ API::Eulerian::EDW::Peer /;

#
# Defines Parser class name matching format.
#
my %PARSERS = (
  'json' => 'API::Eulerian::EDW::Parser::JSON',
  'csv'  => 'API::Eulerian::EDW::Parser::CSV',
);
#
# @brief Allocate and initialize a new Eulerian Data Warehouse Rest Peer.
#
# @param $class - Eulerian Data Warehouse Rest Peer class.
# @param $setup - Setup attributes.
#
# @return Eulerian Data Warehouse Peer.
#

lib/API/Eulerian/EDW/Peer/Rest.pm  view on Meta::CPAN

#
# @param $self - Eulerian Data Warehouse Rest Peer.
# @param $command - Eulerian Data Warehouse Command.
#
# @return HTTP Request Body.
#
sub body
{
  my ( $self, $command ) = @_;
  $command =~ s/\n//gm;
  return JSON::encode_json({
    kind => 'edw#request',
    query => $command,
    creationTime => POSIX::strftime( '%d/%m/%Y %H:%M:%S', gmtime() ),
    location => Sys::Hostname::hostname(),
    expiration => undef,
  });
};
#
# @brief Setup HTTP Request Headers.
#

lib/API/Eulerian/EDW/Peer/Thin.pm  view on Meta::CPAN

use API::Eulerian::EDW::WebSocket;
#
# Import API::Eulerian::EDW::Bench
#
use API::Eulerian::EDW::Bench;
#
# Import Switch
#
use Switch;
#
# Import JSON
#
use JSON;
#
#
#
use API::Eulerian::EDW::Authority();
#
#
#
use Encode;
#
#

lib/API/Eulerian/EDW/Request.pm  view on Meta::CPAN

use LWP::UserAgent;
#
# Import IO::Socket::SSL
#
use IO::Socket::SSL;
#
# Import HTTP::Status
#
use HTTP::Status qw( :constants :is status_message );
#
# Import JSON
#
use JSON;
#
# Import Encode
#
use Encode;
#
# @brief Create new HTTP Headers.
#
# @param $class - API::Eulerian::EDW::HTTP class.
#
# @return HTTP Headers.
#
sub headers
{
  return HTTP::Headers->new();
}
#
# @brief Test if the content type of given HTTP response is a
#        JSON format.
#
# @param $class - API::Eulerian::EDW::Request Class.
# @param $response - HTTP response.
#
# @return 1 - Content type is JSON.
# @return 0 - Content type isnt JSON.
#
sub is_json
{
  my ( $class, $response ) = @_;
  my $type;

  # Get content type value from HTTP response
  $type = $response->header( 'content-type' );
  if( defined( $type ) ) {
    # Split content type into an array.
    my @subtypes = split( '; ', $type );
    # Iterate on subtypes entries
    foreach my $subtype ( @subtypes ) {
      # Test if subtype is JSON format
      if( $subtype eq 'application/json' ) {
        return 1;
      }
    }
  }

  return 0;
}
#
# @brief Get JSON object from HTTP response.
#
# @param $class - API::Eulerian::EDW::Request class.
# @param $response - HTTP response.
#
# @return JSON object.
#
sub json
{
  my ( $class, $response ) = @_;
  my $data = undef;

  if( $class->is_json( $response ) ) {
    $data = $response->decoded_content;
    if( defined( $data ) ) {
      chomp( $data );

lib/API/Eulerian/EDW/Request.pm  view on Meta::CPAN

=head3 output

=over 4

=item * Instance of an HTTP::Headers.

=back

=head2 is_json()

I<Test if given HTTP response content is a JSON format>

=head3 input

=over 4

=item * HTTP response.

=back

=head3 output

=over 4

=item * 1 - HTTP response content is in JSON format.

=item * 0 - HTTP response content isnt in JSON format.

=back

=head2 json()

I<Get JSON message from HTTP response>

=head3 input

=over 4

=item * HTTP response.

=back

=head3 output

=over 4

=item * JSON message.

=back

=head1 SEE ALSO

L<API::Eulerian::EDW::Status>

L<HTTP::Headers>

L<HTTP::Request>

L<HTTP::Status>

L<LWP::UserAgent>

L<IO::Socket::SSL>

L<JSON>

L<Encode>

=head1 AUTHOR

Xavier Thorillon <x.thorillon@eulerian.com>

=head1 COPYRIGHT

Copyright (c) 2008 API::Eulerian::EDW Technologies Ltd L<http://www.eulerian.com>



( run in 1.335 second using v1.01-cache-2.11-cpan-140bd7fdf52 )