Skip to content

Instantly share code, notes, and snippets.

View aaronksaunders's full-sized avatar

Aaron K Saunders aaronksaunders

View GitHub Profile
@aaronksaunders
aaronksaunders / parse.js
Last active August 29, 2015 14:19 — forked from stephenfeather/parse.js
Update parse service for working with Appcelerator Titanium, still some open issues but making progress - will be moving the complete file into a sample starter project
//
// Copyright Aaron K. Saunders and other contributors. 2015
//
// Primarily based on work by Stephen Feather - https://gist.github.com/sfeather/4400387
// with additions listed below
// - added promise functionality (https://github.com/kriskowal/q), and removing callbacks
// - added url query param support to allow for more interesting queries
// - added promises.notify to support in progress information from http request
// - added init function to extract credentials from the library
// - fare number of the user functions are not correct

To implement API authentication in KeystoneJS, you need the following:

For key based authentication

  • Middleware that validates the key in the request body or a header

For session based authentication

  • An endpoint that handles signin
  • An endpoint that handles signout

This is an example of how to scaffold API endpoints to list / get / create / update / delete Posts in a Keystone website.

It's a modification of the default project created with the yo keystone generator (see https://github.com/JedWatson/generator-keystone)

Gists don't let you specify full paths, so in the project structure the files would be:

routes-index.js        -->    /routes/index.js         // modified to add the api endpoints
routes-api-posts.js    -->    /routes/api/posts.js     // new file containing the Post API route controllers
config.json
reading-image.png
var myApp = angular.module('myApp').service('CordovaNetwork', ['$rootScope', '$ionicPlatform', '$q', function($rootScope, $ionicPlatform, $q) {
// Get Cordova's global Connection object or emulate a smilar one
var Connection = window.Connection || {
'ETHERNET' : 'ethernet',
'WIFI' : 'wifi',
'CELL_2G' : 'cell_2g',
'CELL_3G' : 'cell_3g',
'CELL_4G' : 'cell_4g',
'CELL' : 'cell',
'EDGE' : 'edge',
function RateMe(ios_url, goog_url, usecount) {
if(!Ti.App.Properties.hasProperty('RemindToRate')) {
Ti.App.Properties.setString('RemindToRate', 0);
}
var remindCountAsInt = parseInt(Ti.App.Properties.getString('RemindToRate'), 10);
var newRemindCount = remindCountAsInt + 1;
if(remindCountAsInt === -1) {
// the user has either rated the app already, or has opted to never be
// reminded again.
@aaronksaunders
aaronksaunders / app.js
Last active December 21, 2015 03:58 — forked from rborn/app.js
var get_file = function(url, callback) {
var xhr = Ti.Network.createHTTPClient({
onload: function(e) {
// this function is called when data is returned from the server and available for use
// this.responseText holds the raw text return of the message (used for text/JSON)
// this.responseXML holds any returned XML (including SOAP)
// this.responseData holds any returned binary data
console.log('downloaded '+ url);
callback({

TiAgent

Ti Agent is light-weight progressive ajax API crafted for flexibility, readability, and a low learning curve after being frustrated with many of the existing request APIs.

 request
   .post('/api/pet')
   .data({ name: 'Manny', species: 'cat' })
   .set('X-API-Key', 'foobar')
   .set('Accept', 'application/json')

.end(function(res){

<!DOCTYPE html>
<head>
<title>HTML5 Camera Fun</title>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://www.nihilogic.dk/labs/exif/exif.js" type="text/javascript"></script>
<script src="http://www.nihilogic.dk/labs/binaryajax/binaryajax.js" type="text/javascript"></script>
<script type="text/javascript">
// Wrapper around MPL-licensed http://www.nihilogic.dk/labs/binaryajax/binaryajax.js
// to support JavaScript typed arrays since binary strings are not supported in IE 10
var createBinaryFile = function(uintArray) {
/**
* @preserve
* Titanium Cloud Module
*
* This module is used across three distinct platforms (iOS, Android, and Mobile Web), each with their own architectural
* demands upon it.
*
* Appcelerator Titanium is Copyright (c) 2009-2010 by Appcelerator, Inc.
* and licensed under the Apache Public License (version 2)
*/