Coder Social home page Coder Social logo

alloy-stackmob-adapter's Introduction

#Appcelerator Alloy StackMob Sync Adapter

First attempt at migrating the old adapter from two months ago. This is an EARLY BASIC attempt and not meant to be a final solution, but my first draft and demostrating how this MIGHT be implemented... Enjoy... Learn and spread the word.

CODESTRONG

##To use stackmob sync adapter, you must set the keys in the tiapp.xml

<!-- stackmob keys -->
<property name="STACKMOB_PUBLIC_KEY" type="string">YOUR KEY</property>
<property name="STACKMOB_PRIVATE_KEY" type="string">YOUR PRIVATE KEY</property>

##Define your modules the usual manner

exports.definition = {

    config : {
        "columns" : {},
        "defaults" : {},
        "adapter" : {
            "type" : "stackmob",
        },
        "settings" : {
            STACKMOB_APP_NAME : 'people_interact',
            STACKMOB_USER_OBJECT_NAME : 'user',
            STACKMOB_MODEL_NAME : 'user',
        }
    },

    extendModel : function(Model) { 
        _.extend(Model.prototype, {
            url : function() {
                return "http://stackmob.mob1.stackmob.com/api/0/" + this.config.settings.STACKMOB_APP_NAME + "/";
            },
			/**
			* helper function to log a user into stackmob
			*/
            login : function(_opts) { debugger;
                var model = this;
                model.sync('login', model, {
                    success : function(data) { 
                        _opts.success && _opts.success(new Model(data));
                    },
                    error : function(data) {
                        _opts.error && _opts.error(data);
                    }
                });

            }
        });
        // end extend

        return Model;
    },

    extendCollection : function(Collection) {
        _.extend(Collection.prototype, {
            url : function() {
                return "http://stackmob.mob1.stackmob.com/api/0/" + this.config.settings.STACKMOB_APP_NAME + "/";
            },
        });
        // end extend

        return Collection;
    }
}

##Login a user, this is assuming you have created the user object in StackMob

var user = Alloy.createModel('User', {
    'username' : "alloy-sample-2",
    'password' : "password",
});
user.login({
    success : function(model, resp) {
        Ti.API.info(' user.login ' + JSON.stringify(model.toJSON()));
    },
    error : function(resp) {
        Ti.API.error(' user.login  ERROR ' + resp);
    }
})

##Create a User

var user = Alloy.createModel('User', {
    'username' : "alloy-sample-2",
    'password' : "password",
	'email' : '[email protected]'
});

user.save({}, {
    success : function(model, resp) {
        Ti.API.info(' user.login ' + JSON.stringify(model.toJSON()));
    },
    error : function(model, resp) {
        Ti.API.info(' user.login ' + JSON.stringify(model.toJSON()));
    }
})

##Objects will be created with a guid which Backbone needs but StackMob does not expose

{  
    "username": "alloy-sample-2",
    "lastmoddate": 1351720630379,
    "user_id": "55dd6f38-8e5e-c50f-e090-858d78c5565a", // Generated by adapter
    "sm_owner": "user/alloy-sample-2",
    "createddate": 1351720630379    
}  

the id is the combination of the object name + _id

alloy-stackmob-adapter's People

Contributors

aaronksaunders avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dgrekov jigarm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.