Skip to content

Commit

Permalink
Update Profile.php
Browse files Browse the repository at this point in the history
Add a save() method to allow profile data to be sent back to ORCID. The XML provided will be in orcid-message format.
Both environment and APi should have already been selected before calling this method , to allow upload to the correct endpoint.
  • Loading branch information
illuminatusds authored Jul 20, 2016
1 parent 15fb2dd commit 4cfecd4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Orcid;

use Orcid\Http\Curl;

/**
* ORCID profile API class
**/
Expand Down Expand Up @@ -108,4 +110,39 @@ public function fullName()

return $details->{'given-names'}->value . ' ' . $details->{'family-name'}->value;
}

/**
* Saves the orcid-message xml provided to the correct scope
* @return mixed - either false on failure or result content
* If successful, this content will be orcid-message XML
**/
public function save($scope, $xml)
{
$endpoint = $this->oauth->getApiEndpoint($scope, $this->id());
$headers = [
'Content-Type' => 'application/vnd.orcid+xml',
'Authorization' => 'Bearer ' . $this->id()->getAccessToken()
];

$orcid_msg = stripslashes($xml);

/* We need to set up a tmp file in order
* to do the HTTP PUT request properly
*/
$tmp_file = tmpfile();
fwrite($tmp_file,$orcid_msg);
fseek($tmp_file,0);

$c = new Curl;
$c->setUrl($endpoint);
$c->setOpt(CURLOPT_PUT, true);
$c->setOpt(CURLOPT_BINARYTRANSFER, true);
$c->setOpt(CURLOPT_RETURNTRANSFER, true);
$c->setOpt(CURLOPT_INFILE, $tmp_file);
$c->setOpt(CURLOPT_INFILESIZE, strlen($orcid_msg));
$c->setOpt(CURLOPT_VERBOSE, true);
$c->setHeader($headers);
$result = $c->execute();
return $result;
}
}

0 comments on commit 4cfecd4

Please sign in to comment.