| 1 | package Net::Braintree::HTTP; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use HTTP::Request; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Net::Braintree::Xml; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Carp qw(confess); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 0 | ▶ | has 'config' => (is => 'ro', default => sub { Net::Braintree->configuration }); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 10 | |||||||||||
| 11 | 0 | ▶ | sub post { | ||||||||
|
Subroutine
post: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 12 | 0 | my ($self, $path, $params) = @_; | |||||||||
| 13 | 0 | $self -> make_request($path, $params, 'POST'); | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub put { | ||||||||
|
Subroutine
put: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 17 | 0 | my ($self, $path, $params) = @_; | |||||||||
| 18 | 0 | $self -> make_request($path, $params, 'PUT'); | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | sub get { | ||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 22 | 0 | my ($self, $path, $params) = @_; | |||||||||
| 23 | 0 | $self -> make_request($path, $params, 'GET'); | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | sub delete { | ||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 27 | 0 | my ($self, $path, $params) = @_; | |||||||||
| 28 | 0 | $self -> make_request($path, undef, 'DELETE'); | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | sub make_request { | ||||||||
|
Subroutine
make_request: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 32 | 0 | my ($self, $path, $params, $verb) = @_; | |||||||||
| 33 | 0 | my $request = HTTP::Request->new($verb => $self->config->base_merchant_url . $path); | |||||||||
| 34 | 0 | $request->headers->authorization_basic($self->config->public_key, $self->config->private_key); | |||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | if ($params) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | $request->content(hash_to_xml($params)); | |||||||||
| 38 | 0 | $request->content_type("text/xml; charset=utf-8"); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 0 | $request->header("X-ApiVersion" => $self->config->api_version); | |||||||||
| 42 | 0 | $request->header("environment" => $self->config->environment); | |||||||||
| 43 | 0 | $request->header("User-Agent" => "Braintree Perl Module " . Net::Braintree->VERSION); | |||||||||
| 44 | |||||||||||
| 45 | 0 | my $agent = LWP::UserAgent->new; | |||||||||
| 46 | 0 | my $response = $agent->request($request); | |||||||||
| 47 | |||||||||||
| 48 | 0 | $self->check_response_code($response->code); | |||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | if($response->header('Content-Length') > 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | return xml_to_hash($response->content); | |||||||||
| 52 | } else { | ||||||||||
| 53 | 0 | return {http_status => $response->code}; | |||||||||
| 54 | } | ||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub check_response_code { | ||||||||
|
Subroutine
check_response_code: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||
| 58 | 0 | my ($self, $code) = @_; | |||||||||
| 59 | 0 | ▶ | confess "NotFoundError" if $code eq '404'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | ▶ | confess "AuthenticationError" if $code eq '401'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | ▶ | confess "AuthorizationError" if $code eq '403'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | ▶ | confess "ServerError" if $code eq '500'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | ▶ | confess "DownForMaintenance" if $code eq '503'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 1 | 1; | |||||||||