PowerShell Mindflash Administration

04 April, 2016

Having a position where part of my job is to administrate users within Mindflash I am frequently completing the following tasks on Mindflash:
• Creating Users
• Enrolling users in courses
• Resetting user passwords

Often these tasks need to be completed for either an individual user or a batch of users at any given time. While Mindflash provides some bulk administration options through their web portal I found it a little limiting and a little clunky to use.

So naturally been a fan on the command line and primarily a Linux user I thought it would be great to be able to administer Mindflash users from a command line, In this case PowerShell. I have created Get-MindflashUser, A PowerShell cmdlet that hooks into the Mindflash API allowing for administration of users.

Get-MindflashUser allows you to complete all of the following tasks without ever leaving the PowerShell window.
• Get a list of all Mindflash users
• Get a list of all Mindflash courses
• Get a list of all users in a specific course
• Get a specific users details
• Get a specific users details including course enrolment details
• Get course progress for a given user and course
• Invite users to a course
• Reset user password
• Create new users

In addition to all of this, you would obviously be able to use Get-MindflashUser within you own scripts to automate repetitive tasks or generate reports.

Some Examples of Use
Resetting a users password

get-MindflashUser -email user@email.com -resetPassword true -newPassword P@ssword21 –Key <yourAPIKeyHere>

Creating a new user

get-MindflashUser -email user@email.com -first michael -last cho -newUser true -newPassword P@ssword21 –Key <yourAPIKeyHere>

There are more examples of user provided in the header of the script. If you find this script useful in any way please let me know by email at Nathan.kewley@gmail.com. Additionally if you find any issues or bugs in the script please shout out so I can resolve them.

 

Download Get-MindflashUser.ps1

 

Creative Commons License
Get-MindflashUser by Nathan Kewley is licensed under a Creative Commons Attribution 4.0 International License

 

Building a Crappy Rest API in PHP

01 April, 2016

So I got bored and decided it would be a good idea to build a Rest API for my website crappypuns.com. Having only briefly worked with Rest API’s once before I have no doubt that the API I have ended up building is not the best. It is however a simple to implement and understand API so could serve as a good starting point for working with or building API’s. The API and documentation for it are available at http://crappypuns.com/about.php.

The process for creating the API was surprisingly easy and required only two PHP files to create as there are only two commands exposed, one to query for puns and the other to query for images. Each query supports a common parameter ‘limit’ which specifies how many results should be returned up to a maximum of 20.

For the sake of simplicity I will focus only on http://crappypuns.com/api/api_pun.php which is the API link to get jokes. You can choose how many jokes you want returned from the server using the limit parameter like: http://crappypuns.com/api/api_pun.php?limit=10 will return 10 puns in JSON format.

The code that runs on the server when the API call is made is as follows (with minor tweaks for security).

<?php               
        //This is the function that will query the database for the puns
        function getPuns($connect, $limit){                                            
                //Get the amount of jokes required randomly from the database using fake sql parametrs for this example  
                $joke = mysqli_query($connect, "SELECT `punField`,`punIdField` FROM punTable ORDER BY RAND() LIMIT $limit");
                                                                      
                //fetch each result that was returned               
                while($row = mysqli_fetch_assoc($joke)){                 
                        //Append the data to $output               
                        $output[]=$row;                   
                }                                  
                //return the puns pulled from the databse       
                return $output;                    
        }                                             
                                                    
        //See if a limit parameter is set. If not set the limit to 1       
        if (isset($_GET['limit'])){                       
                $limit = $_GET['limit'];               
        }else{$limit = 1;}                      
                                                               
        //make sure limit does not exceed max of 20           
        if($limit > 20){$limit = 20;}                       
                                                         
        //Establish a connection to the database     
        $connect = mysqli_connect('server', 'usrname', 'password', 'database');
        
        //Get the punss from the database                                 
        $jokes = getPuns($connect, $limit);                         
                                                                               
        //Return the results in json format                                 
        print(json_encode($jokes, JSON_UNESCAPED_SLASHES));                  
?> 

I think this is probably the most simple an API can get. Ideally you would expand on this by having some form of security in place like a validation key required to make requests. Maybe a limit on how many requests a client can make in a given time frame.

Home