-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API - Basic API calls #24
base: gsoc2014
Are you sure you want to change the base?
Conversation
API: Added toro library and created hello world basic handler
Creates database entry on login Generates token and deletes on logout
} | ||
|
||
function api_module_status(){ | ||
$enabled = queryDB("SELECT * FROM %smodules WHERE dir_name = '%s' and status = %d", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
queryDB always returns array of arrays. Rows of columns. What is returning value of this function? It makes more sense to return true/false rather than multidimensional array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do the following-
return $enabled[0]?true:false;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is slightly better. $enabled[0] is the array which represents the first row though. If you want to find if there are rows then you need to check count($result) where $result is returning result from queryDB. OR you need to change queryDB to return only 1 row and also return count(*) and then you can always access $result[0]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the using PHP's "count" to count the results. I will push the updated code soon.
Added basic GET calls for courses
} | ||
|
||
function log_request($log) { | ||
queryDB("INSERT INTO %sapi_logs(ip_address, request_uri, http_method, token, response) VALUES('%s', '%s', '%s', '%s', '%s')", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do some variable guarding because if $log is null then you will get a PHP error that $log["ip_address"]
is not accessible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I purposely misspelled ip_address and noticed that an empty string is inserted in the database and no error is raised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always think how you would possibly write a test case whenever you write a logic for your functions. if $log is null or empty you will raise php error when trying to get a property "ip_address"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could provide a default value. function log_request($log = array()) {
That way, it would not raise any error but enter an empty string into the database.
* "access_level" => ADMIN_ACCESS_LEVEL, | ||
* "query" => $query, | ||
* "query_array" => $array, | ||
* "one_row" => true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this option : "one_row" what is it for ?
$array = array(); | ||
} | ||
|
||
api_backbone(array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so if query is "" then what api_backbone will execute here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that case happens when I am making a PUT request without any parameters. No query is executed (as queryDB returns -1), but other things like logging takes place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't it make sense to change code then to be (using the concept of return more often):
if (!$clause) {
return;
}
$query = "UPDATE %scourses ".$clause. "WHERE course_id = %d ". $clause;
$array = array(TABLE_PREFIX, $course_id);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh actually never mind since query_id_existence will return nothing and user will see 404. Nevermind
…questions, tests)
…ng options, choices and answers
No description provided.