File Coverage

blib/lib/Net/HTTP/Factual.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Net::HTTP::Factual;
2             {
3             $Net::HTTP::Factual::VERSION = '0.122480';
4             }
5 1     1   1454 use warnings;
  1         3  
  1         188  
6 1     1   7 use strict;
  1         2  
  1         41  
7 1     1   631 use Net::HTTP::Spore;
  0            
  0            
8              
9             #ABSTRACT: RESTful interface to Factual.com, using Spore
10              
11              
12              
13             use Moose;
14             has client => ( is => 'ro', lazy_build => 1 );
15             has spec => ( is => 'ro', lazy_build => 1 );
16              
17             sub _build_client
18             {
19             my $self = shift;
20             my $client = Net::HTTP::Spore->new_from_string($self->spec );
21             $client->enable( 'Format::JSON' );
22             $client;
23             }
24              
25             sub _build_spec
26             {
27             my $factual_spec =
28             '{
29             "base_url" : "http://api.factual.com",
30             "api_base_url" : "http://api.factual.com",
31             "version" : "v2",
32             "expected" : "200",
33             "methods" : {
34             "input" : {
35             "params" : {
36             "required" : [
37             "table_id",
38             "values",
39             "api_key"
40             ],
41             "optional" : [
42             "subject_key"
43             ]
44             },
45             "api_format" : [
46             "json"
47             ],
48             "documentation" : "This method either suggests corrections for single rows of data or inserts new rows of data in tables. It is important to note that corrections to tables may not immediately be reflected in Factual tables or, in some cases, may never appear. This is because one of the features of Factual tables is to try to discern the most accurate value for a fact based on numerous inputs, of which the ones provided in your input call may only be one of many.\\nIn order to suggest a correction to a fact in an existing row, either provide the subject_key for the row you wish to correct, or the subject itself (along with your fact inputs). It is acceptable to provide both a subject_key AND the subject. If the subject disagrees with the currently displayed subject for the row identified by that subject_key, you are suggesting that the subject\'s actual label should be corrected. Of note: is important to discern the difference between subject_keys and UUIDs. Many tables use UUIDs as their subject. In these cases, the UUID is merely the subject itself. live example.\nIn order to add a row, omit the subject_key and specify the subject you are adding to the table, as well as any facts about the subject you wish to also include. The Factual Server API will determine if this is an existing subject (and add your facts as inputs to that subject) or add a new row for the subject otherwise. If you are using a table that auto-generates subject labels (such as UUIDs), pass in null as the subject label. ",
49             "path" : "/v2/tables/:table_id/input",
50             "method" : "GET",
51             "description" : "inserts or updates a row in a table"
52             },
53             "read" : {
54             "params" : {
55             "required" : [
56             "table_id"
57             ],
58             "optional" : [
59             "sort_by",
60             "sort_dir",
61             "limit",
62             "offset",
63             "filters",
64             "subject_key",
65             "include_schema"
66             ]
67             },
68             "api_format" : [
69             "json"
70             ],
71             "documentation" : "The read method enables you to read either a single row or a number of rows from a table. It has support for limits and offsets to support paging through data. It also has support for filtering data.",
72             "path" : "/v2/tables/:table_id/read",
73             "method" : "GET",
74             "description" : "read from a table"
75             },
76             "schema" : {
77             "required" : [
78             "table_id",
79             "api_key"
80             ],
81             "api_format" : [
82             "json"
83             ],
84             "documentation" : "The schema call returns meta-data about a Factual Table.",
85             "path" : "/v2/tables/:table_id/schema",
86             "method" : "GET",
87             "description" : "get the schema for a table"
88             }
89             },
90             "name" : "factual",
91             "author" : [
92             "andrew grangaard <spazm@cpan.org>"
93             ],
94             "meta" : {
95             "documentation" : "http://wiki.developer.factual.com/"
96             }
97             }';
98             }
99              
100             1;
101              
102             __END__
103              
104             =pod
105              
106             =head1 NAME
107              
108             Net::HTTP::Factual - RESTful interface to Factual.com, using Spore
109              
110             =head1 VERSION
111              
112             version 0.122480
113              
114             =head1 SYNOPSIS
115              
116             my $api_key = "... get this from factual.com ...";
117             my $fact = Net::HTTP::Factual->new();
118              
119             my $response = $fact->client->read(
120             api_key => $api_key,
121             table_id => 'EZ21ij',
122             );
123             die unless $response->status == 200;
124             my @json_decoded_data = $response->body->{response}{data};
125              
126             =head1 DESCRIPTION
127              
128             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.
129              
130             DEPRECATED:
131              
132             This module only supports factual API version 2. The v2 API has been deprecated by factual.
133              
134             =head1 SEE ALSO
135              
136             =over 4
137              
138             =item Spore
139              
140             http://search.cpan.org/perldoc?Spore
141              
142             =item Net::HTTP::Spore
143              
144             http://search.cpan.org/perldoc?Net::HTTP::Spore
145              
146             =back
147              
148             =head1 AUTHOR
149              
150             Andrew Grangaard <spazm@cpan.org>
151              
152             =head1 COPYRIGHT AND LICENSE
153              
154             This software is copyright (c) 2010 by Andrew Grangaard.
155              
156             This is free software; you can redistribute it and/or modify it under
157             the same terms as the Perl 5 programming language system itself.
158              
159             =cut