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

Method readData

lib/Datasource/ExternalJson.php:74–117  ·  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

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