Vedd fel velünk a kapcsolatot ezen a számon: +36-30-925-6635
<?php
/**
* Native FindGore API client
*
* The client needs the following, non standard PHP libraries:
* - cUrl (http://php.net/manual/en/book.curl.php)
* - JSON (http://php.net/manual/en/book.json.php)
*
* @version 1.5.0
*/
class FindGoreNativeClient
{
/**
* @const Hostname of event tracking server
*/
const API_HOST = 'https://api.findgore.com';
/**
* @const Resource of event post API
*/
const API_WHOAMI_RESOURCE = '/whoami/';
/**
* @const Resource of event post API
*/
const API_EVENT_POST_RESOURCE = '/event/@DOMAIN@/@EVENT@/';
/**
* @const Resource of profile emails get API
*/
const API_PROFILE_EMAILS_GET_RESOURCE = '/profile/emails?domain=@DOMAIN@&uuid=@UUID@';
/**
* HTTP request timeout in seconds
* After API_TIMEOUT seconds the methods will return 0 HTTP status
*/
const API_TIMEOUT = 5;
/**
* Test API connection
*
* @param string $user API user name
* @param string $password API password (plain, not encoded)
*
* @return array HTTP response data
*/
public static function whoami($user, $password)
{
$url = static::API_HOST.static::API_WHOAMI_RESOURCE;
return static::requestHttp('get', $user, $password, $url);
}
/**
* Send event to API
*
* @param string $user API user name
* @param string $password API password (plain, not encoded)
* @param string $domain Domain the event belongs to
* @param string $event Event name (lowercase string, optional '_' characters)
* @param array $eventParams Parameters of event
*
* @return array HTTP response data
*/
public static function sendEvent($user, $password, $domain, $event, $eventParams) {
if (
!$domain ||
!$event ||
empty($eventParams)
) {
return;
}
$url = static::API_HOST.str_replace(
array(
'@DOMAIN@',
'@EVENT@',
),
array(
$domain,
$event,
),
static::API_EVENT_POST_RESOURCE
);
return static::requestHttp('post', $user, $password, $url, $eventParams);
}
/**
* Get profile emails from API
*
* @param string $user API user name
* @param string $password API password (plain, not encoded)
* @param string $domain Domain the event belongs to
* @param string $uuid Uuid of profile
*
* @return array HTTP response data
*/
public static function getEmailsOfProfile($user, $password, $domain, $uuid) {
$url = static::API_HOST.str_replace(
array(
'@DOMAIN@',
'@UUID@',
),
array(
$domain,
$uuid,
),
static::API_PROFILE_EMAILS_GET_RESOURCE
);
return static::requestHttp('get', $user, $password, $url);
}
protected static function requestHttp($method, $user, $password, $url, $postData = array())
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_ENCODING, "gzip, deflate");
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $user.":".$password);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, static::API_TIMEOUT);
curl_setopt($curl, CURLOPT_TIMEOUT, static::API_TIMEOUT);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
if (strtolower($method) == 'post') {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postData));
} elseif (strtolower($method) != 'get') {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($method));
}
curl_setopt($curl, CURLOPT_URL, $url);
$curlResult = curl_exec($curl);
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$headers = explode("\n", substr($curlResult, 0, $headerSize));
foreach ($headers as $index => $header) {
$header = trim($header);
if ($header) {
$headers[$index] = $header;
} else {
unset($headers[$index]);
}
}
return array(
'responseHeaders' => $headers,
'status' => curl_getinfo($curl, CURLINFO_HTTP_CODE),
'errorCode' => curl_errno($curl),
'response' => json_decode(substr($curlResult, $headerSize), true),
);
}
}
A Webb & Flow kizárólag a termékeihez adott hivatalos API kliensekkel kapcsolatos support feladatokat látja el. Az egyedi implementációk hibamentesítésében forráskód hiányában nem tud segíteni, a forráskódot nem szeretné megismerni.