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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
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
|
package Net::XRC;
use 5.005;
use strict;
use vars qw( $VERSION @ISA $AUTOLOAD $DEBUG $PROTO_VERSION $POST_URL
@EXPORT_OK %EXPORT_TAGS ); # @EXPORT
use Exporter;
use LWP;
use Data::Dumper;
use Net::XRC::Response;
use Net::XRC::Data::list;
#use Net::XRC::Data::int;
use Net::XRC::Data::string;
use Net::XRC::Data::boolean;
#use Net::XRC::Data::null;
use Net::XRC::Data::bytes;
#use Net::XRC::Data::list;
use Net::XRC::Data::complex;
@ISA = qw(Exporter);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use Net::XRC ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
%EXPORT_TAGS = ( 'types' => [ qw(
string boolean bytes complex
) ] );
@EXPORT_OK = ( @{ $EXPORT_TAGS{'types'} } );
#@EXPORT = qw(
#
#);
$VERSION = '0.02';
$VERSION = eval $VERSION; # modperlstyle: convert the string into a number
$PROTO_VERSION = '1';
$POST_URL = 'https://xrc.everyone.net/ccc/xrc';
$DEBUG = 0;
my $ua = LWP::UserAgent->new;
$ua->agent("Net::XRC/$VERSION");
$ua->ssl_opts( verify_hostname => 0 );
=head1 NAME
Net::XRC - Perl extension for Everyone.net XRC Remote API
=head1 SYNOPSIS
use Net::XRC qw(:types); # pulls in type subroutines:
# string, boolean, bytes
my $xrc = new Net::XRC (
'clientID' => '1551978',
'password' => 'password',
);
# noop
my $response = $xrc->noop; #returns Net::XRC::Response object
die $response->error unless $response->is_success;
# isAccountName
my $username = 'tofu_beast';
my $response = $xrc->isAccountName( $clientID, $username );
die $response->error unless $response->is_success;
my $available = $res->content;
if ( $available ) {
print "$username is available\n";
} else {
print "$username is not available\n";
}
# isAccountName (numeric)
# note the use of string() to force the datatype to string, which would
# otherwise be (incorrectly) auto-typed as int
my $numeric_username = '54321';
my $response = $xrc->isAccountName( $clientID, string($numeric_username) );
die $response->error unless $response->is_success;
my $available = $res->content;
if ( $available ) {
print "$numeric_username is available\n";
} else {
print "$numeric_username is not available\n";
}
# createUser
my $username = 'tofu_beast';
my $response = $xrc->createUser( $clientID, [], $username, 'password' );
die $response->error unless $response->is_success;
my $uid = $response->content;
print "$username created: uid $uid\n";
# createUser (numeric)
# note the use of string() to force the datatype to string, which would
# otherwise be (incorrectly) auto-typed as int
my $numeric_username = '54321';
my $response = $xrc->createUser( $clientID,
[],
string($numeric_username),
'password'
);
die $response->error unless $response->is_success;
my $uid = $response->content;
print "$numeric_username created: uid $uid\n";
# setUserPassword
$response = $src->setUserPassword( $clientID, 'username', 'new_password' );
if ( $response->is_success ) {
print "password change sucessful";
} else {
print "error changing password: ". $response->error;
}
# suspendUser
$response = $src->suspendUser( $clientID, 'username' );
if ( $response->is_success ) {
print "user suspended";
} else {
print "error suspending user: ". $response->error;
}
# unsuspendUser
$response = $src->unsuspendUser( $clientID, 'username' );
if ( $response->is_success ) {
print "user unsuspended";
} else {
print "error unsuspending user: ". $response->error;
}
# deleteUser
$response = $src->deleteUser( $clientID, 'username' );
if ( $response->is_success ) {
print "user deleted";
} else {
print "error deleting user: ". $response->error;
}
=head1 DESCRIPTION
This module implements a client interface to Everyone.net's XRC Remote API,
enabling a perl application to talk to Everyone.net's XRC server.
This documentation assumes that you are familiar with the XRC documentation
available from Everyone.net (XRC-1.0.5.html or later).
A new Net::XRC object must be created with the I<new> method. Once this has
been done, all XRC commands are accessed via method calls on the object.
=head1 METHODS
=over 4
=item new OPTION => VALUE ...
Creates a new Net::XRC object. The I<clientID> and I<password> options are
required.
=cut
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = { 'version' => $PROTO_VERSION,
@_,
};
bless($self, $class);
}
=item AUTOLOADed methods
All XRC methods are available. See the XRC documentation for methods,
arguments and return values.
Responses are returned as B<Net::XRC::Response> objects. See
L<Net::XRC::Response>.
XRC I<int> arguments are auto-recognized as numeric perl scalars.
XRC I<string> arguments are auto-recognized as all other perl scalars, or
you can import and use the B<string()> subroutine to ensure your string is
not mistaken as an I<int>.
XRC I<null> are auto-recognized as undefined ("undef") perl scalars.
XRC I<boolean> arguements must be explicitly specified as B<boolean()>.
XRC I<bytes> arguments must be explicitly specified as B<bytes()>.
XRC I<list> arguments are passed and returned as perl array references.
XRC I<complex> arguments are passed and returned as perl hash references,
with an additional I<_type> key denotating the argument type
(I<AliasInfo>, I<EmailClientSummary>, I<WebmailPresentation>, I<Letter>).
Optionally, you may use the B<complex()> subroutine to construct them, as in:
C<complex('typename', \%hash)>.
=cut
sub AUTOLOAD {
my $self = shift;
$AUTOLOAD =~ s/.*://;
return if $AUTOLOAD eq 'DESTROY';
my $req = HTTP::Request->new( 'POST' => $POST_URL );
$req->content_type('application/x-eon-xrc-request');
$req->content(
join("\n", map { "$_:". $self->{$_} } keys %$self). #metadata
"\n\n".
$AUTOLOAD. # ' '.
Net::XRC::Data::list->new(\@_)->encode
);
warn "\nPOST $POST_URL\n". $req->content. "\n"
if $DEBUG;
my $res = $ua->request($req);
# Check the outcome of the response
if ($res->is_success) {
warn "\nRESPONSE:\n". $res->content
if $DEBUG;
my $response = new Net::XRC::Response $res->content;
warn Dumper( $response )
if $DEBUG;
$response;
}
else {
#print $res->status_line, "\n";
die $res->status_line, "\n";
}
}
sub string { new Net::XRC::Data::string( shift ); }
sub boolean { new Net::XRC::Data::boolean( shift ); }
sub bytes { new Net::XRC::Data::bytes( shift ); }
sub complex {
my $hr;
if ( ref($_[0]) ) {
$hr = shift;
} else {
$hr = { '_type' => shift,
%{shift()},
};
}
new Net::XRC::Data::complex( $hr );
}
=back
=head1 BUGS
Needs better documentation.
Data type auto-guessing can get things wrong for all-numeric strings. I<bool>
and I<bytes> types must be specified explicitly. Ideally each method should
have a type signature so manually specifying data types would never be
necessary.
The "complex" data types (I<AliasInfo>, I<EmailClientSummary>,
I<WebmailPresentation>, I<Letter>) are untested.
=head1 SEE ALSO
L<Net::XRC::Response>,
Everyone.net XRC Remote API documentation (XRC-1.0.5.html or later)
=head1 AUTHOR
Ivan Kohler E<lt>ivan-xrc@420.amE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2005 Ivan Kohler
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
1;
|