Hi Stephen,

You now have edit rights in the wiki, so if you don't mind added that example, that would be great!

If anyone else needs edit rights in the wiki, feel free to ping me and I'll make it so.

Thanks!
Michelle

On 2/11/2012 9:35 AM, Stephen Marquard wrote:
It took me some googling to find out quite how to do this, so in case
anyone else needs to do this in future, here is a sample script using
perl to access Matterhorn's REST webservices with digest
authentication.

I don't have comment or edit access to the MH Wiki, but perhaps someone
could add a perl example to
http://opencast.jira.com/wiki/display/MH/Remote+Services or in
another suitable place.

Regards
Stephen

----

#! /usr/bin/perl

use WWW::Mechanize;
use JSON; # imports encode_json, decode_json, to_json and from_json.

my $url = "http://some.domain/workflow/statistics.json";;

my $digest_user = "matterhorn_system_account";
my $digest_password="PASSWORD";

my $mech = WWW::Mechanize->new( autocheck =>  1 );

$mech->credentials($digest_user, $digest_password);
$mech->add_header( 'X-REQUESTED-AUTH' =>  'Digest' );
$mech->get($url);

my $response = $mech->response();

# Headers

for my $key ( $response->header_field_names() ) {
         print $key, " : ", $response->header( $key ), "\n";
}

print "\n";

# Body

if ($response->is_success) {
      print $response->decoded_content;  # or whatever
} else {
      die $response->status_line;
}

print "\n\n";

my $json = new JSON;
my $statistics =
$json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->decode($response->decoded_content);

print "Running: " . $statistics->{statistics}->{running} . "\n";
print "Failed: " . $statistics->{statistics}->{failed} . "\n";




--

Michelle Ziegmann
Educational Technology Services
University of California Berkeley

_______________________________________________
Matterhorn mailing list
[email protected]
http://lists.opencastproject.org/mailman/listinfo/matterhorn


To unsubscribe please email
[email protected]
_______________________________________________

Reply via email to