annotate lib/Benzin/Bugzilla/XmlRpcClient.pm @ 7:29309bc8d932

initial objects to work with bugzilla web service
author cin
date Fri, 04 Sep 2015 19:41:28 +0300
parents
children cc7244ab1b9f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
1 package Benzin::Bugzilla::XmlRpcClient;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
2 use strict;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
3
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
4 use LWP::UserAgent;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
5 use XMLRPC::Lite;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
6 use YAML::XS qw(Dump);
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
7
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
8 use IMPL::require {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
9 Bug => 'Benzin::Bugzilla::Bug'
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
10 };
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
11
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
12 use fields qw(url apikey);
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
13
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
14 use constant { SELF => __PACKAGE__ };
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
15
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
16 sub new {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
17 my $class = shift;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
18 $class = ref $class || $class;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
19
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
20 my $inst = fields::new($class);
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
21 $inst->CTOR(@_);
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
22
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
23 return $inst;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
24 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
25
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
26 sub CTOR {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
27 my SELF $this = shift;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
28 my %params = @_;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
29
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
30 $this->{url} = $params{url} or die "An url is required";
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
31 $this->{apikey} = $params{apikey} if $params{apikey};
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
32 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
33
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
34 sub GetBugs {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
35 my SELF $this = shift;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
36
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
37 return [map Bug->new($_), @{$this->_CallService( 'Bug.get', shift )->{bugs} || [] }];
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
38 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
39
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
40 sub FillBugComments {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
41 my SELF $this = shift;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
42 my $bugs = shift || [];
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
43
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
44 if ( my @ids = map $_->{id}, @$bugs ) {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
45
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
46 my $comments = $this->_CallService( 'Bug.comments', { ids => \@ids } );
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
47
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
48 for my Bug $bug (@$bugs) {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
49 map @{$comments->{$bug->{id}}->{comments} || [] };
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
50 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
51 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
52 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
53
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
54 sub _CallService {
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
55 my SELF $this = shift;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
56 my ( $method, $params ) = @_;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
57
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
58 die "Method must be specified" unless $method;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
59 $params ||= {};
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
60
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
61 $params->{api_key} = $this->{apikey};
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
62 my $url = URI->new_abs( 'xmlrpc.cgi', $this->{url} );
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
63
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
64 my $result = XMLRPC::Lite->proxy($url)->call( $method, $params );
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
65
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
66 die $result->fault if $result->fault;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
67 return $result->result;
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
68 }
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
69
29309bc8d932 initial objects to work with bugzilla web service
cin
parents:
diff changeset
70 1;