Skip to content

Commit

Permalink
catches v2 tests failures
Browse files Browse the repository at this point in the history
* Factual has deprecated and disabled v2 of their api.  Also deprecated
  non-oauth authentication.
* updates documentation to list as deprecated.
* catches error if client-read fails due to auth issues in test.
  • Loading branch information
Andrew Grangaard authored and Andrew Grangaard committed Sep 4, 2012
1 parent edadcd8 commit 404acf8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
14 changes: 9 additions & 5 deletions lib/Net/HTTP/Factual.pm
Expand Up @@ -17,11 +17,15 @@ use Net::HTTP::Spore;
die unless $response->status == 200;
my @json_decoded_data = $response->body->{response}{data};
=cut
=cut

=head1 DESCRIPTION
Net::HTTP::Factual is currently a thin wrapper around Net::HTTP::Spore that provides the necessary json spec file. This interface should expand with use to provide helper functions around the three available REST verbs, read, input and schema
Net::HTTP::Factual is currently a thin wrapper around Net::HTTP::Spore that provides the necessary json spec file. This interface should expand with use to provide helper functions around the three available REST verbs, read, input and schema.
DEPRECATED:
This module only supports factual API version 2. The v2 API has been deprecated by factual.
=head1 SEE ALSO
Expand All @@ -43,17 +47,17 @@ use Moose;
has client => ( is => 'ro', lazy_build => 1 );
has spec => ( is => 'ro', lazy_build => 1 );

sub _build_client
sub _build_client
{
my $self = shift;
my $client = Net::HTTP::Spore->new_from_string($self->spec );
$client->enable( 'Format::JSON' );
$client;
}

sub _build_spec
sub _build_spec
{
my $factual_spec =
my $factual_spec =
'{
"base_url" : "http://api.factual.com",
"api_base_url" : "http://api.factual.com",
Expand Down
22 changes: 12 additions & 10 deletions t/read.t
Expand Up @@ -5,18 +5,20 @@ use warnings;
use_ok('Net::HTTP::Factual');
my $factual = Net::HTTP::Factual->new();

my $output = $factual->client->read(
my $output = eval { $factual->client->read(
api_key => 'S8bAIJhnEnVp05BmMBNeI17Kz3waDgRYU4ykpKU2MVZAMydjiuy88yi1vhBxGsZC',
table_id => 'EZ21ij',
);
)};
SKIP: {
skip "v2 authentication deprecated", 5 if ( $@ && !$output);
is( $output->status, 200 );
is( ref $output->body, 'HASH' );
is( ref $output->body->{response}->{data}, 'ARRAY', 'json decoded body to array' );
is( @{$output->body->{response}->{data}}, 20, '20 items in array' );

is( $output->status, 200 );
is( ref $output->body, 'HASH' );
is( ref $output->body->{response}->{data}, 'ARRAY', 'json decoded body to array' );
is( @{$output->body->{response}->{data}}, 20, '20 items in array' );

my ( $status, $headers, $data ) = @$output;
is ( $status, 200 ) or
diag explain { headers => $headers, data => $data };
my ( $status, $headers, $data ) = @$output;
is ( $status, 200 ) or
diag explain { headers => $headers, data => $data };
}

done_testing;

0 comments on commit 404acf8

Please sign in to comment.