File Coverage

blib/lib/WebService/Backlog.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package WebService::Backlog;
2              
3             # $Id: Backlog.pm 600 2008-05-09 13:48:50Z yamamoto $
4              
5 13     13   9993 use strict;
  13         28  
  13         491  
6 13     13   387 use 5.008001;
  13         40  
  13         695  
7              
8             our $VERSION = '0.08';
9              
10 13     13   74 use Carp;
  13         21  
  13         1343  
11 13     13   26109 use RPC::XML::Client;
  0            
  0            
12              
13             use WebService::Backlog::Project;
14             use WebService::Backlog::Component;
15             use WebService::Backlog::Version;
16             use WebService::Backlog::User;
17             use WebService::Backlog::Issue;
18             use WebService::Backlog::FindCondition;
19              
20             use WebService::Backlog::CreateIssue;
21             use WebService::Backlog::UpdateIssue;
22             use WebService::Backlog::SwitchStatus;
23              
24             sub new {
25             my ( $class, %args ) = @_;
26             croak('space must be specified') unless ( defined $args{space} );
27             croak('username must be specified') unless ( defined $args{username} );
28             croak('password must be specified') unless ( defined $args{password} );
29              
30             my $client = RPC::XML::Client->new(
31             'https://' . $args{space} . '.backlog.jp/XML-RPC' );
32             $client->credentials( 'Backlog Basic Authenticate',
33             $args{username}, $args{password} );
34             $client->useragent->parse_head(0);
35             $client->useragent->env_proxy;
36             $client->useragent->agent("WebService::Backlog/$VERSION");
37             bless { %args, client => $client }, $class;
38             }
39              
40             sub getProjects {
41             my $self = shift;
42             my $req = RPC::XML::request->new( 'backlog.getProjects', );
43             my $res = $self->{client}->send_request($req);
44             croak "Error backlog.getProjects : " . $res->value->{faultString}
45             if ( $res->is_fault );
46              
47             my @projects = ();
48             for my $project ( @{ $res->value } ) {
49             push( @projects, WebService::Backlog::Project->new($project) );
50             }
51             return \@projects;
52             }
53              
54             sub getProject {
55             my ( $self, $keyOrId ) = @_;
56             croak "key or projectId must be specified." unless ($keyOrId);
57             my $req = RPC::XML::request->new( 'backlog.getProject', $keyOrId, );
58             my $res = $self->{client}->send_request($req);
59             croak "Error backlog.getProject : " . $res->value->{faultString}
60             if ( $res->is_fault );
61             return unless ( $res->value->{id} );
62             return WebService::Backlog::Project->new( $res->value );
63             }
64              
65             sub getComponents {
66             my ( $self, $pid ) = @_;
67             croak "projectId must be specified." unless ($pid);
68             my $req = RPC::XML::request->new( 'backlog.getComponents', $pid, );
69             my $res = $self->{client}->send_request($req);
70             croak "Error backlog.getComponents : " . $res->value->{faultString}
71             if ( $res->is_fault );
72             my @components = ();
73             for my $component ( @{ $res->value } ) {
74             push( @components, WebService::Backlog::Component->new($component) );
75             }
76             return \@components;
77             }
78              
79             sub getVersions {
80             my ( $self, $pid ) = @_;
81             croak "projectId must be specified." unless ($pid);
82             my $req = RPC::XML::request->new( 'backlog.getVersions', $pid, );
83             my $res = $self->{client}->send_request($req);
84             croak "Error backlog.getVersions : " . $res->value->{faultString}
85             if ( $res->is_fault );
86             my @versions = ();
87             for my $version ( @{ $res->value } ) {
88             push( @versions, WebService::Backlog::Version->new($version) );
89             }
90             return \@versions;
91             }
92              
93             sub getUsers {
94             my ( $self, $pid ) = @_;
95             croak "projectId must be specified." unless ($pid);
96             my $req = RPC::XML::request->new( 'backlog.getUsers', $pid, );
97             my $res = $self->{client}->send_request($req);
98             croak "Error backlog.getUsers : " . $res->value->{faultString}
99             if ( $res->is_fault );
100             my @users = ();
101             for my $user ( @{ $res->value } ) {
102             push( @users, WebService::Backlog::User->new($user) );
103             }
104             return \@users;
105             }
106              
107             sub getIssue {
108             my ( $self, $keyOrId ) = @_;
109             croak "key or issueId must be specified." unless ($keyOrId);
110             my $req = RPC::XML::request->new( 'backlog.getIssue', $keyOrId, );
111             my $res = $self->{client}->send_request($req);
112             croak "Error backlog.getIssue : " . $res->value->{faultString}
113             if ( $res->is_fault );
114             return unless ( $res->value->{id} );
115             return WebService::Backlog::Issue->new( $res->value );
116             }
117              
118             sub getComments {
119             my ( $self, $id ) = @_;
120             croak "issueId must be specified." unless ($id);
121             my $req = RPC::XML::request->new( 'backlog.getComments', $id, );
122             my $res = $self->{client}->send_request($req);
123             croak "Error backlog.getComments : " . $res->value->{faultString}
124             if ( $res->is_fault );
125             my @comments = ();
126             for my $comment ( @{ $res->value } ) {
127             push( @comments, WebService::Backlog::Comment->new($comment) );
128             }
129             return \@comments;
130             }
131              
132             sub countIssue {
133             my ( $self, $arg ) = @_;
134             my $cond;
135              
136             if ( ref($arg) eq 'WebService::Backlog::FindCondition' ) {
137             $cond = $arg->toCountCond;
138             }
139             elsif ( ref($arg) eq 'HASH' ) {
140             $cond = WebService::Backlog::FindCondition->new($arg)->toCountCond;
141             }
142             else {
143             croak( 'arg must be WebService::Backlog::FindCondition object'
144             . ' or reference to hash. ['
145             . ref($arg)
146             . ']' );
147             }
148             croak("projectId must be specified.") unless ( $cond->{projectId} );
149              
150             my $req = RPC::XML::request->new( 'backlog.countIssue', $cond );
151             my $res = $self->{client}->send_request($req);
152             croak "Error backlog.countIssue : " . $res->value->{faultString}
153             if ( $res->is_fault );
154              
155             return $res->value;
156             }
157              
158             sub findIssue {
159             my ( $self, $arg ) = @_;
160             my $cond;
161              
162             if ( ref($arg) eq 'WebService::Backlog::FindCondition' ) {
163             $cond = $arg->toFindCond;
164             }
165             elsif ( ref($arg) eq 'HASH' ) {
166             $cond = WebService::Backlog::FindCondition->new($arg)->toFindCond;
167             }
168             else {
169             croak( 'arg must be WebService::Backlog::FindCondition object'
170             . ' or reference to hash. ['
171             . ref($arg)
172             . ']' );
173             }
174             croak("projectId must be specified.") unless ( $cond->{projectId} );
175              
176             my $req = RPC::XML::request->new( 'backlog.findIssue', $cond );
177             my $res = $self->{client}->send_request($req);
178             croak "Error backlog.findIssue : " . $res->value->{faultString}
179             if ( $res->is_fault );
180              
181             my @issues = ();
182             for my $issue ( @{ $res->value } ) {
183             push( @issues, WebService::Backlog::Issue->new($issue) );
184             }
185             return \@issues;
186             }
187              
188             sub createIssue {
189             my ( $self, $arg ) = @_;
190             my $issue;
191             if ( ref($arg) eq 'WebService::Backlog::CreateIssue' ) {
192             $issue = $arg;
193             }
194             elsif ( ref($arg) eq 'HASH' ) {
195             $issue = WebService::Backlog::CreateIssue->new($arg);
196             }
197             else {
198             croak( 'arg must be WebService::Backlog::CreateIssue object'
199             . ' or reference to hash. ['
200             . ref($arg)
201             . ']' );
202             }
203             croak("projectId must be specified.") unless ( $issue->projectId );
204             croak("summary must be specified.") unless ( $issue->summary );
205              
206             my $req = RPC::XML::request->new( 'backlog.createIssue', $issue->hash );
207             my $res = $self->{client}->send_request($req);
208             croak "Error backlog.createIssue : " . $res->value->{faultString}
209             if ( $res->is_fault );
210              
211             return WebService::Backlog::Issue->new( $res->value );
212             }
213              
214             sub updateIssue {
215             my ( $self, $arg ) = @_;
216             my $issue;
217             if ( ref($arg) eq 'WebService::Backlog::UpdateIssue' ) {
218             $issue = $arg;
219             }
220             elsif ( ref($arg) eq 'HASH' ) {
221             $issue = WebService::Backlog::UpdateIssue->new($arg);
222             }
223             else {
224             croak( 'arg must be WebService::Backlog::UpdateIssue object'
225             . ' or reference to hash. ['
226             . ref($arg)
227             . ']' );
228             }
229             croak("key must be specified.") unless ( $issue->key );
230              
231             my $req = RPC::XML::request->new( 'backlog.updateIssue', $issue->hash );
232             my $res = $self->{client}->send_request($req);
233             croak "Error backlog.updateIssue : " . $res->value->{faultString}
234             if ( $res->is_fault );
235              
236             return WebService::Backlog::Issue->new( $res->value );
237             }
238              
239             sub switchStatus {
240             my ( $self, $arg ) = @_;
241             my $switch;
242             if ( ref($arg) eq 'WebService::Backlog::SwitchStatus' ) {
243             $switch = $arg;
244             }
245             elsif ( ref($arg) eq 'HASH' ) {
246             $switch = WebService::Backlog::SwitchStatus->new($arg);
247             }
248             else {
249             croak( 'arg must be WebService::Backlog::SwitchStatus object'
250             . ' or reference to hash. ['
251             . ref($arg)
252             . ']' );
253             }
254             croak("key must be specified.") unless ( $switch->key );
255             croak("StatusId must be specified.") unless ( $switch->statusId );
256              
257             my $req = RPC::XML::request->new( 'backlog.switchStatus', $switch->hash );
258             my $res = $self->{client}->send_request($req);
259             croak "Error backlog.switchStatus : " . $res->value->{faultString}
260             if ( $res->is_fault );
261              
262             return WebService::Backlog::Issue->new( $res->value );
263             }
264              
265             1;
266             __END__