@@ -58,4 +58,46 @@ public function put($path, $data, $headers = null) {
58
58
public function delete ($ path , $ data , $ headers = null ) {
59
59
return $ this ->_request ($ path , 'DELETE ' , $ data , $ headers );
60
60
}
61
+
62
+ private function _apiHelper ($ path , $ params )
63
+ {
64
+ $ params ['format ' ] = 'json ' ;
65
+ $ json = $ this ->get ($ path , $ params , array ('Accept: application/json ' ));
66
+ return $ json == null ? null : json_decode ($ json , true );
67
+ }
68
+
69
+ public function do_query ($ query_path ,$ params ,$ return_param )
70
+ {
71
+ // query path is location to api query, params is either a string (if only one param) or an
72
+ // associtative array, $return_param is the name of the parameter to lookfor and display...
73
+ // what is params ? if only a single then use this code
74
+ // require everyone to pass an associtative array, even if only requesting a single value ??
75
+
76
+ if (!is_array ($ params ){
77
+ // allow developer to pass paramname,attribute
78
+ unset($ params );
79
+ $ one_param = explode (', ' ,$ params ));
80
+ if (count ($ one_param ) == 2 ){
81
+
82
+ $ params [$ one_param [0 ]] = $ one_param [1 ];
83
+ unset($ one_param );
84
+ //}else{
85
+ //foreach($one_param as $key=>$value){
86
+ // ideally allow for developers to pass lists like param:value,param2:value2 - but
87
+ // not sure about issues with escaping .. something to explore (might get in trouble using commas, colons etc.
88
+ //}
89
+ }
90
+ }
91
+
92
+ $ data = $ this ->_apiHelper ($ query_path , $ params );
93
+ return ($ data == null
94
+ ? null
95
+ : (is_array ($ data ) && array_key_exists ($ return_param , $ data )
96
+ ? array_key_exists ($ return_param , $ data )
97
+ ? $ data [$ return_param ]
98
+ : array ()
99
+ : array ()
100
+ )
101
+ );
102
+ }
61
103
}
0 commit comments