ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilECSCourseUrlConnector.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php';
5 include_once './Services/WebServices/ECS/classes/class.ilECSConnectorException.php';
6 
14 {
19  public function __construct(ilECSSetting $settings = null)
20  {
22  }
23 
29  public function addUrl(ilECSCourseUrl $url, $a_target_mid)
30  {
31  global $ilLog;
32 
33  $ilLog->write(__METHOD__.': Add new course url ...');
34 
35  $this->path_postfix = '/campusconnect/course_urls';
36 
37  try
38  {
39  $this->prepareConnection();
40 
41  $this->addHeader('Content-Type', 'application/json');
42  $this->addHeader('Accept', 'application/json');
43  $this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, $a_target_mid);
44 
45  $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
46  $this->curl->setOpt(CURLOPT_POST,true);
47  $this->curl->setOpt(CURLOPT_POSTFIELDS,json_encode($url));
48 
49  $GLOBALS['ilLog']->write(__METHOD__.': Sending url '. print_r(json_encode($url),true));
50 
51  $ret = $this->call();
52 
53  $info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
54 
55  $ilLog->write(__METHOD__.': Checking HTTP status...');
56  if($info != self::HTTP_CODE_CREATED)
57  {
58  $ilLog->write(__METHOD__.': Cannot create course url ressource, did not receive HTTP 201. ');
59  $ilLog->write(__METHOD__.': POST was: '. json_encode($url));
60  $ilLog->write(__METHOD__.': HTTP code: '.$info);
61  throw new ilECSConnectorException('Received HTTP status code: '.$info);
62  }
63  $ilLog->write(__METHOD__.': ... got HTTP 201 (created)');
64  }
65  catch(ilCurlConnectionException $exc)
66  {
67  throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
68  }
69  }
70 }
71 ?>