AMF-Connection
view release on metacpan
or search on metacpan
Changes
view on Meta::CPAN
10 11 12 13 14 15 16 17 18 19 20 21 | 0.21
- Fixed check on Storable version for parse_option()
0.30 Wed May 11 18:07:11 BST 2011
- Added callBatch () to make AMF batch RPC possible
0.31 Fri May 4 17:33:56 2012 +0100
- Support different source and destination in AMF remoting package (patch by Aleksey Komarov)
0.32 Fri May 4 18:59:18 BST 2012
- Fixed bug to correctly decode the HTTP response using decoded_content() when the AMF
gateway supports HTTP Accept-Encoding request headers (bug report by Markus Ortner)
|
META.json
view on Meta::CPAN
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | },
"name" : "AMF-Connection" ,
"no_index" : {
"directory" : [
"t" ,
"inc"
]
},
"prereqs" : {
"build" : {
"requires" : {
"ExtUtils::MakeMaker" : 0
}
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : 0
}
},
"runtime" : {
"requires" : {
"LWP::UserAgent" : "5.829" ,
"Storable::AMF" : "0.71"
}
}
},
"release_status" : "stable" ,
"version" : "0.32"
}
|
META.yml
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ---
abstract: 'A simple library to write AMF clients.'
author:
- 'Alberto Attilio Reggiori, <areggiori@cpan.org>'
build_requires:
ExtUtils::MakeMaker: 0
configure_requires:
ExtUtils::MakeMaker: 0
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 6.59, CPAN::Meta::Converter version 2.112150'
license: unknown
meta-spec:
version: 1.4
name: AMF-Connection
no_index:
directory:
- t
- inc
requires:
LWP::UserAgent: 5.829
Storable::AMF: 0.71
version: 0.32
|
README
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | AMF-Connection
==============
A simple module to write AMF [1] clients to invoke remote services as used by Flex/AIR RIAs.
The module includes basic support for synchronous HTTP/S based RPC request-response access, where
the client sends a request to the server to be processed and the server returns a response to the client
containing the processing outcome. Data is sent back and forth in AMF binary format (AMFChannel). Other access patterns
such as pub/ sub and channels transport are out of scope of this inital release.
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
DEPENDENCIES
This module requires these other modules and libraries:
Storable::AMF ( for serialisation/deserialisation of AMF )
LWP::UserAgent ( for RPC services over HTTP/S POST )
COPYRIGHT AND LICENCE
Put the correct copyright and licence information here.
Copyright (C) 2010 by Alberto Attilio Reggiori
|
TODO
view on Meta::CPAN
1 2 3 4 5 | - tests
- more documentation
- more testing
- look into results/class mapping
|
examples/amfclient.pl
view on Meta::CPAN
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | my $method = 'search' ;
my $client = new AMF::Connection( $endpoint );
$client ->setEncoding(3);
$client ->setHTTPCookieJar( HTTP::Cookies->new( file => "/tmp/lwpcookies.txt" , autosave => 1, ignore_discard => 1 ) );
my $params = [ "italy" ];
my ( $response ) = $client ->call( $service . '.' . $method , $params );
my $json = JSON->new;
$json ->ascii(1);
$json ->utf8(1);
$json ->pretty(1);
$json ->allow_blessed(1);
$json ->convert_blessed(1);
my $json_data = $json ->encode( $response ->getData );
if ( $response ->is_success ) {
print $json_data ;
} else {
die "Can not send remote request for $service.$method method with params on $endpoint using AMF" . $client ->getEncoding(). " encoding:\n" . $json_data . "\n" ;
};
|
examples/get-brightcove-videos-metadata.pl
view on Meta::CPAN
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | 'videoRefId' => undef ,
'videoId' => $videoId ,
'featuredLineupFetchInfo' => {
'fetchLevelEnum' => '4' ,
'contentType' => 'VideoLineup' ,
'childLimit' => '100'
}
}
];
my $response = $client ->call( $service . '.' . $method , $params );
my $json = JSON->new;
$json ->ascii(1);
$json ->utf8(1);
$json ->pretty(1);
$json ->allow_blessed(1);
$json ->convert_blessed(1);
my $json_data = $json ->encode( $response ->getData );
if ( $response ->is_success ) {
print $json_data ;
} else {
die "Can not send remote request for $service.$method method with params on $endpoint using AMF" . $client ->getEncoding(). " encoding:\n" . $json_data . "\n" ;
};
|
lib/AMF/Connection.pm
view on Meta::CPAN
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | sub new {
my ( $proto , $endpoint ) = @_ ;
my $class = ref ( $proto ) || $proto ;
my $self = {
'endpoint' => $endpoint ,
'headers' => [],
'http_headers' => {},
'http_cookie_jar' => new HTTP::Cookies(),
'response_counter' => 0,
'encoding' => 0,
'ua' => new LWP::UserAgent(),
'append_to_endpoint' => ''
};
$self ->{ 'ua' }->cookie_jar( $self ->{ 'http_cookie_jar' } );
return bless ( $self , $class );
};
|
lib/AMF/Connection.pm
view on Meta::CPAN
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | foreach my $call ( @batch )
{
next
unless ( defined $call && ref ( $call ) =~ m/HASH/
&& defined $call ->{ 'operation' } && defined $call ->{ 'arguments' });
my $operation = $call ->{ 'operation' };
my $arguments = $call ->{ 'arguments' };
my $body = new AMF::Connection::MessageBody;
$class ->{ 'response_counter' }++;
$body ->setResponse( "/" . $class ->{ 'response_counter' } );
if ( $class ->{ 'encoding' } == 3 ) {
$body ->setTarget( 'null' );
my ( @operation ) = split ( '\.' , $operation );
my $method = pop @operation ;
my $service = join ( '.' , @operation );
my $destination = ( defined $call ->{ 'destination' }) ? $call ->{ 'destination' } : $service ;
my $remoting_message = $class ->_brew_flex_remoting_message( $service , $method , {}, $arguments , $destination );
|
lib/AMF/Connection.pm
view on Meta::CPAN
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
$request ->serialize( $request_stream );
map { $class ->{ 'ua' }->default_header( $_ => $class ->{ 'http_headers' }->{ $_ } ); } keys %{ $class ->{ 'http_headers' } };
my $http_response = $class ->{ 'ua' }->post(
$class ->{ 'endpoint' }. $class ->{ 'append_to_endpoint' },
Content_Type => "application/x-amf" ,
Content => $request_stream ->getStreamData()
);
croak "HTTP POST error: " . $http_response ->status_line. "\n"
unless ( $http_response ->is_success);
my $response_stream = new AMF::Connection::InputStream( $http_response ->decoded_content, $class ->{ 'input_amf_options' });
my $response = new AMF::Connection::Message;
$response ->deserialize( $response_stream );
$class ->_process_response_headers( $response );
my @all = @{ $response ->getBodies() };
return ( wantarray ) ? @all : $all [0];
};
sub setCredentials {
my ( $class , $username , $password ) = @_ ;
$class ->addHeader( 'Credentials' , { 'userid' => $username , 'password' => $password }, 0 );
};
sub _process_response_headers {
my ( $class , $message ) = @_ ;
foreach my $header (@{ $message ->getHeaders()}) {
if ( $header ->getName eq 'ReplaceGatewayUrl' ) {
$class ->setEndpoint( $header ->getValue )
unless ( ref ( $header ->getValue) );
} elsif ( $header ->getName eq 'AppendToGatewayUrl' ) {
$class ->{ 'append_to_endpoint' } = $header ->getValue
unless ( ref ( $header ->getValue) );
};
|
lib/AMF/Connection.pm
view on Meta::CPAN
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | my $service = 'myService' ;
my $method = 'myMethod' ;
my $client = new AMF::Connection( $endpoint );
$client ->setEncoding(3);
$client ->setHTTPCookieJar( HTTP::Cookies->new( file => "/tmp/mycookies.txt" , autosave => 1, ignore_discard => 1 ) );
my @params = ( 'param1' , { 'param2' => 'value2' } );
my $response = $client ->call( "$service.$method" , \ @params );
if ( $response ->is_success ) {
my $result_object = $response ->getData();
} else {
die "Can not send remote request for $service.$method method on $endpoint\n" ;
};
my @response = $client ->callBatch ( { "operation" => $service . $method ", " arguments" => \ @params }, ... );
|
lib/AMF/Connection.pm
view on Meta::CPAN
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
lib/AMF/Connection/InputStream.pm
view on Meta::CPAN
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | sub readLong {
my ( $class ) = @_ ;
my $block = $class ->readBuffer(4);
my @long = unpack ( "N" , $block );
return $long [0];
};
sub readAMFData {
my ( $class ) = @_ ;
my $type = $class ->readByte();
$class ->{ 'cursor' }--;
local $@ = undef ;
|
lib/AMF/Connection/Message.pm
view on Meta::CPAN
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
$stream ->writeAMFData( $class ->getEncoding(), $header ->getValue() );
};
$stream ->writeInt( scalar (@{ $class ->{ 'bodies' }}));
foreach my $body (@{ $class ->{ 'bodies' }}) {
my $target = $body ->getTarget();
$stream ->writeInt( length ( $target ));
$stream ->writeBuffer( $target );
my $response = $body ->getResponse();
$stream ->writeInt( length ( $response ));
$stream ->writeBuffer( $response );
$stream ->writeLong(-1);
$stream ->writeAMFData( $class ->getEncoding(), $body ->getData() );
};
};
sub deserialize {
my ( $class , $stream ) = @_ ;
|
lib/AMF/Connection/Message.pm
view on Meta::CPAN
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | return $class ->{ 'encoding' };
};
1;
|
lib/AMF/Connection/MessageBody.pm
view on Meta::CPAN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | sub new {
my $proto = shift ;
my $class = ref ( $proto ) || $proto ;
my ( $target , $response , $data ) = @_ ;
my $self = {
'target' => $target ,
'response' => $response ,
'data' => $data
};
return bless ( $self , $class );
};
sub setTarget {
my ( $class , $target ) = @_ ;
$class ->{ 'target' } = $target ;
};
sub getTarget {
my ( $class ) = @_ ;
return $class ->{ 'target' };
};
sub setResponse {
my ( $class , $response ) = @_ ;
$class ->{ 'response' } = $response ;
};
sub getResponse {
my ( $class ) = @_ ;
return $class ->{ 'response' };
};
sub setData {
my ( $class , $data ) = @_ ;
$class ->{ 'data' } = $data ;
};
sub getData {
my ( $class ) = @_ ;
|
lib/AMF/Connection/MessageBody.pm
view on Meta::CPAN
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | my ( $class ) = @_ ;
return ( $class ->{ 'target' } =~ m|onDebug|) ? 1 : 0 ;
};
1;
|
lib/AMF/Connection/MessageHeader.pm
view on Meta::CPAN
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | $class ->{ 'required' } = ( $required ) ? 1 : 0 ;
};
1;
|
lib/AMF/Connection/MessageHeader.pm
view on Meta::CPAN
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | } else {
};
my $header2 = new AMF::Connection::MessageHeader( $name , $value ,0);
|