File: Toppreise.pm

package info (click to toggle)
jabber-querybot 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 212 kB
  • sloc: perl: 1,136; makefile: 2
file content (108 lines) | stat: -rwxr-xr-x 2,793 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/perl -w
#
# This file is part of querybot (-a modular perl jabber bot)
# http://github.com/micressor/jabber-querybot
#
# Copyright (C) 2009-2012 Marco Balmer <marco@balmer.name>
#
# Querybot is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Querybot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Querybot. If not, see <http://www.gnu.org/licenses/>.

package Querymodule;

use strict;

=head1 NAME

jabber-querybot - toppreise.ch

=head1 DESCRIPTION

This example works *and* need access rights from toppreise.ch administrators.
Access to this API is restricted.

=head1 RESOURCES

http://www.toppreise.ch

http://www.toppreise.ch/im/imQuery.php/

=cut

use LWP::Simple;
use LWP::UserAgent;
use URI::URL;

use vars qw(@EXPORT @ISA);
use Exporter;

@ISA               = qw(Exporter);
@EXPORT            = qw(run_query $ident $service_name $bot_admin $hostname
  $port $timeout $user $password);

our $stanza_penalty_calc_default = 60;


our $hostname		= "jabberserver.tld";
our $user		= "";
our $password		= "";
our $ident		= "Toppreise";
our $bot_admin		= "\@swissjabber.ch";
our $port		= "5222";
our $timeout		= "5";
our $service_name	= "$user\@$hostname";
our $bot_description		 = "Toppreise.ch - Preisvergleich
Realtime Preisvergleich. Dieser Bot ist direkt mit der Toppreise.ch Datenbank verbunden.

Search examples:
Canon Digitalkamera

This service is also available via
the following instant messaging systems:
";

sub run_query  #################################################################
{
my $msg	 	= shift;
my $jid               = shift;
my $bare_jid          = shift;
my $digest_jid        = shift;

unless ($msg =~ /^[\-A-Za-z0-9äöüÄÖÜ\.\?\s]*$/) {
  return ("error",401,"Some characters are not allowed, please try again.");
}

my $url = url("http://www.toppreise.ch/im/imQuery.php/");
$url->query_form(client => $digest_jid,  search=>$msg);
my $ua = LWP::UserAgent->new;
$ua->timeout(5);
$ua->agent($ident);
my $request = HTTP::Request->new('GET', $url);
my $response = $ua->request($request);
my $url_response = $response->content;

# Return result message an the time for processing
return (0,0,$url_response);

}

1;

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2009-2012 Marco Balmer <marco@balmer.name>

The Debian packaging is licensed under the 
GPL, see `/usr/share/common-licenses/GPL-3'.

=cut