From 77b0c36408113a9719397f5acbbd73a5f431e7d6 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 22 May 2011 20:08:18 -0700 Subject: Rename trigger script --- scripts/post_to_hook.pl | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 scripts/post_to_hook.pl (limited to 'scripts/post_to_hook.pl') diff --git a/scripts/post_to_hook.pl b/scripts/post_to_hook.pl new file mode 100644 index 0000000..2e2f717 --- /dev/null +++ b/scripts/post_to_hook.pl @@ -0,0 +1,56 @@ +use strict; +use warnings; + +use jitterbug; +use jitterbug::Schema; + +use JSON; +use YAML qw/LoadFile Dump/; + +use File::Temp qw/tempdir/; + +use Dancer::Test; +use Dancer::Config qw/setting/; +use File::Spec::Functions; + +my $content = LoadFile(catfile(qw/t data hook_data.yml/)); +my $db_file = catfile( qw/t data jitterbug.db/ ); +my $dsn = 'dbi:SQLite:dbname=' . $db_file; +my $schema = jitterbug::Schema->connect($dsn); +# assume we have a deployed schema +# $schema->deploy; + +setting plugins => { + DBIC => { + schema => { + skip_automake => 1, + pckg => "jitterbug::Schema", + connect_info => [$dsn] + } + } +}; + +{ + my $response = dancer_response( + POST => '/hook/', + { + headers => + [ 'Content-Type' => 'application/x-www-form-urlencoded' ], + body => _generate_post_request($content), + } + ); + + printf "Response was: %s\n", $response->{status}; +} + +sub _generate_post_request { + my $content = shift; + my $payload = "payload=" . JSON::encode_json($content); + open my $in, '<', \$payload; + + $ENV{'CONTENT_LENGTH'} = length($payload); + $ENV{'CONTENT_TYPE'} = 'application/x-www-form-urlencoded'; + $ENV{'psgi.input'} = $in; + return $payload; +} + -- cgit 1.4.1 From 9836838062eb5d9687b67b2fc36717bfc2c34c50 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 22 May 2011 20:09:31 -0700 Subject: Allow a file to be specified to post_to_hook.pl --- scripts/post_to_hook.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts/post_to_hook.pl') diff --git a/scripts/post_to_hook.pl b/scripts/post_to_hook.pl index 2e2f717..55d3d73 100644 --- a/scripts/post_to_hook.pl +++ b/scripts/post_to_hook.pl @@ -13,7 +13,8 @@ use Dancer::Test; use Dancer::Config qw/setting/; use File::Spec::Functions; -my $content = LoadFile(catfile(qw/t data hook_data.yml/)); +my $content = LoadFile(shift || catfile(qw/t data hook_data.yml/)); + my $db_file = catfile( qw/t data jitterbug.db/ ); my $dsn = 'dbi:SQLite:dbname=' . $db_file; my $schema = jitterbug::Schema->connect($dsn); -- cgit 1.4.1