Skip to content

Instantly share code, notes, and snippets.

@jreviews
Last active October 26, 2022 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jreviews/c49d45e2a18d80a47d29b7a9f1de8ba2 to your computer and use it in GitHub Desktop.
Save jreviews/c49d45e2a18d80a47d29b7a9f1de8ba2 to your computer and use it in GitHub Desktop.
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 Clickfwd\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 )
{
// 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 = \FWDHttp::post($this->webhook, $payload);
}
}
}
}
<?php
defined( 'MVC_FRAMEWORK') or die;
use Clickfwd\Listener\ListenerProvider;
class ZapierListenerProvider extends ListenerProvider
{
protected $listen = [
'JReviews\Events\ListingWasFirstPublished' => [
'JReviews\Listeners\PostListingToPinterestViaZapier',
]
];
}
@jreviews
Copy link
Author

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