Skip to content

Instantly share code, notes, and snippets.

@ryjen
Last active June 23, 2016 16:52
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 ryjen/7715b23c0166d7a320f24bc3690efa14 to your computer and use it in GitHub Desktop.
Save ryjen/7715b23c0166d7a320f24bc3690efa14 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
#
# Summary:
# Sends a post for facebook with or without a link.
# Requirements:
# Create a couple maker and facebook recipes in IFTTT.com
# 1) text post named 'post_facebook' with value1 as the content
# 2) link post named 'post_link_facebook' with value1 as the link and value2 as the content
# Set a IFTTT_MAKER_KEY environment variable containing your key
# Author:
# Ryan Jennings <info@ryan-jennings.net>
#
use LWP::Curl;
use Getopt::Long;
sub send_post
{
my ($post, $link) = @_;
my $curl = LWP::Curl->new();
my $key = $ENV{'IFTTT_MAKER_KEY'};
my $params;
my $event;
if (!defined $key || length $key == 0) {
print "Please set an IFTTT_MAKER_KEY environment variable\n";
return 1;
}
if (defined $link && length $link > 0) {
$event = "post_link_facebook";
$params = { "value1" => $link, "value2" => $post };
} else {
$event = "post_facebook";
$params = { "value1" => $post };
}
$curl->post("https://maker.ifttt.com/trigger/$event/with/key/$key", $params);
print "Posted!\n";
return 0;
}
sub main
{
my $link;
my $post;
GetOptions("--link=s", \$link);
print "Enter post content. Send with '\$' on an empty line:\n";
while(<STDIN>) {
my $line = $_;
chomp $line;
if ($line eq "\$") {
last;
}
$post .= $line;
$post .= "\n";
}
if (!defined $post || length $post == 0) {
print "You have to post something!\n";
return 1;
}
return send_post($post, $link);
}
exit(&main);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment