MCPcopy Create free account
hub / github.com/Rello/analytics / readData

Method readData

lib/Datasource/ExternalJson.php:73–116  ·  view source on GitHub ↗

* Read the Data * @param $option * @return array available options of the data source */

($option)

Source from the content-addressed store, hash-verified

71 * @return array available options of the data source
72 */
73 public function readData($option): array
74 {
75 $cache = $this->getCacheMetadata($option);
76 if ($cache['notModified'] === true) {
77 return [
78 'header' => [],
79 'dimensions' => [],
80 'data' => [],
81 'rawdata' => null,
82 'error' => 0,
83 'cache' => $cache,
84 ];
85 }
86
87 $url = htmlspecialchars_decode($option['url'], ENT_NOQUOTES);
88 $auth = (string)($option['auth'] ?? '');
89 $method = ($option['method'] ?? 'GET') === 'POST' ? 'POST' : 'GET';
90 $contentType = !empty($option['content-type']) ? (string)$option['content-type'] : 'application/json';
91 $data = array();
92 $http_code = '';
93 $headers = $this->parseHeaders((string)($option['customHeaders'] ?? ''));
94 $headers['OCS-APIRequest'] = 'true';
95 $headers['Content-Type'] = $contentType;
96 $response = $this->httpClient->request(
97 $url,
98 $method,
99 $headers,
100 isset($option['body']) && $option['body'] !== '' ? (string)$option['body'] : null,
101 (string)$auth,
102 );
103 $rawResult = $response['body'];
104 $http_code = $response['status'];
105 if ($response['error'] !== null) {
106 return ['header' => [], 'dimensions' => [], 'data' => [], 'error' => $response['error'], 'cache' => $cache];
107 }
108
109 $return = $this->jsonParser($option, $rawResult);
110 $return['rawdata'] = $rawResult;
111 $return['URL'] = $url;
112 $return['error'] = ($http_code >= 200 && $http_code < 300) ? 0 : 'HTTP response code: ' . $http_code;
113 $return['cache'] = $cache;
114
115 return $return;
116 }
117
118 /** @return array<string, string> */
119 private function parseHeaders(string $customHeaders): array {

Callers

nothing calls this directly

Calls 4

getCacheMetadataMethod · 0.95
parseHeadersMethod · 0.95
jsonParserMethod · 0.95
requestMethod · 0.45

Tested by

no test coverage detected