Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Profile.php #30

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}