From e1aea961a9dd83d6d14b4e45cbf4a70b00fbe18c Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Mon, 19 May 2014 00:44:19 -0400 Subject: Bug 993223 - Notify Review Board when a bug is made confidential r=glob --- .../Push/lib/Connector/ReviewBoard/Client.pm | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 extensions/Push/lib/Connector/ReviewBoard/Client.pm (limited to 'extensions/Push/lib/Connector/ReviewBoard/Client.pm') diff --git a/extensions/Push/lib/Connector/ReviewBoard/Client.pm b/extensions/Push/lib/Connector/ReviewBoard/Client.pm new file mode 100644 index 000000000..7ec4938d2 --- /dev/null +++ b/extensions/Push/lib/Connector/ReviewBoard/Client.pm @@ -0,0 +1,67 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +package Bugzilla::Extension::Push::Connector::ReviewBoard::Client; + +use 5.10.1; +use strict; +use warnings; + +use Carp qw(croak); +use LWP::UserAgent; +use Scalar::Util qw(blessed); +use URI; + +use Bugzilla::Extension::Push::Connector::ReviewBoard::ReviewRequest; + +sub new { + my ($class, %params) = @_; + + croak "->new() is a class method" if blessed($class); + return bless(\%params, $class); +} + +sub username { $_[0]->{username} } +sub password { $_[0]->{password} } +sub base_uri { $_[0]->{base_uri} } +sub realm { $_[0]->{realm} // 'Web API' } +sub proxy { $_[0]->{proxy} } + +sub _netloc { + my $self = shift; + + my $uri = URI->new($self->base_uri); + return $uri->host . ':' . $uri->port; +} + +sub useragent { + my $self = shift; + + unless ($self->{useragent}) { + my $ua = LWP::UserAgent->new(agent => Bugzilla->params->{urlbase}); + $ua->credentials( + $self->_netloc, + $self->realm, + $self->username, + $self->password, + ); + $ua->proxy('https', $self->proxy) if $self->proxy; + $ua->timeout(10); + + $self->{useragent} = $ua; + } + + return $self->{useragent}; +} + +sub review_request { + my $self = shift; + + return Bugzilla::Extension::Push::Connector::ReviewBoard::ReviewRequest->new(client => $self, @_); +} + +1; -- cgit v1.2.3-24-g4f1b