Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
The api accessor was unneeded and also not required, which was causin…
…g exceptions when we tried to use it.
  • Loading branch information
oalders committed Apr 22, 2016
1 parent 9891052 commit 0ca1989
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions lib/MetaCPAN/Web/Model/API.pm
Expand Up @@ -3,18 +3,25 @@ package MetaCPAN::Web::Model::API;
use Moose;
extends 'Catalyst::Model';

has [qw(api api_secure)] => ( is => 'ro' );
use namespace::autoclean;

use Encode ();
use JSON::MaybeXS;
use HTTP::Request ();
use AnyEvent::Curl::Multi;
use Try::Tiny 0.09;
use Encode ();
use HTTP::Request ();
use JSON::MaybeXS;
use MetaCPAN::Web::Types qw( Uri );
use MooseX::ClassAttribute;
use namespace::autoclean;
use Try::Tiny qw( catch try );

class_has client => ( is => 'ro', lazy_build => 1 );

has api_secure => (
is => 'ro',
isa => Uri,
coerce => 1,
required => 1,
);

sub _build_client {
return AnyEvent::Curl::Multi->new( max_concurrency => 5 );
}
Expand Down Expand Up @@ -58,13 +65,16 @@ sub model {

sub request {
my ( $self, $path, $search, $params ) = @_;

my ( $token, $method ) = @$params{qw(token method)};
$path .= "?access_token=$token" if ($token);
my $req = $self->cv;
my $req = $self->cv;
my $url = $self->api_secure->clone;
$url->path($path);

my $request = HTTP::Request->new(
$method ? $method : $search ? 'POST' : 'GET',
( $token ? $self->api_secure : $self->api ) . $path,
[ 'Content-type' => 'application/json' ],
$url, [ 'Content-type' => 'application/json' ],
);

# encode_json returns an octet string
Expand Down

0 comments on commit 0ca1989

Please sign in to comment.