Skip to content

Instantly share code, notes, and snippets.

@aGupieWare
aGupieWare / phplumbing_bare_bones_api
Created October 25, 2014 21:10
A bare-bones RESTful API interface . . .
<?php
/*
Plumbing Supply House API -- Super PHPlumbing Bros. Inc.
This script provides a RESTful API interface for a web application
Input:
$_GET['format'] = [ json | html | xml ]
$_GET['method'] = []
Output: A formatted HTTP response
@aGupieWare
aGupieWare / copper_pipes_and_fittings_inventory.php
Created October 29, 2014 05:41
Copper pipes and fittings inventory array . . .
return array(
'0' => array(
'id' => 'CP12010',
'name' => '1 inch copper pipe.',
'image' => 'http://localhost:8888/assets/1_inch_copper_pipe.png',
'description' => '1 in. x 10 ft. Copper Type M Hard Temper Straight Pipe for a multitude of plumbing and heating purposes. It is NSF and ANSI Standard 61 certified. Made of hard-temper ASTM - B88 copper. For general plumbing and heating purposes. Alloy C12200 (DHP) meets industry standards and is NSF and ANSI Standard 61 certified. Meets or exceeds industry standards to deliver a high quality flow product. Plumbing and mechanical codes govern what types of products may be used for applications. Local codes should always be consulted for minimum requirements'),
'1' => array(
'id' => 'CP12020',
'name' => '1 1/4 inch copper pipe.',
'image' => 'http://localhost:8888/assets/1_1_4_inch_copper_pipe.png',
@aGupieWare
aGupieWare / deliver_response.php
Created October 29, 2014 05:56
Deliver response logic for PHPlumbing api . . .
// Define HTTP responses //
$http_response_code = array(
200 => 'OK',
400 => 'Bad Request',
401 => 'Unauthorized',
403 => 'Forbidden',
404 => 'Not Found'
);
// Set HTTP Response //
@aGupieWare
aGupieWare / phplumbing_api_part_two.php
Created October 29, 2014 22:11
This file contains the base code for building out the second half of our Super PHPlumbing Bros api . . .
<?php
/*
Plumbing Supply House API -- PHP Plumbing inc.
This script provides a RESTful API interface for a web application
Input:
$_GET['format'] = [ json | html | xml ]
$_GET['method'] = []
Output: A formatted HTTP response
@aGupieWare
aGupieWare / plumbing_tools_inventory.php
Created October 29, 2014 22:23
The plumbing tools inventory for part two of building a RESTful API in PHP . . .
return array(
'0' => array(
'id' => 'PT12010',
'name' => 'Plunger.',
'image' => 'http://localhost:8888/assets/plunger.png',
'description' => 'Super-pliable industrial-rubber cup with tiered ridges forms ultra-tight seal on any size drain. The heavy-duty steel handle allows for maximum pressure forced down drain to source of clog. Designed to work effectively at any angle for hard-to-reach, low-clearance applications.'),
'1' => array(
'id' => 'PT12020',
'name' => 'Pipe Wrench.',
'image' => 'http://localhost:8888/assets/pipe_wrench.png',
@aGupieWare
aGupieWare / plumbing_supply_item.txt
Created November 6, 2014 21:26
Code snippet for Swift client plumbing supply item class implementation
var bsn_id : String? = ""
var bsn_name : String? = ""
var bsn_image : String? = ""
var bsn_description : String? = ""
init(var bsn_id : String?, var bsn_name : String?, var bsn_image : String?, var bsn_description : String?) {
self.bsn_id = bsn_id
self.bsn_name = bsn_name
self.bsn_image = bsn_image
self.bsn_description = bsn_description
@aGupieWare
aGupieWare / swift_client_url_endpoint.txt
Created November 6, 2014 21:42
Code snippet for Swift client inventory URL endpoint
class PlumbingSupplyInventoryTableViewController: UITableViewController {
var inventoryUrlEndpoint : String = ""
...
}
@aGupieWare
aGupieWare / Swift_client_prepare_for_segue.txt
Created November 6, 2014 21:45
Swift client, prepare for segue snippet . . .
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var destViewController = segue.destinationViewController as PlumbingSupplyInventoryTableViewController
if segue.identifier == "plumbingTools" {
destViewController.title = "Plumbing Tools"
destViewController.inventoryUrlEndpoint = "http://localhost:8888/api/v1/plumbing_tools.json"
}
else if segue.identifier == "copperPipesAndFittings" {
destViewController.title = "Copper Pipes and Fittings"
destViewController.inventoryUrlEndpoint = "http://localhost:8888/api/v1/copper_pipes_and_fittings.json"
@aGupieWare
aGupieWare / web_activity_indicator_var.txt
Created November 6, 2014 21:49
Swift client, web activity indicator var . . .
private var webActivityIndicator : UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.WhiteLarge)
@aGupieWare
aGupieWare / Swift_client_activity_indicator_2.txt
Created November 6, 2014 21:52
Swift client activity indicator 2, snippet . . .
self.webActivityIndicator.color = UIColor.lightGrayColor()
self.webActivityIndicator.startAnimating()
self.webActivityIndicator.center = self.view.center
self.view.addSubview(self.webActivityIndicator)