line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Iperntiy::API::Request |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Contact: doomy [at] dokuleser [dot] org |
4
|
|
|
|
|
|
|
# Copyright 2008 Winfried Neessen |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# $Id$ |
7
|
|
|
|
|
|
|
# Last modified: [ 2011-01-13 12:32:58 ] |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
### Module definitions {{{ |
10
|
|
|
|
|
|
|
package Ipernity::API::Request; |
11
|
4
|
|
|
4
|
|
24
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
132
|
|
12
|
4
|
|
|
4
|
|
24
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
96
|
|
13
|
4
|
|
|
4
|
|
16051
|
use HTTP::Request; |
|
4
|
|
|
|
|
133565
|
|
|
4
|
|
|
|
|
136
|
|
14
|
4
|
|
|
4
|
|
41
|
use URI; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1165
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw(Ipernity::API HTTP::Request); |
17
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
18
|
|
|
|
|
|
|
# }}} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
### Module constructor {{{ |
21
|
|
|
|
|
|
|
sub new |
22
|
|
|
|
|
|
|
{ |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
### Define class and object and read arguments |
25
|
0
|
|
|
0
|
1
|
|
my ( $class, %args ) = @_; |
26
|
0
|
|
|
|
|
|
my $self = new HTTP::Request; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
## Initalize placeholder for API signature |
29
|
0
|
|
|
|
|
|
$self->{ 'api_sig' } = {}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
### Some static definitions |
32
|
0
|
|
|
|
|
|
$self->method( 'POST' ); |
33
|
0
|
|
|
|
|
|
$self->uri( 'http://api.ipernity.com/api/' ); |
34
|
0
|
|
|
|
|
|
$self->header( 'User-Agent' => 'Ipernity::API v' . $Ipernity::API::VERSION ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
### Assign arguments to my object |
37
|
0
|
|
|
|
|
|
foreach my $key ( keys %args ) |
38
|
|
|
|
|
|
|
{ |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$self->{ 'args' }->{ $key } = $args{ $key }; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
### We need a method to call at least! |
45
|
0
|
0
|
|
|
|
|
warn 'Please provide at least a calling method' unless( defined( $self->{ 'args' }->{ 'method' } ) ); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
### Reference object to class |
48
|
0
|
|
|
|
|
|
bless $self, $class; |
49
|
0
|
|
|
|
|
|
return $self; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
# }}} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
### Encode arguements and build a HTTP request // encode() {{{ |
55
|
|
|
|
|
|
|
sub encode |
56
|
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
### Get objects |
58
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
### Build an URI object |
61
|
0
|
|
|
|
|
|
my $uri = URI->new( 'http:' ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
### Build an HTTP valid request URI |
64
|
0
|
|
|
|
|
|
delete( $self->{ 'args' }->{ 'method' } ); |
65
|
0
|
|
|
|
|
|
$uri->query_form( $self->{ 'args' } ); |
66
|
0
|
|
|
|
|
|
my $content = $uri->query; |
67
|
0
|
|
|
|
|
|
my $length = length( $content ); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
### Add POST fields to HTTP header |
70
|
0
|
|
|
|
|
|
$self->header( 'Content-Type' => 'application/x-www-form-urlencoded' ); |
71
|
0
|
0
|
|
|
|
|
if( defined( $content ) ) |
72
|
|
|
|
|
|
|
{ |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$self->header( 'Content-Length' => $length ); |
75
|
0
|
|
|
|
|
|
$self->content( $content ); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
# }}} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
__END__ |