preparation for updating via Twingle API

This commit is contained in:
Marc Michalsky forumZFD 2020-09-29 21:47:03 +02:00
parent 338539e9be
commit 50b0ff7da8
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
2 changed files with 38 additions and 3 deletions

View file

@ -119,15 +119,24 @@ class TwingleApiCall {
) {
$result = $project->update();
}
elseif (
$result['state'] == 'exists' &&
$values['last_update'] < $project->getTimestamp()
) {
$result = $this->updateProject($project->export());
}
return $result;
} else {
return null;
}
else {
return NULL;
}
}
public function updateProject() {
public function updateProject(array $values) {
$url = $this->protocol . 'project' . $this->baseUrl . $values['id'];
return $this->curlPost($url, $values);
}
public function updateEvent() {
@ -168,4 +177,21 @@ class TwingleApiCall {
return $response;
}
private function curlPost($url, $data) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
"x-access-code: $this->apiKey",
'Content-Type: application/json',
]);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
$response = json_decode(curl_exec($curl), TRUE);
if (empty($response)) {
$response = curl_error($curl);
}
curl_close($curl);
return $response;
}
}

View file

@ -130,6 +130,15 @@ class TwingleProject {
];
}
/**
* Export values
*
* @return array
*/
public function export() {
return $this->values;
}
/**
* Check if a project already exists
*