| 1 | package WWW::SFDC::Partner; | ||
| 2 | # ABSTRACT: Interface to the Salesforce.com Partner API | ||
| 3 | |||
| 4 | use 5.12.0; | ||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | use Data::Dumper; | ||
| 9 | use Log::Log4perl ':easy'; | ||
| 10 | use Scalar::Util 'blessed'; | ||
| 11 | use SOAP::Lite; | ||
| 12 | use WWW::SFDC::SessionManager; | ||
| 13 | |||
| 14 | use Moo; | ||
| 15 | with "MooX::Singleton", "WWW::SFDC::Role::Session", "WWW::SFDC::Role::CRUD"; | ||
| 16 | |||
| 17 | |||
| 18 | has 'uri', | ||
| 19 | is => 'ro', | ||
| 20 | default => "urn:partner.soap.sforce.com"; | ||
| 21 | |||
| 22 | sub _extractURL { return $_[1]->{serverUrl} } | ||
| 23 | |||
| 24 | sub _prepareSObjects { | ||
| 25 | my $self = shift; | ||
| 26 | # prepares an array of objects for an update or insert call by converting | ||
| 27 | # it to an array of SOAP::Data | ||
| 28 | |||
| 29 | TRACE "objects for operation", Dumper \@_; | ||
| 30 | |||
| 31 | return map { | ||
| 32 | my $obj = $_; | ||
| 33 | my @type; | ||
| 34 | if ($obj->{type}) { | ||
| 35 | @type = SOAP::Data->name('type' => $obj->{type}); | ||
| 36 | delete $obj->{type}; | ||
| 37 | } | ||
| 38 | |||
| 39 | SOAP::Data->name(sObjects => \SOAP::Data->value( | ||
| 40 | @type, | ||
| 41 | map { | ||
| 42 | (blessed ($obj->{$_}) and blessed ($obj->{$_}) eq 'SOAP::Data') | ||
| 43 | ? $obj->{$_} | ||
| 44 | : SOAP::Data->name($_ => $obj->{$_}) | ||
| 45 | } keys %$obj | ||
| 46 | )) | ||
| 47 | } @_; | ||
| 48 | } | ||
| 49 | |||
| 50 | |||
| 51 | sub setPassword { | ||
| 52 | my ($self, %params) = @_; | ||
| 53 | LOGDIE "You must provide an Id and Password" unless $params{Id} and $params{Password}; | ||
| 54 | INFO "Setting password for user $params{Id}"; | ||
| 55 | return $self->_call( | ||
| 56 | 'setPassword', | ||
| 57 | SOAP::Data->name(userID => $params{Id}), | ||
| 58 | SOAP::Data->name(password => $params{Password}), | ||
| 59 | ); | ||
| 60 | } | ||
| 61 | |||
| 62 | 1; | ||
| 63 | |||
| 64 | __END__ | ||
| 65 | |||
| 66 | =pod | ||
| 67 | |||
| 68 | =head1 NAME | ||
| 69 | |||
| 70 | WWW::SFDC::Partner - Interface to the Salesforce.com Partner API | ||
| 71 | |||
| 72 | =head1 VERSION | ||
| 73 | |||
| 74 | version 0.22 | ||
| 75 | |||
| 76 | =head1 SYNOPSIS | ||
| 77 | |||
| 78 | my @objects = WWW::SFDC::Partner->instance(creds => { | ||
| 79 | username => "foo", | ||
| 80 | password => "bar", | ||
| 81 | url => "url", | ||
| 82 | })->query("SELECT field, ID FROM Object__c WHERE conditions"); | ||
| 83 | |||
| 84 | WWW::SFDC::Partner->instance()->update( | ||
| 85 | map { $_->{field} =~ s/baz/bat/ } @objects | ||
| 86 | ); | ||
| 87 | |||
| 88 | =head1 METHODS | ||
| 89 | |||
| 90 | =head2 setPassword | ||
| 91 | |||
| 92 | WWW::SFDC::Partner->instance()->setPassword(Id=>$ID, Password=$newPassword); | ||
| 93 | |||
| 94 | =head1 BUGS | ||
| 95 | |||
| 96 | Please report any bugs or feature requests at L<https://github.com/alexander-brett/WWW-SFDC/issues>. | ||
| 97 | |||
| 98 | =head1 SUPPORT | ||
| 99 | |||
| 100 | You can find documentation for this module with the perldoc command. | ||
| 101 | |||
| 102 | perldoc WWW::SFDC::Partner | ||
| 103 | |||
| 104 | You can also look for information at L<https://github.com/alexander-brett/WWW-SFDC> | ||
| 105 | |||
| 106 | =head1 AUTHOR | ||
| 107 | |||
| 108 | Alexander Brett <alexander.brett@sophos.com> | ||
| 109 | |||
| 110 | =head1 COPYRIGHT AND LICENSE | ||
| 111 | |||
| 112 | This software is Copyright (c) 2015 by Sophos Limited. | ||
| 113 | |||
| 114 | This is free software, licensed under: | ||
| 115 | |||
| 116 | The MIT (X11) License | ||
| 117 | |||
| 118 | The full text of the license can be found in the | ||
| 119 | F<LICENSE> file included with this distribution. | ||
| 120 | |||
| 121 | =cut |