Skip to content

Instantly share code, notes, and snippets.

@JulienGadanho
Last active August 21, 2024 19:20
Show Gist options
  • Save JulienGadanho/55ec4889252fd47bc966d3e7b1a2ff0f to your computer and use it in GitHub Desktop.
Save JulienGadanho/55ec4889252fd47bc966d3e7b1a2ff0f to your computer and use it in GitHub Desktop.
LinkFinder API PHP Class
<?php
//for an other language, convert with chatGPT
class LinkFinderAPI {
private $apiKey;
private $baseUrl = 'https://app.link-finder.net/api/v2/';
public function __construct($apiKey) {
$this->apiKey = $apiKey;
}
public function listPlatforms() {
$endpoint = 'listPlatforms.php';
$params = [
'apiKey' => $this->apiKey,
];
return $this->sendRequest($endpoint, $params);
}
public function checkDomain($domain) {
$endpoint = 'checkDomain.php';
$params = [
'domain' => $domain,
'apiKey' => $this->apiKey,
];
return $this->sendRequest($endpoint, $params);
}
public function checkPricesInBulk($urls) {
$endpoint = 'bulk.php';
$data = [
'apiKey' => $this->apiKey,
'urls' => $urls,
];
return $this->sendRequest($endpoint, $data, true);
}
private function sendRequest($endpoint, $params = [], $isPost = false) {
$url = $this->baseUrl . $endpoint;
if (!$isPost) {
$url .= '?' . http_build_query($params);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($isPost) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
}
$response = curl_exec($ch);
curl_close($ch);
//echo $response;
return json_decode($response, true);
}
}
// Usage
$apiKey = ''; // Replace with your actual API key
$linkFinder = new LinkFinderAPI($apiKey);
// List all platforms
$platforms = $linkFinder->listPlatforms();
print_r($platforms);
// Check prices for a specific domain
$domainPrices = $linkFinder->checkDomain('https://luciolaria.com/fr/');
print_r($domainPrices);
// Check prices in bulk
$urls = [
'http://35mm-compact.com/',
'margs-home-again.com',
'https://alexitauzin.com'
];
// Sanitize ';' in URLs
$sanitizedUrls = array_map(function($url) {
return str_replace(';', '%3B', $url);
}, $urls);
$urls = implode(';', $sanitizedUrls);
$bulkPrices = $linkFinder->checkPricesInBulk($urls);
print_r($bulkPrices);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment