 b64_to_utf8 = (str) ->
     unescape decodeURIComponent atob str
 
+serialize = (record, serializer) ->
+    object = serializer.serialize record
+    json = JSON.stringify object
+    utf8_to_b64 json
+
 guid = (->
     s4 = ->
         Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1)

        throw "I DIDN'T IMPLEMENT THIS SHIT"

    createRecord: (store, type, record) -> new Promise (resolve) ->
        record.set 'id', guid()
        serializer = store.serializerFor type.typeKey

        key = getKey record
        data = serializer.serialize record

        localStorage.setItem key, utf8_to_b64 JSON.stringify data
        resolve()

    updateRecord: (store, type, record) -> new Promise (resolve) ->
        serializer = store.serializerFor type.typeKey

        key = getKey record
        data = serializer.serialize record

        localStorage.setItem key, utf8_to_b64 JSON.stringify data
        resolve()

    deleteRecord: (store, type, record) ->

    return ->
        s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4()
)()

Promise = Ember.RSVP.Promise

