Subversion Repositories DevTools

Rev

Rev 1295 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1293 dpurdie 1
###############################################################################
2
# Codestriker: Copyright (c) 2001, 2002 David Sitsky.  All rights reserved.
3
# sits@users.sourceforge.net
4
#
5
# This program is free software; you can redistribute it and modify it under
6
# the terms of the GPL.
7
 
8
# Code for interacting with a Codestriker server via HTTP.
9
#
10
# Example usage for creating a new Codestriker topic.
11
#
12
# my $client = CodestrikerClient->new('http://localhost.localdomain/codestriker/codestriker.pl');
13
# $client->create_topic({
14
#      topic_title => 'Automatic Topic from script',
15
#      topic_description => "Automatic Topic Description\nAnd more",
16
#      project_name => 'Project2',
17
#      repository => ':ext:sits@localhost:/home/sits/cvs',
18
#      bug_ids => '1',
19
#      email => 'sits',
20
#      reviewers => 'root',
21
#      topic_text => "Here is some text\nHere is some\n\nMore and more...\n"});
22
 
23
package CodestrikerClient;
24
 
25
use strict;
26
use LWP::UserAgent;
27
use HTTP::Request;
28
use HTTP::Request::Common;
29
use File::Temp qw/ tempfile /;
30
use IO::Handle;
31
 
32
# Create a new CodestrikerClient object, which records the base URL of the server.
33
sub new {
34
    my ($type, $url) = @_;
35
    my $self = {};
36
    $self->{url} = $url;
37
    return bless $self, $type;
38
}
39
 
40
# Create a new topic.
41
sub create_topic {
42
    my ($self, $params) = @_;
43
 
44
    # Create a temporary file containing the topic text.
45
    my ($tempfile_fh, $tempfile_filename) = tempfile();
46
    $tempfile_fh->print($params->{topic_text});
47
    $tempfile_fh->flush;
48
 
49
    # Perform the HTTP Post.
50
    my $ua = new LWP::UserAgent;
51
    my $content = [ action => 'submit_new_topic',
52
		    topic_title => $params->{topic_title},
53
		    topic_description => $params->{topic_description},
54
		    project_name => $params->{project_name},
55
		    repository => $params->{repository},
56
		    bug_ids => $params->{bug_ids},
57
		    email => $params->{email},
58
		    reviewers => $params->{reviewers},
59
		    cc => $params->{cc},
60
		    topic_file => [$tempfile_filename]];
61
    my $response =
62
	$ua->request(HTTP::Request::Common::POST($self->{url},
63
						 Content_Type => 'form-data',
64
						 Content => $content));
65
 
66
    # Remove the temporary file.
67
    unlink $tempfile_filename;
68
 
69
    # Indicate if the operation was successful.
70
    my $response_content = $response->content;
71
    my $rc = $response_content =~ /Topic URL: \<A HREF=\"(.*)\"/i;
72
    print STDERR "Failed to create topic, response: $response_content\n" if $rc == 0;
73
    return $rc ? $1 : undef;
74
}
75
 
76
1;