Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to automatically share listings on Pinterest using Zapier https://www.jreviews.com/blog/share-listings-on-pinterest-using-zapier
<?php
namespace JReviews\Listeners;
defined( 'MVC_FRAMEWORK') or die;
use cmsFramework;
use S2Array;
use JReviews\Listeners\Traits\ListenerSetting;
use Clickfwd\Listener\QueueableListener;
use League\Event\EventInterface;
use GuzzleHttp\Client as Guzzle;
\S2App::import('ListenerTrait','listener_setting','jreviews');
class PostListingToPinterestViaZapier extends QueueableListener
{
use ListenerSetting;
/**
* Add task to the queue
* @var bool
*/
protected $queue = false;
/**
* Execution delay in seconds
* @var int
*/
protected $queue_delay = 5*60;
/**
* Webhook URL
* @var string
*/
protected $webhook = '';
public function handle(EventInterface $event)
{
$listing = $event->getListing();
if ( $listing )
{
$mainMediaUrl = S2Array::get($listing,'MainMedia.media_info.image.url');
// Only send request if there's a main media photo for the listing
if ( $mainMediaUrl )
{
$client = new Guzzle();
// Build the listing payload that will be sent to the Zapier webhook
$payload = [
'title' => $listing['Listing']['title'],
'summary' => strip_tags($listing['Listing']['summary']),
'summary_html' => $listing['Listing']['summary'],
'description' => strip_tags($listing['Listing']['description']),
'description_html' => $listing['Listing']['description'],
'category' => $listing['Category']['title'],
'directory' => $listing['Directory']['title'],
'listing_url' => cmsFramework::route($listing['Listing']['url']),
'main_media_url'=> $mainMediaUrl,
];
$response = $client->post($this->webhook, [
\GuzzleHttp\RequestOptions::JSON => $payload
]);
}
}
}
}
<?php
defined( 'MVC_FRAMEWORK') or die;
use Clickfwd\Listener\ListenerProvider;
class ZapierListenerProvider extends ListenerProvider
{
protected $listen = [
'JReviews\Events\ListingWasFirstPublished' => [
'JReviews\Listeners\PostListingToPinterestViaZapier',
]
];
}
@jreviews

This comment has been minimized.

Copy link
Owner Author

jreviews commented Nov 15, 2019

Follow the instructions in the How to share new listings on Pinterest using Zapier blog post to use these files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.