datacircle / datacircle-bundle
Find the best GTM APIs. A Symfony bundle with a client and console commands for Datacircle's public API. You need no API key.
Package info
github.com/waynehamadi/datacircle-bundle
Type:symfony-bundle
pkg:composer/datacircle/datacircle-bundle
Requires
- php: >=8.1
- ext-json: *
- symfony/config: ^6.4|^7.0|^8.0
- symfony/console: ^6.4|^7.0|^8.0
- symfony/dependency-injection: ^6.4|^7.0|^8.0
- symfony/http-client: ^6.4|^7.0|^8.0
- symfony/http-client-contracts: ^3.0
- symfony/http-kernel: ^6.4|^7.0|^8.0
- symfony/string: ^6.4|^7.0|^8.0
Requires (Dev)
- phpunit/phpunit: ^10.5|^11.0|^12.0
- symfony/framework-bundle: ^6.4|^7.0|^8.0
- symfony/yaml: ^6.4|^7.0|^8.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Find the best GTM APIs. We benchmark all the GTM APIs and we put the results on our website.
This bundle adds a Datacircle client and four console commands to a Symfony app. The client and the commands call Datacircle's public API, https://api.datacircle.dev/v1. You need no key and no account.
| Client method | Command | Answer | Call |
|---|---|---|---|
apis() |
datacircle:apis |
Every GTM API on Datacircle, with the API's slug, number of plans, number of providers and best plan | GET /apis |
best($slug, $limit) |
datacircle:best |
One API's plans, sorted by score out of 100, best first. Each plan comes with a rank and a price per 1,000 calls | GET /apis/{slug}/best |
plans($api, $query, $sort, $limit, $offset) |
datacircle:plans |
Plans that match a provider name or plan name. Search all APIs or one API. Sort the plans by score, provider or price | GET /plans |
provider($provider, $plans) |
datacircle:provider |
The APIs a provider sells, and the provider's rank on each API | GET /providers/{slug} |
Install
composer require datacircle/datacircle-bundle
The bundle needs PHP 8.1 or later and Symfony 6.4, 7 or 8. Symfony Flex adds the bundle to config/bundles.php. Without Flex, add this line to config/bundles.php yourself:
Datacircle\DatacircleBundle\DatacircleBundle::class => ['all' => true],
Commands
bin/console datacircle:apis
bin/console datacircle:best email-finder --limit=5
bin/console datacircle:plans hunter --api=email-finder --sort=price
bin/console datacircle:provider "Bright Data" --best
datacircle:apislists every API and the API's slug. Use the slug indatacircle:best.datacircle:best <slug>shows the API's best plans.--limittakes 1 to 50 plans, 10 by default.datacircle:plans [<query>]searches plans by provider name and plan name. A match needs each word of the query in the provider name or the plan name.--apishows only the plans of one API. Give the API's name or slug.--sorttakesscore(the default),providerorprice. Use--limitand--offsetto page through the plans.datacircle:provider <provider>takes the provider's slug or name.--bestadds the provider's best plan on each API.
Add --json to any command to print the Datacircle API's answer as JSON.
The client
Symfony autowires Datacircle\DatacircleBundle\DatacircleClient in your controllers and services:
namespace App\Controller; use Datacircle\DatacircleBundle\DatacircleClient; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Routing\Attribute\Route; final class GtmController extends AbstractController { #[Route('/gtm/best/{slug}')] public function best(DatacircleClient $datacircle, string $slug): JsonResponse { return $this->json($datacircle->best($slug, limit: 3)); } }
The four methods:
$apis = $datacircle->apis(); $best = $datacircle->best('email-finder', limit: 3); foreach ($best['plans'] as $plan) { echo $plan['rank'], ' ', $plan['provider'], ' ', $plan['plan'], ' ', $plan['score'], ' $', $plan['perThousand'], PHP_EOL; } $cheapest = $datacircle->plans(api: 'email-finder', sort: 'price', limit: 5); $ranks = $datacircle->provider('Bright Data', plans: 'none');
Each method returns the API's JSON answer as an array. A plan has about 90 keys. The keys give the provider, plan name, score and price per 1,000 calls (perThousand, in dollars). Other keys give the rate limits, speed and fields. Read https://datacircle.dev/fields for the meaning of each key.
provider() gives the provider's plans on each API. With plans: 'best', you get only the best plan on each API. plans: 'none' gives the ranks with no plans. Bright Data has plans on more than 60 APIs. Use plans: 'best' or plans: 'none' for a shorter answer.
Errors
The client throws Datacircle\DatacircleBundle\ApiError on a 4xx answer, like an unknown slug or a limit over 50. The error message holds the API's own words. The status property holds the HTTP status. The body property holds the API's answer. After an unknown slug, body['slugs'] lists every valid slug. On any other failure, like a network error or a 5xx answer, the client throws a RuntimeException. Each console command prints the error and exits with code 1.
Config
The client calls https://api.datacircle.dev/v1 through your app's http_client service. The client waits 30 seconds for an answer. To change the URL, the timeout or the HTTP client, add config/packages/datacircle.yaml:
datacircle: base_url: 'https://api.datacircle.dev/v1' timeout: 30 http_client: null
All three keys are optional. timeout is in seconds. http_client takes the id of another HTTP client service, like a scoped client of yours. bin/console config:dump-reference datacircle prints the keys and the defaults.
Tests
In a unit test, give the client a MockHttpClient:
use Datacircle\DatacircleBundle\DatacircleClient; use Symfony\Component\HttpClient\MockHttpClient; use Symfony\Component\HttpClient\Response\JsonMockResponse; $datacircle = new DatacircleClient(new MockHttpClient( new JsonMockResponse([['api' => 'Employee email', 'slug' => 'email-finder']]), )); $this->assertSame('email-finder', $datacircle->apis()[0]['slug']);
In a kernel test, set the mock_response_factory option of framework.http_client. The bundle calls through the app's http_client. So your mock answers the bundle's calls too.
Network
Each method makes one HTTPS GET request to https://api.datacircle.dev/v1 and nothing else. The request holds only the method's own arguments: no key and nothing from your app or your app's users. Symfony's HTTP client asks for gzip. The API sends large answers compressed. The API takes up to 60 calls a minute from one IP address. The API can ask the client to wait. The client then waits once, for a minute at most. The bundle stores nothing.
Links
- Datacircle: https://datacircle.dev
- The API: https://datacircle.dev/api
- The API's spec: https://api.datacircle.dev/v1/openapi.json
- What each key means: https://datacircle.dev/fields
MIT license.