Skip to content

Commit 3130e3c

Browse files
committed
Add possibilty to return API response as JSON object
1 parent 3a77a11 commit 3130e3c

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

sslLabsApi.php

+43-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ class sslLabsApi
1414
{
1515
CONST API_URL = "https://api.ssllabs.com/api/v2";
1616

17+
private $returnJsonObjects;
18+
19+
/**
20+
* sslLabsApi::__construct()
21+
*/
22+
public function __construct($returnJsonObjects = false)
23+
{
24+
$this->returnJsonObjects = (boolean) $returnJsonObjects;
25+
}
26+
1727
/**
1828
* sslLabsApi::fetchApiInfo()
1929
*
@@ -135,7 +145,39 @@ public function sendApiRequest($apiCall, $parameters = array())
135145
)
136146
);
137147

138-
return (file_get_contents(self::API_URL . '/' . $apiCall . $this->buildGetParameterString($parameters), false, $context));
148+
$apiResponse = file_get_contents(self::API_URL . '/' . $apiCall . $this->buildGetParameterString($parameters), false, $context);
149+
150+
if($this->returnJsonObjects)
151+
{
152+
return (json_decode($apiResponse));
153+
}
154+
155+
return ($apiResponse);
156+
}
157+
158+
/**
159+
* sslLabsApi::setReturnJsonObjects()
160+
*
161+
* Setter for returnJsonObjects
162+
* Set true to return all API responses as JSON object, false returns it as simple JSON strings (default)
163+
*
164+
* @param boolean $returnJsonObjects
165+
*/
166+
public function setReturnJsonObjects($returnJsonObjects)
167+
{
168+
$this->returnJsonObjects = (boolean) $returnJsonObjects;
169+
}
170+
171+
/**
172+
* sslLabsApi::getReturnJsonObjects()
173+
*
174+
* Getter for returnJsonObjects
175+
*
176+
* @return boolean true returns all API responses as JSON object, false returns it as simple JSON string
177+
*/
178+
public function getReturnJsonObjects()
179+
{
180+
return ($this->returnJsonObjects);
139181
}
140182

141183
/**

0 commit comments

Comments
 (0)