Mockacino a lightweight ruby/sinatra API Mocking script

Hi Guys, so i’ve been working on a new app recently for a client of mine, currently there is no API… so in the meantime I decided to knock up a quick few lines of ruby to get a mocking api up and running… to explain this better, I need not do more than paste my README.md here.. Enjoy 🙂

Mockacino

A very simple and easy to use MOCK API server that serves static JSON written in ruby/sinatra.


NOTE: This is a super simple, super fragile MOCKING SERVER Intended so you can test routes and mock an API with static jso whilst you’re still building the real production API. DO NOT EVER use this in production… Seriously. It breaks a lot and will if you try… DONT. Absolutely 0 effort went into it, therefor 0 Warranty. Use if you dare.

DOCS:

Folder structure defines API calls…. return.json is what gets served.

site_root ->;
    [ http method ] ->; [ api call route ] ->; [ json response contents of call return.json ] 

e.g.

site_root ->;
    GET ->; users ->; return.json
    POST ->; users ->; create ->; return.json

If you have static assets you wanna reference in the json, plonk them in the ASSETS folder

e.g.

site_root ->; file.jpg

You can call http://yourhost:port/ASSETS/file.jpg

Here’s the directory structure of the sample project included here

mockacino.rb  
./site_root/ASSETS
./site_root/GET
./site_root/POST
./site_root/GET/sheep
./site_root/GET/sheep/create
./site_root/GET/sheep/return.json
./site_root/GET/sheep/create/return.json

Which supports calls like…

http://localhost:4567/sheep
http://localhost:4567/sheep/create

And gives responses from the static result.json file like…

{
    "sheep": [
        {
            "id": "1234",
            "name": "Dolly Two",
            "url": "http://mike.kz/sheep1234",
            "assets": {
                "small_image": "http://cloned.sheep.com/ASSETS/small.jpg",
                "large_image": "http://cloned.sheep.com/ASSETS/large.jpg"
            }
        }
    ]
}

Usage:

gem install sinatra
ruby mockacino.rb
 

Installing Debian or Ubuntu on a Cubox i4-Pro

IMG_0434In March I got my hands on a new Cubox i4-Pro, for those who don’t know what it is… its basically an armv7l based “raspberry-pi style” 2″ cube on crack! It packs a Quad Core 2GHz armv7l i.MX6  variant architecture with 2GB of memory, on board bluetooth,wifi,esata,usb and more. Its pretty damn cool… Until recently I didn’t really have time to get it all up and running, but after unboxing it last week, I realised… damn this thing is tiny and must pack a punch… So I get it out the box and I wonder… so…. erm…. how do I get something running on this thing. After a quick lazy trawl of Google I noticed there isn’t a lot of info compared to other dev-boards and systems and a lot of info seems out of date. So here is my attempt to making a first post of a few, this one aimed at getting you up and running immediately on a CuBox i4-Pro with a “no-frills” approach… Next in line, i’ll maybe do some posts on how to build your own image, kernel and more. These instructions are for Linux / Mac OS X only really. Those using Windows, google is your friend :).

  • Firstly download the latest debian jessi image from solid-run.com. (note: if you browse around there you’ll find both an ubuntu and geexbox image also).
IMG_0435 IMG_0436

Now you’ve got all that downloaded. The next step is to extract it using the ‘xz’ utility. Much like any other compression utility, this one is a little different as it uses lzma but supports the usual commands.

xz --decompress debian-jessi-4-july-2014.img.xz

You should now be left with a .img file thats ready to copy over to your Micro SD card 🙂 To do this we’ll be using the ‘dd’ utility that ships with most variants of Linux and Mac OS X. Windows users can find `windd` via the google link above 🙂

But before hand… you’ll need to find out which device on your system is your Micro SD card and make sure NOT mounted!

Mac OS X :

~# diskutil list
/dev/disk0
#: ......
/dev/disk1
#: ......
/dev/disk2
#: TYPE NAME SIZE IDENTIFIER
0: FAT *31.97GB disk2

~# diskutil unmountDisk disk2

Linux :

sudo fdisk -l
sudo umount /dev/somedevice

Now you know which device you want… its time to copy over that .img! For this we’ll be using ‘dd’. Depending on which version of ‘dd’ you’ve got on Mac OS X or Linux, the command will vary very slightly, but remain very similar.

Mac OS X:
sudo dd if=/path/to/debian-jessi-4-july-2014.img of=/dev/disk2 bs=16384

Linux:
sudo dd if=/path/to/debian-jessi-4-july-2014.img of=/dev/sdb bs=16M

On Linux you’re likely to see progress, but on Mac OS X, nothing will “appear” to happen and the command prompt will hang, but trust me… thats a good thing, its copying… Once done. Your prompt will return to normal and after a few seconds, you can safely pull the Micro SD out of your machine.

Now place that Micro SD into your Cubox i4-Pro upside down. Plug in some power and Ethernet… and boot! 🙂