Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
intranet-rest
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
project-open
intranet-rest
Commits
f999bb99
Commit
f999bb99
authored
May 26, 2010
by
Frank Bergmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added debugging for retrieving XML results
parent
34a072f5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
2 deletions
+83
-2
list-projects.perl
perl-client-examples/list-projects.perl
+83
-2
No files found.
perl-client-examples/list-projects.perl
View file @
f999bb99
...
...
@@ -9,25 +9,106 @@
# --------------------------------------------------------
# Libraries
use
XML::
Parser
;
use
LWP::
UserAgent
;
# --------------------------------------------------------
# Connection parameters:
# Debug: 0=silent, 9=verbose
$debug
=
1
;
$rest_server
=
"http://demo.project-open.net"
;
# May include port number
$rest_email
=
"bbigboss\@tigerpond.com"
;
$rest_password
=
"ben"
;
#$rest_server = "http://192.168.0.2:30086"; # May include port number
# --------------------------------------------------------
# Request the XML result
print
"list-projects.perl: Sending HTTP request to $rest_server/intranet-rest/im_project\n"
if
(
$debug
>
0
);
print
"list-projects.perl: Using email=$rest_email and password=$rest_password\n"
if
(
$debug
>
0
);
$ua
=
LWP::
UserAgent
->
new
;
$req
=
HTTP::
Request
->
new
(
GET
=>
"$rest_server/intranet-rest/i
ndex
"
);
$req
=
HTTP::
Request
->
new
(
GET
=>
"$rest_server/intranet-rest/i
m_project
"
);
$req
->
authorization_basic
(
$rest_email
,
$rest_password
);
$response
=
$ua
->
request
(
$req
);
# Extract return_code (200, ...), headers and body from the response
print
$response
->
as_string
if
(
$debug
>
8
);
$code
=
$response
->
code
if
(
$debug
>
0
);
print
"list-projects.perl: HTTP return_code=$code\n"
if
(
$debug
>
0
);
$headers
=
$response
->
headers_as_string
;
print
"list-projects.perl: HTTP headers=$headers\n"
if
(
$debug
>
7
);
$body
=
$response
->
content
;
print
"list-projects.perl: HTTP body=$body\n"
if
(
$debug
>
8
);
# -------------------------------------------------------
# Creates a XML parser object with a number of event handlers
my
$parser
=
new
XML::
Parser
(
Handlers
=>
{
Start
=>
\&
hdl_start
,
End
=>
\&
hdl_end
,
Char
=>
\&
hdl_char
,
Default
=>
\&
hdl_def
,
});
my
$message
;
# Hashref containing infos on a message
$parser
->
parse
(
$body
);
# Parse the message
# -------------------------------------------------------
# Define Event Handlers for event based XML parsing
# Handle the start of a tag.
# Store the tag's attributes into "message".
# Create a reserved field "_str" which will contain the strings of the tag.
sub
hdl_start
{
my
(
$p
,
$elt
,
%
atts
)
=
@_
;
return
unless
$elt
eq
'object_id'
;
# We're only interrested in what's said
$atts
{
'_str'
}
=
''
;
$message
=
\%
atts
;
}
# Handle the end of a tag.
# Just print out the tag
sub
hdl_end
{
my
(
$p
,
$elt
)
=
@_
;
format_message
(
$message
)
if
$elt
eq
'object_id'
&&
$message
&&
$message
->
{
'_str'
}
=~
/\S/
;
}
# Handle characters: Append them to the "_str" field
sub
hdl_char
{
my
(
$p
,
$str
)
=
@_
;
$message
->
{
'_str'
}
.=
$str
;
}
# Default handler: Just ignore everything else
sub
hdl_def
{
}
# -------------------------------------------------------
# Helper sub to nicely format what we got from the XML
sub
format_message
{
my
$atts
=
shift
;
$atts
->
{
'_str'
}
=~
s/\n//g
;
$str
=
$atts
->
{
'_str'
};
print
"list-projects.perl: project_id=$str\n"
;
# while ( my ($key, $value) = each(%$atts) ) { print "$key => $value\n"; }
undef
$message
;
}
print
$ua
->
request
(
$req
)
->
as_string
;
exit
0
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment