ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Service.php
Go to the documentation of this file.
1<?php
2
4
7
18{
19
25 public $unsigned = false;
26
32 protected $endpoint;
38 private $consumer;
44 private $mediaType;
45
54 {
55
56 $this->consumer = $consumer;
57 $this->endpoint = $endpoint;
58 $this->mediaType = $mediaType;
59
60 }
61
71 public function send($method, $parameters = array(), $body = null)
72 {
73
75 if (!empty($parameters)) {
76 if (strpos($url, '?') === false) {
77 $sep = '?';
78 } else {
79 $sep = '&';
80 }
81 foreach ($parameters as $name => $value) {
82 $url .= $sep . urlencode($name) . '=' . urlencode($value);
83 $sep = '&';
84 }
85 }
86 if (!$this->unsigned) {
87 $header = ToolProvider\ToolConsumer::addSignature($url, $this->consumer->getKey(), $this->consumer->secret, $body, $method, $this->mediaType);
88 } else {
89 $header = null;
90 }
91
92// Connect to tool consumer
93 $http = new HTTPMessage($url, $method, $body, $header);
94// Parse JSON response
95 if ($http->send() && !empty($http->response)) {
96 $http->responseJson = json_decode($http->response);
97 $http->ok = !is_null($http->responseJson);
98 }
99
100 return $http;
101
102 }
103
104}
An exception for terminatinating execution or to throw for unit testing.
Class to represent an HTTP message.
Definition: HTTPMessage.php:15
Class to implement a service.
Definition: Service.php:18
send($method, $parameters=array(), $body=null)
Send a service request.
Definition: Service.php:71
$unsigned
Whether service request should be sent unsigned.
Definition: Service.php:25
__construct($consumer, $endpoint, $mediaType)
Class constructor.
Definition: Service.php:53
$consumer
Tool Consumer for this service request.
Definition: Service.php:38
$mediaType
Media type of message body.
Definition: Service.php:44
static addSignature($endpoint, $consumerKey, $consumerSecret, $data, $method='POST', $type=null)
Add the OAuth signature to an array of message parameters or to a header string.
if($format !==null) $name
Definition: metadata.php:146
$url
$http
Definition: raiseError.php:7