source: tools/trunk/lib/Sophie/Client.pm @ 411

Last change on this file since 411 was 411, checked in by nanardon, 12 years ago
  • use a config file for sophie_notify
  • fix login
  • kill warn()
File size: 2.6 KB
Line 
1package Sophie::Client;
2
3use 5.010000;
4use strict;
5use warnings;
6use RPC::XML;
7use base qw(RPC::XML::Client);
8use Sophie::Client::Transaction;
9$RPC::XML::FORCE_STRING_ENCODING = 1;
10
11our $VERSION = '0.01';
12
13sub 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
35sub 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
59sub 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
70sub ts {
71    my ($self, $distrib) = @_;
72    return Sophie::Client::Transaction->new($self, $distrib);
73}
74
751;
76
77__END__
78# Below is stub documentation for your module. You'd better edit it!
79
80=head1 NAME
81
82Sophie::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
91Stub documentation for Sophie::Client, created by h2xs. It looks like the
92author of the extension was negligent enough to leave the stub
93unedited.
94
95Blah blah blah.
96
97
98=head1 SEE ALSO
99
100Mention other useful documentation such as the documentation of
101related modules or operating system documentation (such as man pages
102in UNIX), or any relevant external documentation such as RFCs or
103standards.
104
105If you have a mailing list set up for your module, mention it here.
106
107If you have a web site set up for your module, mention it here.
108
109=head1 AUTHOR
110
111Olivier Thauvin, E<lt>olivier@localdomainE<gt>
112
113=head1 COPYRIGHT AND LICENSE
114
115Copyright (C) 2010 by Olivier Thauvin
116
117This library is free software; you can redistribute it and/or modify
118it under the same terms as Perl itself, either Perl version 5.12.2 or,
119at your option, any later version of Perl 5 you may have available.
120
121
122=cut
Note: See TracBrowser for help on using the repository browser.