| 1 | #!/bin/false | ||
| 2 | # PODNAME: BZ::Client::API | ||
| 3 | # ABSTRACT: Abstract base class for the clients of the Bugzilla API. | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings 'all'; | ||
| 7 | |||
| 8 | package BZ::Client::API; | ||
| 9 | $BZ::Client::API::VERSION = '4.4001'; | ||
| 10 | |||
| 11 | sub api_call { | ||
| 12 | my(undef, $client, $methodName, $params, $options) = @_; | ||
| 13 | return $client->api_call($methodName, $params, $options) | ||
| 14 | } | ||
| 15 | |||
| 16 | sub error { | ||
| 17 | my(undef, $client, $message, $http_code, $xmlrpc_code) = @_; | ||
| 18 | return $client->error($message, $http_code, $xmlrpc_code) | ||
| 19 | } | ||
| 20 | |||
| 21 | sub new { | ||
| 22 | my $class = shift; | ||
| 23 | my $self = { @_ }; | ||
| 24 | bless($self, ref($class) || $class); | ||
| 25 | return $self | ||
| 26 | } | ||
| 27 | |||
| 28 | # Move stuff here so we dont do it over and over | ||
| 29 | |||
| 30 | sub _create { | ||
| 31 | my(undef, $client, $methodName, $params, $key) = @_; | ||
| 32 | $key ||= 'id'; | ||
| 33 | my $sub = ( caller(1) )[3]; | ||
| 34 | $client->log('debug', $sub . ': Running'); | ||
| 35 | my $result = __PACKAGE__->api_call($client, $methodName, $params); | ||
| 36 | my $id = $result->{$key}; | ||
| 37 | if (!$id) { | ||
| 38 | __PACKAGE__->error($client, "Invalid reply by server, expected $methodName $key."); | ||
| 39 | } | ||
| 40 | $client->log('debug', "$sub: Returned $id"); | ||
| 41 | return $id | ||
| 42 | } | ||
| 43 | |||
| 44 | sub _returns_array { | ||
| 45 | my(undef, $client, $methodName, $params, $key) = @_; | ||
| 46 | my $sub = ( caller(1) )[3]; | ||
| 47 | $client->log('debug',$sub . ': Running'); | ||
| 48 | my $result = __PACKAGE__->api_call($client, $methodName, $params); | ||
| 49 | my $foo = $result->{$key}; | ||
| 50 | if (!$foo || 'ARRAY' ne ref($foo)) { | ||
| 51 | __PACKAGE__->error($client, "Invalid reply by server, expected array of $methodName details"); | ||
| 52 | } | ||
| 53 | $client->log('debug', "$sub: Recieved results"); | ||
| 54 | return wantarray ? @$foo : $foo | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | |||
| 59 | 1; | ||
| 60 | |||
| 61 | __END__ | ||
| 62 | |||
| 63 | =pod | ||
| 64 | |||
| 65 | =encoding UTF-8 | ||
| 66 | |||
| 67 | =head1 NAME | ||
| 68 | |||
| 69 | BZ::Client::API - Abstract base class for the clients of the Bugzilla API. | ||
| 70 | |||
| 71 | =head1 VERSION | ||
| 72 | |||
| 73 | version 4.4001 | ||
| 74 | |||
| 75 | =head1 SYNOPSIS | ||
| 76 | |||
| 77 | This is an abstract base class for classes like L<BZ::Client::Product>, which | ||
| 78 | are subclassing this one, in order to inherit common functionality. | ||
| 79 | |||
| 80 | None of these methods are useful to end users. | ||
| 81 | |||
| 82 | =head1 METHODS | ||
| 83 | |||
| 84 | =head2 api_call | ||
| 85 | |||
| 86 | Wraps C<BZ::Client::api_call> | ||
| 87 | |||
| 88 | =head2 error | ||
| 89 | |||
| 90 | Wraps C<BZ::Client::error> | ||
| 91 | |||
| 92 | =head2 new | ||
| 93 | |||
| 94 | Generic C<new()> function. Saving doing it over and over. | ||
| 95 | |||
| 96 | =head2 _create | ||
| 97 | |||
| 98 | Calls something on the Bugzilla Server, and returns and ID. | ||
| 99 | |||
| 100 | =head2 _returns_array | ||
| 101 | |||
| 102 | Calls something on the Bugzilla Server, and returns an array / arrayref. | ||
| 103 | |||
| 104 | =head1 SEE ALSO | ||
| 105 | |||
| 106 | L<BZ::Client> | ||
| 107 | |||
| 108 | =head1 AUTHORS | ||
| 109 | |||
| 110 | =over 4 | ||
| 111 | |||
| 112 | =item * | ||
| 113 | |||
| 114 | Dean Hamstead <dean@bytefoundry.com.au> | ||
| 115 | |||
| 116 | =item * | ||
| 117 | |||
| 118 | Jochen Wiedmann <jochen.wiedmann@gmail.com> | ||
| 119 | |||
| 120 | =back | ||
| 121 | |||
| 122 | =head1 COPYRIGHT AND LICENSE | ||
| 123 | |||
| 124 | This software is copyright (c) 2017 by Dean Hamstad. | ||
| 125 | |||
| 126 | This is free software; you can redistribute it and/or modify it under | ||
| 127 | the same terms as the Perl 5 programming language system itself. | ||
| 128 | |||
| 129 | =cut |