Hi Brad
Yes here it is.
You will have to create an account and a test application at parse.com, after you have done that you can find the “Application-Id” and the “REST-API-Key” in your dashboard there.
Copy the id and the key into the code below and you are ready to go.
I have been trying to upload and download images to the parse backend, but have some problems decoding the image file. If anyone can help me with this I will be very happy. See this link:
https://developer.anscamobile.com/forum/2012/01/20/downloading-base64-encoded-image-server
Here is the code:
[lua]local json = require “json”
local baseUrl = “https://api.parse.com/1/classes/”
local objectClass = “testClass”
local objectId = nil
local responseTF
local headers = {}
headers[“Content-Type”] = “application/json”
headers[“X-Parse-Application-Id”] = “” – your Application-Id
headers[“X-Parse-REST-API-Key”] = “” – your REST-API-Key
local params = {}
params.headers = headers
local function networkListener( event )
if ( event.isError ) then
print( “Network error!”)
else
local response = json.decode ( event.response )
if response[“objectId”] then
objectId = response[“objectId”]
end
end
responseTF.text = "RESPONSE: " … event.response
end
local function post ( message )
params.body = json.encode ( message )
network.request( baseUrl … objectClass, “POST”, networkListener, params)
end
local function put ( message, id )
if id then
params.body = json.encode ( message )
network.request( baseUrl … objectClass …"/"… id, “PUT”, networkListener, params)
end
end
local function delete ( id )
if id then network.request( baseUrl … objectClass …"/"… id, “DELETE”, networkListener, params) end
objectId = nil
end
local function get ( id )
params.body = nil
if id then network.request( baseUrl … objectClass …"/"… id, “GET”, networkListener, params) end
end
– set up buttons
local message = { foo = “bar” }
responseTF = display.newText ( “”, 30, 260, 260, 200, native.systemFont, 12)
local function buttonHandler ( event )
local method = event.target.method
if event.phase == “began” then
if method == “POST” then post ( message )
elseif method == “GET” then get ( objectId )
elseif method == “PUT” then put ( message, objectId )
elseif method == “DELETE” then delete ( objectId ) end
end
end
local buttons = { “POST”, “GET”, “PUT”, “DELETE” }
for i=1,#buttons do
local b = display.newText ( buttons[i], 30, 50*i, native.systemFontBold, 23)
b.method = buttons[i]
b:addEventListener ( “touch”, buttonHandler )
end[/lua]
[import]uid: 13632 topic_id: 15637 reply_id: 81554[/import]