PHP Class Factual

This is a refactoring of the Factual Driver by Aaron: https://github.com/Factual/factual-java-driver
Author: Tyler
Datei anzeigen Open project: factual/factual-php-driver Class Usage Examples

Protected Properties

Property Type Description
$config OAuthStore object
$configPath geocoder object (unsupported, experimental)
$connectTimeout maximum number of seconds for the network function to execute (0 = no timeout)
$curlTimeout debug flag
$debug array of queries teed up for multi
$factHome
$fetchQueue last table queried
$geocoder array from config.ini file on construct
$lastTable where the config file is found: path + file
$signer string assigned from config

Public Methods

Method Description
__construct ( $key, $secret ) Constructor. Creates authenticated access to Factual.
boost ( $factualBoost ) : object Improves search results by associating query with selected record
buildQuery ( $tableName, $query ) : string Build query string without running fetch
clear ( $clear ) : object Clear a/n attribute/s from a Factual entity
debug ( ) Turns on debugging for output to stderr
factualAutoload ( $className ) Autoloader for file dependencies Called by spl_autoload_register() to avoid conflicts with autoload() methods from other libs
factualReverseGeocode ( $point, $tableName = "places" ) : the Reverse geocodes by returning a response containing the address nearest a given point.
fetch ( $tableName, $query ) : object Factual Fetch Abstraction
fetchRow ( string $tableName, $factualID ) : the Runs a read query against the specified Factual table.
flag ( $flagger ) : object Flags entties as problematic
geocode ( $address ) : array Geocodes address string or placename
geocoderDiagnostics ( )
match ( $tableName, $vars ) : object Matches entity to Factual ID (shortcut method)
multiFetch ( ) : response Use this to send all queued reads as a multi request
multiQueue ( $table, $query, $handle ) Queue a request for inclusion in a multi request.
rawGet ( $path, $params ) : string Runs a GET request against the specified endpoint path, using the given parameters and your OAuth credentials. Returns the raw response body returned by Factual. The necessary URL base will be automatically prepended to path. If you need to change it, e.g. to make requests against a development instance of the Factual service, use Factual::setFactHome().
rawPost ( $path, $body, $params = null ) : string Runs a GET request against the specified endpoint path, using the given parameters and your OAuth credentials. Returns the raw response body returned by Factual. The necessary URL base will be automatically prepended to path. If you need to change it, e.g. to make requests against a development instance of the Factual service, use Factual::setFactHome().
resolve ( $tableName, $vars ) : object Resolves and returns resolved entity or null (shortcut method)
reverseGeocode ( $lon, $lat ) : array Reverse geocodes long/lat to the smallest bounding WOEID
schema ( $tableName ) : object
setConnectTimeout ( $secs ) Sets maximum number of seconds to connect to the server before bailing
setCurlTimeout ( $secs ) Sets maximum number of seconds to the network function to execute
setFactHome ( $urlBase ) : void Change the base URL at which to contact Factual's API. This may be useful if you want to talk to a test or staging server withou changing config Example value: http://staging.api.v3.factual.com/t/
submit ( $submittor ) : object Submit data to Factual
version ( ) : string Gets driver version

Protected Methods

Method Description
getGeocoder ( ) : array Geocodes address string or placename
loadConfig ( ) : void Loads config file from ini
request ( string $urlStr, string $requestMethod = "GET", null $params = null, array $curlOptions = [] ) : array Sign the request, perform a curl request and return the results
setConfigPath ( $path ) : void Sets location of config file at runtime
toQueryString ( $parameters ) : string Converts and encodes parameter array to a query string
urlForBoost ( $tableName )
urlForClear ( $tableName, $factualID )
urlForDiffs ( $tableName, $query )
urlForFacets ( $tableName, $query )
urlForFetch ( $tableName, $query )
urlForFetchRow ( $tableName, $factualID )
urlForFlag ( $tableName, $factualID )
urlForGeocode ( $tableName, $query )
urlForMatch ( $tableName, $query )
urlForMulti ( )
urlForResolve ( $tableName, $query )
urlForSchema ( $tableName )
urlForSubmit ( $tableName, $factualID = null )

Method Details

__construct() public method

Constructor. Creates authenticated access to Factual.
public __construct ( $key, $secret )

boost() public method

Improves search results by associating query with selected record
public boost ( $factualBoost ) : object
return object

buildQuery() public method

Build query string without running fetch
public buildQuery ( $tableName, $query ) : string
return string

clear() public method

Clear a/n attribute/s from a Factual entity
public clear ( $clear ) : object
return object Submit Response object

debug() public method

Turns on debugging for output to stderr
public debug ( )

factualAutoload() public static method

Autoloader for file dependencies Called by spl_autoload_register() to avoid conflicts with autoload() methods from other libs
public static factualAutoload ( $className )

factualReverseGeocode() public method

Reverse geocodes by returning a response containing the address nearest a given point.
public factualReverseGeocode ( $point, $tableName = "places" ) : the
return the response of running a reverse geocode query for point against Factual.

fetch() public method

Factual Fetch Abstraction
public fetch ( $tableName, $query ) : object
return object ReadResponse object with result of running query against Factual.

fetchRow() public method

Runs a read query against the specified Factual table.
public fetchRow ( string $tableName, $factualID ) : the
$tableName string the name of the table you wish to query (e.g., "places")
return the response of running query against Factual.

flag() public method

Flags entties as problematic
public flag ( $flagger ) : object
return object Flag Response object

geocode() public method

Geocodes address string or placename
public geocode ( $address ) : array
return array

geocoderDiagnostics() public method

public geocoderDiagnostics ( )

getGeocoder() protected method

Geocodes address string or placename
protected getGeocoder ( ) : array
return array

loadConfig() protected method

Loads config file from ini
protected loadConfig ( ) : void
return void

match() public method

Matches entity to Factual ID (shortcut method)
public match ( $tableName, $vars ) : object
return object MatchResponse

multiFetch() public method

Use this to send all queued reads as a multi request
public multiFetch ( ) : response
return response for a multi request

multiQueue() public method

Queue a request for inclusion in a multi request.
public multiQueue ( $table, $query, $handle )

rawGet() public method

Runs a GET request against the specified endpoint path, using the given parameters and your OAuth credentials. Returns the raw response body returned by Factual. The necessary URL base will be automatically prepended to path. If you need to change it, e.g. to make requests against a development instance of the Factual service, use Factual::setFactHome().
public rawGet ( $path, $params ) : string
return string JSON response body from the Factual API.

rawPost() public method

Runs a GET request against the specified endpoint path, using the given parameters and your OAuth credentials. Returns the raw response body returned by Factual. The necessary URL base will be automatically prepended to path. If you need to change it, e.g. to make requests against a development instance of the Factual service, use Factual::setFactHome().
public rawPost ( $path, $body, $params = null ) : string
return string JSON response body from the Factual API.

request() protected method

Sign the request, perform a curl request and return the results
protected request ( string $urlStr, string $requestMethod = "GET", null $params = null, array $curlOptions = [] ) : array
$urlStr string unsigned URL request
$requestMethod string
$params null
$curlOptions array
return array ex: array ('code'=>int, 'headers'=>array(), 'body'=>string)

resolve() public method

Resolves and returns resolved entity or null (shortcut method)
public resolve ( $tableName, $vars ) : object
return object ResolveResponse

reverseGeocode() public method

Reverse geocodes long/lat to the smallest bounding WOEID
public reverseGeocode ( $lon, $lat ) : array
return array single result

schema() public method

public schema ( $tableName ) : object
return object SchemaResponse object

setConfigPath() protected method

Sets location of config file at runtime
protected setConfigPath ( $path ) : void
return void

setConnectTimeout() public method

Sets maximum number of seconds to connect to the server before bailing
public setConnectTimeout ( $secs )

setCurlTimeout() public method

Sets maximum number of seconds to the network function to execute
public setCurlTimeout ( $secs )

setFactHome() public method

Change the base URL at which to contact Factual's API. This may be useful if you want to talk to a test or staging server withou changing config Example value: http://staging.api.v3.factual.com/t/
public setFactHome ( $urlBase ) : void
return void

submit() public method

Submit data to Factual
public submit ( $submittor ) : object
return object Submit Response object

toQueryString() protected method

Converts and encodes parameter array to a query string
protected toQueryString ( $parameters ) : string
return string

urlForBoost() protected method

protected urlForBoost ( $tableName )

urlForClear() protected method

protected urlForClear ( $tableName, $factualID )

urlForDiffs() protected method

protected urlForDiffs ( $tableName, $query )

urlForFacets() protected method

protected urlForFacets ( $tableName, $query )

urlForFetch() protected method

protected urlForFetch ( $tableName, $query )

urlForFetchRow() protected method

protected urlForFetchRow ( $tableName, $factualID )

urlForFlag() protected method

protected urlForFlag ( $tableName, $factualID )

urlForGeocode() protected method

protected urlForGeocode ( $tableName, $query )

urlForMatch() protected method

protected urlForMatch ( $tableName, $query )

urlForMulti() protected method

protected urlForMulti ( )

urlForResolve() protected method

protected urlForResolve ( $tableName, $query )

urlForSchema() protected method

protected urlForSchema ( $tableName )

urlForSubmit() protected method

protected urlForSubmit ( $tableName, $factualID = null )

version() public method

Gets driver version
public version ( ) : string
return string

Property Details

$config protected_oe property

OAuthStore object
protected $config

$configPath protected_oe property

geocoder object (unsupported, experimental)
protected $configPath

$connectTimeout protected_oe property

maximum number of seconds for the network function to execute (0 = no timeout)
protected $connectTimeout

$curlTimeout protected_oe property

debug flag
protected $curlTimeout

$debug protected_oe property

array of queries teed up for multi
protected $debug

$factHome protected_oe property

protected $factHome

$fetchQueue protected_oe property

last table queried
protected $fetchQueue

$geocoder protected_oe property

array from config.ini file on construct
protected $geocoder

$lastTable protected_oe property

where the config file is found: path + file
protected $lastTable

$signer protected_oe property

string assigned from config
protected $signer