Created
June 11, 2015 12:42
-
-
Save nqounet/f6177ba152cfad2a72fa to your computer and use it in GitHub Desktop.
Slack::IncomingWebHooks
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
package Slack::IncomingWebHooks; | |
use utf8; | |
use Moo; | |
use HTTP::Tiny; | |
use JSON::MaybeXS qw(JSON); | |
has url => (is => 'ro'); | |
has channel => (is => 'ro'); | |
has username => (is => 'ro'); | |
has icon_url => (is => 'ro'); | |
has icon_emoji => (is => 'ro'); | |
has _json => ( | |
is => 'ro', | |
default => sub { JSON->new } | |
); | |
sub send { | |
my $self = shift; | |
my $text = shift; | |
my $params = +{text => $text}; | |
my $json_text = $self->_json->encode($params); | |
return HTTP::Tiny->new->post_form($self->url, +{payload => $json_text}); | |
} | |
1; | |
__END__ | |
## synopsis | |
use Slack::IncomingWebHooks; | |
my $hook = Slack::IncomingWebHooks->new(url => 'https://slack.com/hogehoge'); | |
my $res = $hook->send('Hello World'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment