summaryrefslogtreecommitdiff
path: root/scripts/trigger_hook
diff options
context:
space:
mode:
authorJonathan "Duke" Leto <jonathan@leto.net>2011-05-22 18:12:40 -0700
committerJonathan "Duke" Leto <jonathan@leto.net>2011-05-22 18:12:40 -0700
commit0962bea6887d6d1ec5e74ddbc3a53467cf44c150 (patch)
tree421a4e6fb7297f2156e75288d04fea38d42a9ad3 /scripts/trigger_hook
parentError out early if a task id is not given (diff)
downloadjitterbug-0962bea6887d6d1ec5e74ddbc3a53467cf44c150.tar.gz
add a script to trigger our hook
Diffstat (limited to '')
-rw-r--r--scripts/trigger_hook57
1 files changed, 57 insertions, 0 deletions
diff --git a/scripts/trigger_hook b/scripts/trigger_hook
new file mode 100644
index 0000000..7c031af
--- /dev/null
+++ b/scripts/trigger_hook
@@ -0,0 +1,57 @@
+use strict;
+use warnings;
+
+use jitterbug;
+use jitterbug::Schema;
+
+use JSON;
+use YAML qw/LoadFile Dump/;
+
+use File::Spec;
+use File::Temp qw/tempdir/;
+
+use Dancer::Test;
+use Dancer::Config qw/setting/;
+
+my $content = LoadFile('t/data/test.yaml');
+
+my $db_file = File::Spec->catfile( qw/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;
+}
+