PHP code example of trustedsearch / php-trustedsearch

1. Go to this page and download the library: Download trustedsearch/php-trustedsearch library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

trustedsearch / php-trustedsearch example snippets


	
	$publicKey = "XXXX";
	$privateKey = "YYYYY";
	TrustedSearch::setApiPublicKey($publicKey);
	TrustedSearch::setApiPrivateKey($privateKey);
    TrustedSearch::setApiEnvironment('sandbox');  //Options are sandbox or production
    TrustedSearch::setApiVersion('1'); //You MUST set this. 1 is currently the only option. There is no default.



$resource = TrustedSearch_Token::get($username, $password);
$data = $resource->getData();
echo $data['token'];
echo $data['expires'];
echo json_encode($data['userSettings']);


$resource = TrustedSearch_DirectoryListing::get();
$data = $resource->getData();
echo json_encode($data);

$testLocation = '45c907bc-6d2f-5f62-9610-5395858d41a0';
$resource = TrustedSearch_DirectoryListing::get($testLocation);
$data = $resource->getData();
echo json_encode($data);

$resource = TrustedSearch_DirectoryListing::since(1380611103);
$data = $resource->getData();
echo json_encode($data);


$data = array(
	array(
		'audit'=> false,
		'externalId' => 'mary_t123456240',
		'order' => array(
			"onBehalfOf" => "Partner ABC",
			'packages' => array(
				'ut002500'
			),
			'termsAccepted' => true
		),
		'contact' => array(
			'firstName' => 'Mary',
			'lastName' => 'Poppins',
			'email' => '[email protected]',
			'phone' => '8055551234'
		),
		'business' => array(
			'name' => "Jeremy's Umbrellas Shop",
			'street' => "17 Cherry Tree Lane",
			'city' => "London",
			'state' => "CA",
			'postalCode' => "93001",
			'phoneLocal' => "(805) 555-9876",
			'phoneTollFree'     => '(800) 555-5555',
			'fax'               => '(801) 555-5555',
			'website'           => 'http://www.marysumbrellas.com',
			'email'             => '[email protected]',
			'slogan'            => "A spoon full of sugar helps the medicine go down.",
			'descriptionLong'   => 'some long desc...',
			'descriptionMedium' => 'some medium desc...',
			'descriptionShort'  => 'some short desc...',
			'keywords'          => 'rain gear, fashion, outdoor gear',
			'paymentMethods'    => array( 'mastercard', 'visa'),
			'category1'			=> 'outdoor',
			'category2'			=> 'fashion',
			'category3'			=> 'rain gear',
			'yearEstablished'   => '1808',
			'productsOffered'   => 'umbrellas, rain coats',
			'languagesSpoken'   => 'english, japanese, spanish',
			'hoursOfOperation'  => 'MF08001700H',
			'numberEmployees' 	=> 23,
			'logoUrl'           => "http://trustedsearch.org/images/imgTS_Logo.png",
			'logoSquareUrl'     => 'http://trustedsearch.org/images/imgTS_Logo.png',
			'imageUrl'=> array(
					'http://trustedsearch.org/images/imgTS_Logo.png',
					'http://trustedsearch.org/images/imgTS_Logo.png',
					'http://trustedsearch.org/images/imgTS_Logo.png',
					'http://trustedsearch.org/images/imgTS_Logo.png',
					'http://trustedsearch.org/images/imgTS_Logo.png',
				),
			'videoUrl' => 'http://www.youtube.com/watch?v=cXuTiAHdxTg'
		)
	),
	array(
		'audit'=> false,
		'externalId' => 'mary_t123456239',
		'order' => array(
			"onBehalfOf" => "Partner ABC",
			'packages' => array(
				'ut002500'
			),
			'termsAccepted' => true
		),
		'contact' => array(
			'firstName' => 'Mary',
			'lastName' => 'Poppins',
			'email' => '[email protected]',
			'phone' => '8055551234'
		),
		'business' => array(
			'name' => "Jeremy's Umbrellas Shop",
			'street' => "17 Cherry Tree Lane",
			'city' => "London",
			'state' => "CA",
			'postalCode' => "93001",
			'phoneLocal' => "(805) 555-9876",
			'phoneTollFree'     => '(800) 555-5555',
			'fax'               => '(801) 555-5555',
			'website'           => 'http://www.marysumbrellas.com',
			'email'             => '[email protected]',
			'slogan'            => "A spoon full of sugar helps the medicine go down.",
			'descriptionLong'   => 'some long desc...',
			'descriptionMedium' => 'some medium desc...',
			'descriptionShort'  => 'some short desc...',
			'keywords'          => 'rain gear, fashion, outdoor gear',
			'paymentMethods'    => array( 'mastercard', 'visa'),
			'category1'			=> 'outdoor',
			'category2'			=> 'fashion',
			'category3'			=> 'rain gear',
			'yearEstablished'   => '1808',
			'productsOffered'   => 'umbrellas, rain coats',
			'languagesSpoken'   => 'english, japanese, spanish',
			'hoursOfOperation'  => 'MF08001700H',
			'numberEmployees' 	=> 23,
			'logoUrl'           => "http://trustedsearch.org/images/imgTS_Logo.png",
			'logoSquareUrl'     => 'http://trustedsearch.org/images/imgTS_Logo.png',
			'imageUrl'=> array(
					'http://trustedsearch.org/images/imgTS_Logo.png',
					'http://trustedsearch.org/images/imgTS_Logo.png',
					'http://trustedsearch.org/images/imgTS_Logo.png',
					'http://trustedsearch.org/images/imgTS_Logo.png',
					'http://trustedsearch.org/images/imgTS_Logo.png',
				),
			'videoUrl' => 'http://www.youtube.com/watch?v=cXuTiAHdxTg'
		)
	)
);  // end data array

$resource = TrustedSearch_LocalBusiness::create($data);
$data = $resource->getData();
echo json_encode($data);


    $data = //Use same data structure as above to "Submit New Business Listings"
 
    try{
        $resource = TrustedSearch_LocalBusiness::validate($data);
            $data = $resource->getData();
            echo json_encode($data);
    }catch(TrustedSearch_Error $e){
        $errors = $e->getValidations();
        echo $errors['business.descriptionShort'];
        
    }


$uuid = '45c907bc-6d2f-5f62-9610-5395858d41a0'; //Take from response above.
$response = TrustedSearch_DirectoryListing::simulate($uuid);
echo json_encode($response->getData());



$page = 1;
$filters = array(
	fulfillment_status_id = "33"
);
$perPage = 25;
$sort = 'asc';
$orderBy = 'created_at';

$resource = TrustedSearch_Listing::index($page, $filters, $perPage, $sort, $orderBy);
$data = $resource->getData();
echo json_encode($data);



    try {
      $token = TrustedSearch_Token::get($username, $password);
    } catch (TrustedSearch_AuthenticationError $e) {
    	echo $e->getMessage();
	    $this->assertEquals(401, $e->getCode());
    }