Skip to content

Instantly share code, notes, and snippets.

@akishin
Last active August 29, 2015 14:24
Show Gist options
  • Save akishin/9f3d022b7cbad5c1a06b to your computer and use it in GitHub Desktop.
Save akishin/9f3d022b7cbad5c1a06b to your computer and use it in GitHub Desktop.
Perl から Errbit にデータ登録するサンプル
use strict;
use warnings;
use utf8;
use Data::Dumper;
use Furl;
use XML::Simple;
my $notify_url = 'http://errbit.example.com/notifier_api/v2/notices';
my $api_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
my $notice = +{
notice => +{
version => '2.3',
'api-key' => [$api_key],
notifier => [
+{
name => ['Perl Example Notifier'],
version => ['0.01'],
url => ['http://example.com/api'],
},
],
error => [
+{
class => ['RuntimeError'],
message => ["RuntimeError: I've made a huge mistake"],
backtrace => [
+{
line => [
+{
number => '1',
file => 'foo.pl',
method => '<main>',
},
+{
number => '2',
file => 'bar.pl',
method => '<hoge>',
}
]
}
]
},
],
request => +{
url => ['http://example.com'],
component => [],
action => [],
params => [
+{
var => [
+{
key => 'foo',
content => 'bar',
},
],
}
],
'cgi-data' => [
+{
var => [
+{
key => 'baz',
content => 'qux',
},
],
}
],
},
'server-environment' => +{
'project-root' => ['/testapp'],
'environment-name' => ['production'],
'app-version' => ['0.0.1']
},
framework => ['Standalone'],
}
};
my $xml = XMLout($notice, RootName => undef, NoIndent => 1, XMLDecl => "<?xml version='1.0' encoding='utf-8'?>");
print $xml;
my $furl = Furl->new;
my $res = $furl->post(
$notify_url,
['Content-Type' => 'text/xml'],
$xml
);
print Dumper($res->content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment