File: sf-info.pl

package info (click to toggle)
libxml-compile-soap-perl 3.28%2Bds-1
  • links: PTS, VCS
  • area: non-free
  • in suites: bookworm, forky, sid, trixie
  • size: 616 kB
  • sloc: perl: 4,407; makefile: 7
file content (84 lines) | stat: -rw-r--r-- 2,539 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env perl
#
# Demonstration of a Salesforce coupling, as test script.  You see the
# initial steps to shape a clean module.
# Contributed by Ciaran Deignan, 18 dec 2013 (slightly modified by MarkOv)
#
# References:
# http://blog.deadlypenguin.com/blog/2012/02/03/salesforce-and-soapui/
# http://wiki.developerforce.com/page/Sample_SOAP_Messages

use warnings;
use strict;
use Data::Dumper;

# preparation
use XML::Compile;
use XML::Compile::WSDL11;      # use WSDL version 1.1
use XML::Compile::SOAP11;      # use SOAP version 1.1
use XML::Compile::Transport::SOAPHTTP;

#my $wsdlfn = 'enterprise-2013-12-16.xml';
my $wsdlfn = 'sandbox-2013-12-18.xml';

## Take login and password from command-line
@ARGV==2 or die "Usage: $0 <username> <password>\n";
my ($U, $P) = @ARGV;

warn "Using XML-Compile version\t%s\n", $XML::Compile::VERSION;
warn "Using XML-Compile-SOAP version\t%s\n", $XML::Compile::SOAP::VERSION;

my $ws   = XML::Compile::WSDL11->new;

## Get WSDL from file...
$ws->addWSDL($wsdlfn);

## Login provides info for the other methods, so needs to be compiled
## separately.
my $ini =  $ws->compileClient('login');

## We need to login first
my ($ret, $trace) = $ini->(username => $U, password=> $P);

#$trace->printErrors(*STDERR); exit;
#print Dumper($ret); exit;

## You may get an error back from the server
if(my $f = $ret->{Fault})
{   my $errname = $f->{_NAME};
    my $error   = $ret->{$errname};
    printf "Error %s (%s)\n", $errname, $f->{faultstring};
#  print Dumper($ret);
    exit;
}


my $login = $ret->{parameters}{result};
my $sh = { sessionId => $login->{sessionId} };

## Information/debugging utilities
#$ws->printIndex; exit;
#print $ws->explain('login', PERL => 'INPUT', recurse => 1); #exit;
#print $ws->explain('logout', PERL => 'INPUT', recurse => 1); exit;
#print $ws->explain('describeSObject', PERL => 'INPUT', recurse => 1); exit;

## Compile all other calls
$ws->compileCalls(endpoint => $login->{serverUrl});

## Best to wrap each of the calls in a convenient function/method, to
## provide an abstract interface to the main program.
my ($ret2, $trace2) = $ws->call(
     'getServerTimestamp'
#    'describeGlobal'
#    'describeSObject', parameters => {sObjectType => 'Account'}
#    'describeSObject', parameters => {sObjectType => 'Machine__c'}
   , SessionHeader => $sh
   );
print Dumper $ret2; 

my ($ret3, $trace3) = $ws->call('logout', SessionHeader => $sh);

#print Dumper($ret3); 
exit 0;