1 | package Sophie::Client; |
---|
2 | |
---|
3 | use 5.010000; |
---|
4 | use strict; |
---|
5 | use warnings; |
---|
6 | use RPC::XML; |
---|
7 | use base qw(RPC::XML::Client); |
---|
8 | use Sophie::Client::Transaction; |
---|
9 | $RPC::XML::FORCE_STRING_ENCODING = 1; |
---|
10 | |
---|
11 | our $VERSION = '0.01'; |
---|
12 | |
---|
13 | sub new { |
---|
14 | my ($class, %options) = @_; |
---|
15 | |
---|
16 | my $self = $class->SUPER::new( |
---|
17 | $options{server} || 'http://sophie.zarb.org/rpc' |
---|
18 | ); |
---|
19 | if ($options{proxy}) { |
---|
20 | $self->useragent->proxy([ 'http' ], $options{proxy}); |
---|
21 | } else { |
---|
22 | $self->useragent->env_proxy; |
---|
23 | } |
---|
24 | |
---|
25 | $self->{options} = { %options }; |
---|
26 | |
---|
27 | |
---|
28 | if ($options{login}) { |
---|
29 | login($self) or die "Can't login"; |
---|
30 | } |
---|
31 | |
---|
32 | bless($self, $class); |
---|
33 | } |
---|
34 | |
---|
35 | sub login { |
---|
36 | my ($self) = @_; |
---|
37 | my %options = %{ $self->{options} }; |
---|
38 | if ($options{login}) { |
---|
39 | my $res = $self->send_request('login', |
---|
40 | $options{login}, |
---|
41 | $options{password}); |
---|
42 | if (ref $res && !$res->is_fault) { |
---|
43 | $self->request->header('cookie', $$res); |
---|
44 | return 1; |
---|
45 | } else { |
---|
46 | return; |
---|
47 | } |
---|
48 | } else { |
---|
49 | my $res = $self->send_request('user.session'); |
---|
50 | if (ref $res && !$res->is_fault) { |
---|
51 | $self->request->header('cookie', $$res); |
---|
52 | return 1; |
---|
53 | } else { |
---|
54 | return; |
---|
55 | } |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | sub pkgid_to_filename { |
---|
60 | my ($self, $pkgid) = @_; |
---|
61 | |
---|
62 | my $res = $self->send_request('rpms.basicinfo', $pkgid); |
---|
63 | if (ref $res && !$res->is_fault) { |
---|
64 | return $res->value->{filename}; |
---|
65 | } else { |
---|
66 | die "XML RPC error"; |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | sub ts { |
---|
71 | my ($self, $distrib) = @_; |
---|
72 | return Sophie::Client::Transaction->new($self, $distrib); |
---|
73 | } |
---|
74 | |
---|
75 | 1; |
---|
76 | |
---|
77 | __END__ |
---|
78 | # Below is stub documentation for your module. You'd better edit it! |
---|
79 | |
---|
80 | =head1 NAME |
---|
81 | |
---|
82 | Sophie::Client - Perl extension for blah blah blah |
---|
83 | |
---|
84 | =head1 SYNOPSIS |
---|
85 | |
---|
86 | use Sophie::Client; |
---|
87 | blah blah blah |
---|
88 | |
---|
89 | =head1 DESCRIPTION |
---|
90 | |
---|
91 | Stub documentation for Sophie::Client, created by h2xs. It looks like the |
---|
92 | author of the extension was negligent enough to leave the stub |
---|
93 | unedited. |
---|
94 | |
---|
95 | Blah blah blah. |
---|
96 | |
---|
97 | |
---|
98 | =head1 SEE ALSO |
---|
99 | |
---|
100 | Mention other useful documentation such as the documentation of |
---|
101 | related modules or operating system documentation (such as man pages |
---|
102 | in UNIX), or any relevant external documentation such as RFCs or |
---|
103 | standards. |
---|
104 | |
---|
105 | If you have a mailing list set up for your module, mention it here. |
---|
106 | |
---|
107 | If you have a web site set up for your module, mention it here. |
---|
108 | |
---|
109 | =head1 AUTHOR |
---|
110 | |
---|
111 | Olivier Thauvin, E<lt>olivier@localdomainE<gt> |
---|
112 | |
---|
113 | =head1 COPYRIGHT AND LICENSE |
---|
114 | |
---|
115 | Copyright (C) 2010 by Olivier Thauvin |
---|
116 | |
---|
117 | This library is free software; you can redistribute it and/or modify |
---|
118 | it under the same terms as Perl itself, either Perl version 5.12.2 or, |
---|
119 | at your option, any later version of Perl 5 you may have available. |
---|
120 | |
---|
121 | |
---|
122 | =cut |
---|