Skip to content

Commit 7c6c63f

Browse files
committed
EOD Changes
- Require 'ext-curl' - Fix xml2js return - Added API_Authenticate test - Create runAll.php for running tests
1 parent 969028e commit 7c6c63f

File tree

4 files changed

+113
-25
lines changed

4 files changed

+113
-25
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
}
2424
],
2525
"require": {
26-
"php": ">=5.4.0"
26+
"php": ">=5.4.0",
27+
"ext-curl": "*"
2728
}
2829
}

quickbase.php

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
/* Error Handling */
19-
class QuickBaseError extends Exception {
20-
21-
public function __construct($code = 0, $message = 'No error', $detail = ''){
22-
parent::__construct($message.$detail, $code);
23-
}
24-
25-
public function __toString(){
26-
return __CLASS__.': ['.$this->code.'] '.$this->message;
27-
}
28-
29-
}
30-
3118
class QuickBase {
3219

3320
private $defaults = array(
@@ -55,22 +42,40 @@ class QuickBase {
5542
'errdetail' => ''
5643
),
5744

58-
'maxErrorRetryAttempts': 3,
59-
// 'connectionLimit' => 10,
60-
// 'errorOnConnectionLimit' => false
45+
'maxErrorRetryAttempts' => 3
6146
);
6247

63-
public function __construct($options){
48+
public function __construct($options = array()){
6449
$this->settings = array_merge_recursive($this->defaults, $options);
6550
}
6651

67-
public function api($action, $options){
52+
public function api($action, $options = array()){
53+
return new QuickBaseQuery($this, $action, $options);
54+
}
55+
56+
}
57+
58+
class QuickBaseError extends Exception {
59+
60+
public function __construct($code = 0, $message = 'No error', $detail = ''){
61+
parent::__construct($message.$detail, $code);
62+
}
63+
64+
public function __toString(){
65+
return __CLASS__.': ['.$this->code.'] '.$this->message;
66+
}
67+
68+
}
6869

70+
class QuickBaseQuery {
71+
72+
public function __construct($action, $options){
73+
$this->packet = new SimpleXMLElement('<qdbapi></qdbapi>');
74+
75+
return $this;
6976
}
7077

71-
/* Helpers */
72-
protected function xml2js($xml){
73-
$root = func_num_args() > 1 ? false : true;
78+
protected function xml2js($xml, $root = false){
7479
$js = array();
7580

7681
if($root){
@@ -79,7 +84,7 @@ protected function xml2js($xml){
7984

8085
array_push($js[$nodeName], $this->xml2js($xml, true));
8186

82-
return $json_encode($js);
87+
return json_encode($js);
8388
}
8489

8590
if(count($xml->attributes()) > 0){
@@ -106,7 +111,7 @@ protected function xml2js($xml){
106111
array_push($js[$childName], $this->xml2js($child, true));
107112
}
108113

109-
return $js;
114+
return json_encode($js);
110115
}
111116

112117
}

tests/API_Authenticate.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/* Copyright 2015 Tristian Flanagan
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
$response = $qb->api('API_Authenticate', array(
19+
'username' => '',
20+
'password' => ''
21+
));
22+
23+
?>

tests/runAll.php

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,65 @@
1515
* limitations under the License.
1616
*/
1717

18-
require_once('../quickbase.php');
18+
/* Dependancies */
19+
require_once(__DIR__.'/../quickbase.php');
20+
21+
/* Error Handling */
22+
set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext){
23+
if(error_reporting() === 0){
24+
return false;
25+
}
26+
27+
throw new Exception($errstr, $errno);
28+
});
29+
30+
/* Globals */
31+
$stderr = fopen('php://stderr', 'w+');
32+
$error = false;
33+
34+
$qb = new QuickBase();
35+
36+
/* Main */
37+
$files = array_diff(scandir(__DIR__), array(
38+
'..',
39+
'.',
40+
'runAll.php',
41+
'API_Authenticate.php'
42+
));
43+
44+
array_unshift($files, 'API_Authenticate.php');
45+
46+
foreach($files as $i => $file){
47+
if(strpos($file, '.') === 0){
48+
continue;
49+
}
50+
51+
try {
52+
echo "\nRunning Test ".$file.'... ';
53+
54+
include(__DIR__.'/'.$file);
55+
56+
echo 'Passed.';
57+
}catch(Exception $e){
58+
fwrite($stderr, implode('', array(
59+
'Failed!',
60+
"\n\nError: [".$e->getCode().'] ',
61+
$e->getMessage(),
62+
"\n".$e->getTraceAsString()
63+
)));
64+
65+
$error = true;
66+
67+
break;
68+
}
69+
}
70+
71+
fclose($stderr);
72+
73+
if($error){
74+
echo "\n\nTesting Failed! Please see above for details.";
75+
}else{
76+
echo "\n\nTesting Complete!";
77+
}
1978

2079
?>

0 commit comments

Comments
 (0)