@@ -80,13 +80,56 @@ class ApiClient extends \Ease\Sand
8080 */
8181 private $ lastResponseCode ;
8282
83+ /**
84+ * @var array Unit status enumeration
85+ */
86+ public $ unitStatus = [
87+ 0 => 'free ' ,
88+ 1 => 'pre-reserved ' ,
89+ 2 => 'reserved ' ,
90+ 3 => 'sold ' ,
91+ 4 => 'not for sale ' ,
92+ 5 => 'delayed '
93+ ];
94+
95+ /**
96+ * @var array Unit type enumeration
97+ */
98+ public $ unitType = [
99+ 1 => 'flat ' ,
100+ 2 => 'parking ' ,
101+ 3 => 'cellar ' ,
102+ 4 => 'outdoor parking ' ,
103+ 5 => 'garage ' ,
104+ 6 => 'commercial space ' ,
105+ 7 => 'family house ' ,
106+ 8 => 'land ' ,
107+ 9 => 'atelier ' ,
108+ 10 => 'office ' ,
109+ 11 => 'art workshop ' ,
110+ 12 => 'non-residential unit ' ,
111+ 13 => 'motorbike parking ' ,
112+ 14 => 'creative workshop ' ,
113+ 15 => 'townhouse ' ,
114+ 16 => 'utility room ' ,
115+ 17 => 'condominium ' ,
116+ 18 => 'storage ' ,
117+ 19 => 'apartment ' ,
118+ 20 => 'accommodation unit ' ,
119+ 21 => 'bike stand ' ,
120+ 22 => 'communal area '
121+ ];
122+
83123 /**
84124 * RealPad Data obtainer
125+ *
126+ * @var string $username - leave empty to use Environment or constant REALPAD_USERNAME
127+ * @var string $password - leave empty to use Environment or constant REALPAD_PASSWORD
85128 */
86- public function __construct ()
129+ public function __construct ($ username = '' , $ password = '' )
87130 {
88- $ this ->apiUsername = \Ease \Shared::cfg ('REALPAD_USERNAME ' );
89- $ this ->apiPassword = \Ease \Shared::cfg ('REALPAD_PASSWORD ' );
131+ $ this ->apiUsername = strlen ( $ username ) ? $ username : \Ease \Shared::cfg ('REALPAD_USERNAME ' );
132+ $ this ->apiPassword = strlen ( $ password ) ? $ password : \Ease \Shared::cfg ('REALPAD_PASSWORD ' );
90133 $ this ->curlInit ();
91134 $ this ->setObjectName ();
92135 }
@@ -117,11 +160,6 @@ public function curlInit()
117160 CURLOPT_USERAGENT ,
118161 'RealpadTakeout v ' . \Ease \Shared::appVersion () . ' https://github.com/Spoje-NET/Realpad-Takeout '
119162 );
120- \curl_setopt (
121- $ this ->curl ,
122- CURLOPT_POSTFIELDS ,
123- 'login= ' . $ this ->apiUsername . '&password= ' . $ this ->apiPassword
124- );
125163 return $ this ->curl ;
126164 }
127165
@@ -133,8 +171,16 @@ public function curlInit()
133171 *
134172 * @return int HTTP Response CODE
135173 */
136- public function doCurlRequest ($ url , $ method = 'GET ' )
174+ public function doCurlRequest ($ url , $ method = 'GET ' , $ postParams = [] )
137175 {
176+ \curl_setopt (
177+ $ this ->curl ,
178+ CURLOPT_POSTFIELDS ,
179+ array_merge (
180+ ['login ' => $ this ->apiUsername , 'password ' => $ this ->apiPassword ],
181+ $ postParams
182+ )
183+ );
138184 curl_setopt ($ this ->curl , CURLOPT_URL , $ url );
139185
140186 curl_setopt ($ this ->curl , CURLOPT_CUSTOMREQUEST , strtoupper ($ method ));
@@ -256,9 +302,9 @@ public function __destruct()
256302 *
257303 * @return array
258304 */
259- public function getExcelData ($ endpoint )
305+ public function getExcelData ($ endpoint, $ params = [] )
260306 {
261- $ responseCode = $ this ->doCurlRequest ($ this ->baseEndpoint . 'ws/v10/ ' . $ endpoint , 'POST ' );
307+ $ responseCode = $ this ->doCurlRequest ($ this ->baseEndpoint . 'ws/v10/ ' . $ endpoint , 'POST ' , $ params );
262308 $ excelData = [];
263309 if ($ responseCode == 200 ) {
264310 $ xls = sys_get_temp_dir () . '/ ' . $ endpoint . '_ ' . \Ease \Functions::randomString () . '.xls ' ;
@@ -379,21 +425,36 @@ public function listInspections()
379425 * Accepts an additional optional parameter mode. By default all the Deal
380426 * Warranty Claim Defects are returned. Certain developers will also see the
381427 * Communal Areas Defects here by default. If mode is specified, other
382- * Defects can be returned. Available modes are:
383- * DEAL_DEFECTS, DEAL_DEFECTS_COMMUNAL_AREA, DEAL_DEFECTS_COMBINED,
384- * INSPECTION_DEFECTS, INSPECTION_DEFECTS_COMMUNAL_AREA,
385- * INSPECTION_DEFECTS_COMBINED.
428+ * Defects can be returned.
386429 *
387430 * The last column contains the unique defect ID from the Realpad database.
388431 * The second column is the relevant deal ID.
389432 *
390433 * @todo Implement Modes
391434 *
435+ * @var string mode none or one from: DEAL_DEFECTS,
436+ * DEAL_DEFECTS_COMMUNAL_AREA,
437+ * DEAL_DEFECTS_COMBINED,
438+ * INSPECTION_DEFECTS,
439+ * INSPECTION_DEFECTS_COMMUNAL_AREA,
440+ * INSPECTION_DEFECTS_COMBINED.
441+ *
392442 * @return array
393443 */
394- public function listDefects ()
444+ public function listDefects ($ mode = '' )
395445 {
396- return $ this ->getExcelData ('list-excel-defects ' );
446+ $ modesAvailble = [
447+ 'DEAL_DEFECTS ' ,
448+ 'DEAL_DEFECTS_COMMUNAL_AREA ' ,
449+ 'DEAL_DEFECTS_COMBINED ' ,
450+ 'INSPECTION_DEFECTS ' ,
451+ 'INSPECTION_DEFECTS_COMMUNAL_AREA ' ,
452+ 'INSPECTION_DEFECTS_COMBINED '
453+ ];
454+ if (strlen ($ mode ) && (array_search ($ mode , $ modesAvailble ) === false )) {
455+ throw new \SpojeNet \Realpad \Exception ('Iillegal inspection Mode ' . $ mode );
456+ }
457+ return $ this ->getExcelData ('list-excel-defects ' , ['mode ' => $ mode ]);
397458 }
398459
399460 /**
@@ -429,43 +490,53 @@ public function listSalesStatus()
429490 }
430491
431492 /**
432- * Accepts an additional required parameter unitid, which has to be a valid
433- * unit Realpad database ID obtained from some other endpoint.
434493 * The first column contains the timestamp of when the given unit started
435494 * containing the data on the given row. The second column contains the name
436495 * of the user who caused that data to be recorded.
437496 *
497+ * @var int $unitID Required parameter unitid, which has to be a valid unit
498+ * Realpad database ID obtained from some other endpoint.
499+ *
438500 * @return array
439501 */
440- public function listUnitHistory ()
502+ public function listUnitHistory (int $ unitID )
441503 {
442- return $ this ->getExcelData ('list-excel-unit-history ' );
504+ return $ this ->getExcelData ('list-excel-unit-history ' , [ ' unitid ' => $ unitID ] );
443505 }
444506
445507 /**
446- * Accepts several additional optional parameters:
447- * ● `filter_status` - if left empty, invoices in all statuses are sent. 1 - new invoices. 2 -
448- * invoices in Review #1. 3 - invoices in Review #2. 4 - invoices in approval. 5 - fully
449- * approved invoices. 6 - fully rejected invoices.
508+ * Listing of Invoices. The initial set of columns describes the Invoice
509+ * itself, and the last set of columns contains the data of its Lines.
510+ *
511+ * @var array $options ● `filter_status` - if left empty, invoices in all statuses are sent. 1 - new invoices. 2 -
512+ * invoices in Review #1. 3 - invoices in Review #2. 4 - invoices in approval. 5 - fully
513+ * approved invoices. 6 - fully rejected invoices.
450514 *
451- * ● `filter_groupcompany` - if left empty, invoices from all the group companies are sent. If
452- * Realpad database IDs of group companies are provided (as a comma-separated list),
453- * then only invoices from these companies are sent.
515+ * ● `filter_groupcompany` - if left empty, invoices from all the group companies are sent. If
516+ * Realpad database IDs of group companies are provided (as a comma-separated list),
517+ * then only invoices from these companies are sent.
454518 *
455- * ● `filter_issued_from` ` - specify a date in the 2019-12-31 format to only send invoices
456- * issues after that date.
519+ * ● `filter_issued_from` - specify a date in the 2019-12-31 format to only send invoices
520+ * issues after that date.
457521 *
458- * ● `filter_issued_to` - specify a date in the 2019-12-31 format to only send invoices issues
459- * before that date.
460- * The initial set of columns describes the Invoice itself, and the last set of columns contains the
461- * data of its Lines.
522+ * ● `filter_issued_to` - specify a date in the 2019-12-31 format to only send invoices issues before that date.
462523 *
463- * @todo Implement Filters
464524 *
465525 * @return array
466526 */
467- public function listInvoices ()
527+ public function listInvoices ($ options = [] )
468528 {
469- return $ this ->getExcelData ('list-excel-invoices ' );
529+ $ colsAvailble = [
530+ 'filter_status ' ,
531+ 'filter_groupcompany ' ,
532+ 'filter_issued_from ' ,
533+ 'filter_issued_to '
534+ ];
535+ foreach ($ options as $ key => $ value ) {
536+ if (array_search ($ key , $ colsAvailble ) === false ) {
537+ throw new \SpojeNet \Realpad \Exception ('Iillegal Invoice option ' . $ key );
538+ }
539+ }
540+ return $ this ->getExcelData ('list-excel-invoices ' , $ options );
470541 }
471542}
0 commit comments