2020use TxTextControl \ReportingCloud \PropertyMap \AccountSettings as AccountSettingsPropertyMap ;
2121use TxTextControl \ReportingCloud \PropertyMap \TemplateInfo as TemplateInfoPropertyMap ;
2222use TxTextControl \ReportingCloud \PropertyMap \TemplateList as TemplateListPropertyMap ;
23+ use TxTextControl \ReportingCloud \PropertyMap \IncorrectWord as IncorrectWordMap ;
2324use TxTextControl \ReportingCloud \Validator \StaticValidator ;
2425
2526/**
@@ -36,27 +37,32 @@ class ReportingCloud extends AbstractReportingCloud
3637 */
3738
3839 /**
39- * Return an array of merge blocks and merge fields in a template file in template storage .
40+ * Check a corpus of text for spelling errors .
4041 *
41- * @param string $templateName Template name
42+ * Return an array of misspelled words, if spelling errors are found in the corpus of text.
4243 *
43- * @throws InvalidArgumentException
44+ * Return null, if no misspelled words are found in the corpus of text.
45+ *
46+ * @param string $text Corpus of text that should be spell checked
47+ * @param string $language Language of specified text
4448 *
4549 * @return array|null
4650 */
47- public function getTemplateInfo ( $ templateName )
51+ public function proofingCheck ( $ text , $ language )
4852 {
4953 $ ret = null ;
5054
51- $ propertyMap = new TemplateInfoPropertyMap ();
55+ StaticValidator::execute ($ text , 'TypeString ' );
56+ StaticValidator::execute ($ language , 'Language ' );
5257
53- StaticValidator:: execute ( $ templateName , ' TemplateName ' );
58+ $ propertyMap = new IncorrectWordMap ( );
5459
5560 $ query = [
56- 'templateName ' => $ templateName ,
61+ 'text ' => $ text ,
62+ 'language ' => $ language ,
5763 ];
5864
59- $ records = $ this ->get ('/templates/info ' , $ query );
65+ $ records = $ this ->get ('/proofing/check ' , $ query );
6066
6167 if (is_array ($ records ) && count ($ records ) > 0 ) {
6268 $ ret = $ this ->buildPropertyMapArray ($ records , $ propertyMap );
@@ -66,25 +72,80 @@ public function getTemplateInfo($templateName)
6672 }
6773
6874 /**
69- * Execute a GET request via REST client
75+ * Return an array of available dictionaries on the Reporting Cloud service
7076 *
71- * @param string $uri URI
72- * @param array $query Query
77+ * @return array|null
78+ */
79+ public function getAvailableDictionaries ()
80+ {
81+ $ ret = null ;
82+
83+ $ dictionaries = $ this ->get ('/proofing/availabledictionaries ' );
84+
85+ if (is_array ($ dictionaries ) && count ($ dictionaries ) > 0 ) {
86+ $ ret = array_map ('trim ' , $ dictionaries );
87+ }
88+
89+ return $ ret ;
90+ }
91+
92+ /**
93+ * Return an array of suggestions for a misspelled word.
7394 *
74- * @return mixed|null
95+ * @param string $word Word that should be spell checked
96+ * @param string $language Language of specified text
97+ * @param int $max Maximum number of suggestions to return
98+ *
99+ * @return array|null
75100 */
76- protected function get ( $ uri , $ query = [] )
101+ public function getProofingSuggestions ( $ word , $ language , $ max = 10 )
77102 {
78103 $ ret = null ;
79104
80- $ options = [
81- RequestOptions::QUERY => $ query ,
105+ StaticValidator::execute ($ word , 'TypeString ' );
106+ StaticValidator::execute ($ language , 'Language ' );
107+ StaticValidator::execute ($ max , 'TypeInteger ' );
108+
109+ $ query = [
110+ 'word ' => $ word ,
111+ 'language ' => $ language ,
112+ 'max ' => $ max ,
82113 ];
83114
84- $ response = $ this ->request ( ' GET ' , $ this -> uri ( $ uri ), $ options );
115+ $ records = $ this ->get ( ' /proofing/suggestions ' , $ query );
85116
86- if ($ response instanceof Response && 200 === $ response ->getStatusCode ()) {
87- $ ret = json_decode ($ response ->getBody (), true );
117+ if (is_array ($ records ) && count ($ records ) > 0 ) {
118+ $ ret = array_map ('trim ' , $ records );
119+ }
120+
121+ return $ ret ;
122+ }
123+
124+ /**
125+ * Return an array of merge blocks and merge fields in a template file in template storage.
126+ *
127+ * @param string $templateName Template name
128+ *
129+ * @throws InvalidArgumentException
130+ *
131+ * @return array|null
132+ */
133+ public function getTemplateInfo ($ templateName )
134+ {
135+ $ ret = null ;
136+
137+ $ propertyMap = new TemplateInfoPropertyMap ();
138+
139+ StaticValidator::execute ($ templateName , 'TemplateName ' );
140+
141+ $ query = [
142+ 'templateName ' => $ templateName ,
143+ ];
144+
145+ $ records = $ this ->get ('/templates/info ' , $ query );
146+
147+ if (is_array ($ records ) && count ($ records ) > 0 ) {
148+ $ ret = $ this ->buildPropertyMapArray ($ records , $ propertyMap );
88149 }
89150
90151 return $ ret ;
@@ -277,6 +338,31 @@ public function downloadTemplate($templateName)
277338 return $ ret ;
278339 }
279340
341+ /**
342+ * Execute a GET request via REST client
343+ *
344+ * @param string $uri URI
345+ * @param array $query Query
346+ *
347+ * @return mixed|null
348+ */
349+ protected function get ($ uri , $ query = [])
350+ {
351+ $ ret = null ;
352+
353+ $ options = [
354+ RequestOptions::QUERY => $ query ,
355+ ];
356+
357+ $ response = $ this ->request ('GET ' , $ this ->uri ($ uri ), $ options );
358+
359+ if ($ response instanceof Response && 200 === $ response ->getStatusCode ()) {
360+ $ ret = json_decode ($ response ->getBody (), true );
361+ }
362+
363+ return $ ret ;
364+ }
365+
280366
281367 /**
282368 * POST methods
0 commit comments