Download the PHP package silktide/brightlocal-api without Composer

On this page you can find all versions of the php package silktide/brightlocal-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package brightlocal-api

brightlocal-api

Wrapper for BrightLocal API. Work in progress.

Build Status Code Climate Test Coverage

Methods implemented:

Create a client

Using the client factory

This library comes with a convenient factory for those not using DI. Just use the following to create an API client:

$clientFactory = new \Silktide\BrightLocalApi\ClientFactory();
$client = $clientFactory->createClient([YOUR API KEY], [YOUR API SECRET]);  

Using dependency injection

If you don't know what this is, ignore this part.

If you're using syringe , a config is included for convenience. If you want to wire it up in your own DI container, take a look inside the ClientFactory class to see how the Client and its dependencies are created.

Batches

Create a batch

$batch = $client->createNewBatch();

Commit batch for processing

$batch->commit();

Get results

Gets the batch results. Note - due to the way BrightLocal takes time to gather results, you may prefer to poll for results (see below).

$results = $batch->getResults();

Poll for results

As it may take time for BrightLocal to complete the batch, a convenience method will poll for results until they are available. This hangs the execution of your script until the BrightLocal results are ready. By default, the results will be checked every 5 seconds for up to 20 attempts (this can be overriden by passing values to this method). An exception will be thrown if the batch has not completed before the maximum number of attempts have been made.

$results = $batch->pollForResults();

Local directories

Fetch profile details by business data

$client->fetchProfileDetailsByBusinessData($batch, [
    'business-names' => 'Silktide',
    'country' => 'GBR',
    'city' => 'Derby',
    'postcode' => 'DE248HR',
    'local-directory' => 'google'
]);

The directory should be one listed in BrightLocal's appendices. Country should be 3-letter ISO

Directory config helper

To help with talking to the BrightLocal API, a helper is included which can help with your integration.

Find out which directories can be used

This function returns an array of directory IDs which BrightLocal supports in a given country.

$helper = Silktide\BrightLocalApi\Data\DirectoryConfigHelper(new Silktide\BrightLocalApi\Data\DataLoader());
$helper->getDirectoriesForCountry('GBR');

Get the "friendly name" of a directory

BrightLocal's API contains a reference to all the directories they support, but all the names are lowercase with punctuation removed (e.g. 2findlocal, canadaspace). This function returns a "friendly" name for your given directory.

$helper = Silktide\BrightLocalApi\Data\DirectoryConfigHelper(new Silktide\BrightLocalApi\Data\DataLoader());
$helper->getLabelForDirectory('192'); // returns '192.com'

Complete examples

Fetch profile details for a business

// Create client (using factory)
$clientFactory = new \Silktide\BrightLocalApi\ClientFactory();
$client = $clientFactory->createClient([YOUR API KEY], [YOUR API SECRET]);  

// Directories to fetch
$directories = [
    'google',
    'facebook',
    'yell',
    'scoot'
];

//Create batch
$batch = $client->createNewBatch();

// Add directory checks for each local directory
foreach ($directories as $directory) {
    $client->fetchProfileDetailsByBusinessData($batch, [
        'business-names' => 'Silktide\nSilktide Ltd',
        'country' => 'GBR',
        'city' => 'Derby',
        'postcode' => 'DE248HR',
        'local-directory' => $directory
    ]);
}

// Commit the batch for processing
$batch->commit();

// Poll for results
$results = $batch->pollForResults();

General

Error handling

In the event of an issue or bad result from the API, an exception will be thrown. You should expect exceptions to be thrown in your application and handle them gracefully.


All versions of brightlocal-api with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.0
guzzlehttp/guzzle Version ^6.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package silktide/brightlocal-api contains the following files

Loading the files please wait ....