preparation for updating via Twingle API
This commit is contained in:
parent
338539e9be
commit
50b0ff7da8
2 changed files with 38 additions and 3 deletions
|
@ -119,15 +119,24 @@ class TwingleApiCall {
|
||||||
) {
|
) {
|
||||||
$result = $project->update();
|
$result = $project->update();
|
||||||
}
|
}
|
||||||
|
elseif (
|
||||||
|
$result['state'] == 'exists' &&
|
||||||
|
$values['last_update'] < $project->getTimestamp()
|
||||||
|
) {
|
||||||
|
$result = $this->updateProject($project->export());
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
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() {
|
public function updateEvent() {
|
||||||
|
@ -168,4 +177,21 @@ class TwingleApiCall {
|
||||||
return $response;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -130,6 +130,15 @@ class TwingleProject {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export values
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function export() {
|
||||||
|
return $this->values;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a project already exists
|
* Check if a project already exists
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue