Skip to content

Commit a83f084

Browse files
committed
Applies post-processing to returned API response data.
1 parent c5fad4f commit a83f084

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/SDK.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ public function __construct(array $data = array())
5050
*/
5151
public function summarizeText(string $text): stdClass
5252
{
53-
return $this->requester->post($this->buildUrl(), array(
53+
$summary = $this->requester->post($this->buildUrl(), array(
5454
'sm_api_input' => $text,
5555
));
56+
57+
return $this->cleanSummary($summary);
5658
}
5759

5860
/**
@@ -64,7 +66,9 @@ public function summarizeText(string $text): stdClass
6466
*/
6567
public function summarizeUrl(string $url): stdClass
6668
{
67-
return $this->requester->get($this->buildUrl(array('SM_URL' => $url)));
69+
$summary = $this->requester->get($this->buildUrl(array('SM_URL' => $url)));
70+
71+
return $this->cleanSummary($summary);
6872
}
6973

7074
/**
@@ -102,4 +106,19 @@ protected function buildUrl(array $data = array()): string
102106

103107
return $url;
104108
}
109+
110+
/**
111+
* Cleans summary response values.
112+
*
113+
* @param stdClass $summary The summary response to clean.
114+
*
115+
* @return stdClass
116+
*/
117+
protected function cleanSummary(stdClass $summary)
118+
{
119+
$summary->sm_api_title = trim($summary->sm_api_title);
120+
$summary->sm_api_content = trim($summary->sm_api_content);
121+
122+
return $summary;
123+
}
105124
}

0 commit comments

Comments
 (0)