Last active
October 26, 2022 18:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined( 'MVC_FRAMEWORK') or die; | |
use Clickfwd\Listener\ListenerProvider; | |
class ZapierListenerProvider extends ListenerProvider | |
{ | |
protected $listen = [ | |
'JReviews\Events\ListingWasFirstPublished' => [ | |
'JReviews\Listeners\PostListingToPinterestViaZapier', | |
] | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Follow the instructions in the How to share new listings on Pinterest using Zapier blog post to use these files.