Skip to content

Commit

Permalink
::HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
foxcool committed May 29, 2011
1 parent 4393015 commit caa203f
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/WWW/Monitis/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ our $MAPPING = {
memory => 'Memory',
drive => 'Drive',
process => 'Process',
la => 'LA'
la => 'LA',
http => 'HTTP'
};
our $MAPPING_LOADED = {};

Expand Down
126 changes: 126 additions & 0 deletions lib/WWW/Monitis/API/HTTP.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package WWW::Monitis::API::HTTP;

use warnings;
use strict;
require Carp;

use base 'WWW::Monitis::API';

sub add {
my ( $self, %params ) = @_;

my @mandatory = qw/userAgentId contentMatchFlag contentMatchString httpMethod timeout url name tag/;
my @optional = qw/loadFull overSSL passAuth postData redirect userAuth /;

my $params = $self->prepare_params( \%params, \@mandatory, \@optional );

return $self->api_post( 'addInternalHttpMonitor' => $params );
}

sub edit {
my ( $self, %params ) = @_;

my @mandatory = qw/testId contentMatchString httpMethod urlParams timeout name tag/;
my @optional = qw/passAuth userAuth postData/;

my $params = $self->prepare_params( \%params, \@mandatory, \@optional );

return $self->api_post( 'editInternalHttpMonitor' => $params );
}

sub get {
my ( $self, %params ) = @_;

my @mandatory = qw/agentId/;
my @optional = qw//;

my $params = $self->prepare_params(\%params, \@mandatory, \@optional);

return $self->api_get('agentHttpTests' => $params);
}

sub get_info {
my ( $self, %params ) = @_;

my @mandatory = qw/monitorId/;
my @optional = qw//;

my $params = $self->prepare_params(\%params, \@mandatory, \@optional);

return $self->api_get('internalHttpInfo' => $params);
}

sub get_results {
my ( $self, %params ) = @_;

my @mandatory = qw/monitorId day month year/;
my @optional = qw/timezone/;

my $params = $self->prepare_params(\%params, \@mandatory, \@optional);

return $self->api_get('internalHttpResult' => $params);
}


__END__
=head1 NAME
WWW::Monitis::API::HTTP - [One line description of module's purpose here]
=head1 SYNOPSIS
use WWW::Monitis::API::HTTP;
=head1 DESCRIPTION
=head1 ATTRIBUTES
L<WWW::Monitis::API::Layout> implements following attributes:
=head1 METHODS
L<WWW::Monitis::API::Layout> implements following methods:
=head1 BUGS AND LIMITATIONS
Please report any bugs or feature requests to
C<bug-www-monitis-api-subaccounts@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org>.
=head1 AUTHOR
Yaroslav Korshak C<< <ykorshak@gmail.com> >>
=head1 LICENCE AND COPYRIGHT
Copyright (c) 2011, Yaroslav Korshak C<< <ykorshak@gmail.com> >>. All rights reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.
=head1 DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
1 change: 1 addition & 0 deletions xt/agents.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ note 'Action agents (agents->get) ###########################################';

my $response = $api->agents->get;
isa_ok $response, 'ARRAY', 'JSON response ok';
warn Dumper $response;

note 'Action agentInfo (agents->get_agent_info) ###########################################';

Expand Down
82 changes: 82 additions & 0 deletions xt/http.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use lib 't/lib';
use Test::Monitis tests => 8, live => 1;
use Data::Dumper;

my $api = WWW::Monitis::API->new(
api_key => $ENV{MONITIS_API_KEY},
secret_key => $ENV{MONITIS_SECRET_KEY}
);

note
'Action addInternalHttpMonitor (http->add) ###########################################';

# TODO: Make a good request to API -> We not have Agents in monitoring system.
my $response = $api->http->add(
userAgentId => '',
contentMatchFlag => '',
contentMatchString => '',
httpMethod => '',
timeout => '',
url => '',
name => '',
tag => ''
);

isa_ok $response, 'HASH', 'JSON response ok';
is $response->{status}, 'ok', 'status ok';
like $response->{data}{testId}, qr/^\d+$/, 'API returned test id';

my $test_id = $response->{data}{testId};
warn Dumper $response;
note
'Action editInternalHttpMonitor (http->edit) ###########################################';

my $response = $api->http->edit(
testId => '',
contentMatchString => '',
httpMethod => '',
urlParams => '',
timeout => '',
name => '',
tag => ''
);

isa_ok $response, 'HASH', 'JSON response ok';
is $response->{status}, 'ok', 'status ok';

note
'Action agentInternalHttp (http->get) ###########################################';

my $response = $api->http->get( agentId => "$test_id" );

isa_ok $response, 'HASH', 'JSON response ok';
warn Dumper $response;

note
'Action InternalHttpInfo (http->get_info) ###########################################';

my $response = $api->http->get_info( monitorId => "$test_id" );

isa_ok $response, 'HASH', 'JSON response ok';
warn Dumper $response;

note
'Action httpResult (http->get_results) ###########################################';

my $response = $api->http->get_results(
monitorId => "$test_id",
day => '29',
month => '5',
year => '2011'
);

isa_ok $response, 'HASH', 'JSON response ok';
warn Dumper $response;

note
'Action tophttp (http->get_top_results) ###########################################';

my $response = $api->http->get_top_results;

isa_ok $response, 'HASH', 'JSON response ok';
warn Dumper $response;

0 comments on commit caa203f

Please sign in to comment.