Parse

Parse

by develephant

View and activate on the Corona Store

A Parse.com plugin for Corona SDK development based on the full Parse REST API. Parse handles everything you need to store data securely and efficiently in the cloud. Store basic data types, including locations and photos, and query across them without spinning up a single server. Parse also features analytics, A/B testing, push, email, and more.

Documentation

Thanks Michael!

It’s finally here folks. Have at it!

Need help? Visit http://support.coronium.io

Cheers.

This is amazing news. Thank you @develephant for this.

HI,

I have started porting my code from previous parse module to the new plugin.

Doing the following code; always failed saying missing password.

 local function cb( ok, res, info ) print( ok, res, info ) end parse.request( parse.User.login ) :set("username", "userNameForTest") :set("password", "testing123") :response(cb)

Here is the message I always receive :

********************************************************************

** Parse RESPONSE @ 11-24 22:44:26 [1]

********************************************************************

> code: 201

> error: missing user password

********************************************************************

PS: I can create object successfully.

thanks for your help

Whoo hoo, first bug! Let me take a look.

Cheers

Looks like a documentation error. Its been updated. The proper syntax is:

[lua]parse.request( parse.User.login )
:options( { username = “Nestor”, password = “1234abcd” } )
:response(cb)[/lua]

Thanks for bringing it to my attention.

Cheers.

Thank you sir, it is indeed now working properly :slight_smile:

I think I found another bug while migrating our code. In the case of a reset password :

 parse.request( parse.User.requestPasswordReset ) :options( { email = "thisIsThePswd" } ) :response(cb)

We always receive this error :

********************************************************************

** Parse RESPONSE @ 11-25 16:00:00 [1]

********************************************************************

> code: 204

> error: you must provide an email

thanks for your help

I have a few more questions.

In modParse we were using the method modParse:linkObject to link a user to an object. WIth the new plugin, how would you suggest we do that? 

Also in modParse we were using the method :

modParse:linkFile( modParse.USER, objectId, “userData”, fileUri, fileUrl, onLinkFile ) to link a file to an object. With the new API, I am not sure to understand how to establish the link between the objectId and the file information.

thank you

Nick

Great plugin, got everything I needed working in a day! Fantastic work. 

Out of interest does the plugin support batch requests? 

Hi,

Batch requests are in the pipeline. Should be soon.

@nick - I’ll take a look at the issues.

Cheers.

here is my code,i can create,update,and i want get the string from parse that i created,i use query [res.color] to get string,but it return nil?

any idea?

parse.request( parse.Object.create, “test” )
:data( { color = “Green”,  yes = “red”, })
:response()

parse.request( parse.Object.query, “test” )
:response(function( ok, res )
    if not ok then
      print(‘err’, res)
    else
    print(‘yes’, res)
      print(res.color, res.yes)
    end
  end)

parse.request( parse.Object.update, “test”,“4PP8K8jecJ”)
:data( {color = “black”})
:response()

Updated release 0.2.4

Added Macros

Added Batch Operations

Refactored Misc Stuff

Updated Docs

Enjoy.

Hi,

To retrieve the Object record you can use a “get” or a “query” (See here). In this case you are using a query, but it’s not properly built up. More on that in a sec.

Also, be mindful that “test” is the Class name on Parse, not your object identifier. You could consider “test” the category that your data objects are stored in. In the response of certain plugin calls to Parse you will find identifiers. Turning on debugging – after your Parse plugin “init” – can be helpful in these cases.

parse.config:debugEnabled( true )

How you manage and store these ids is up to you. Parses methodology is the User system, being the only entry point accessible by a users credentials. You can then create relations as needed to other Object ids using the User id as your “master” identifier.

Now, back to the code. On the “test” Class instance you have added 2 properties ( color and yes ), these are searchable with a parse.Object.query :

parse.request( parse.Object.query, “test” ) --Class (category)

:where( { color = “red” } ) --The search key query

:response(function( ok, res )

  if not ok then

    print( ‘err’, res )

  else

    parse.trace( res ) --parse.trace() outputs table data

    print( res.objectId ) --the actual id

  end

end)

This would bring back all Objects from the “test” Class that contain a key called “color” that is equal to “red”. The plugin offers Macros (shortcuts) as well, so you could also use:

parse.macro.findWhereEqual( “test”, “color”, “red” ) --Class, key, value

:response(cb)

Generally you’ll be working with objectIds, so to fetch the Object as shown in your example, you would us a parse.Object.get :

parse.request( parse.Object.get, “test”, “4PP8K8jecJ” ) --Class, objectId

:response(function( ok, res )

  if not ok then

    print( ‘err’, res )

  else

    print( res.color ) – red

  end

end)

Hope that helps. Be sure to read through the documentation at parse.develephant.com

Cheers.

i try again,it still don’t work,i can create,get,update,but i use query to get objectId value but it return nil(code line 31)

please see code line 31​

please see code line 31​
it return value=nil and I want to get objectId value(s6Au2jeHmF)

this is my parse screen picture

this is my console output picture

my code

parse.config:debugEnabled( true ) --get local req = parse.request( parse.Object.get, "countertest","s6Au2jeHmF" ) req:response(function( ok, res ) if not ok then print('err', res) else print('get', res) print(res.counter, res.yes) end end) --create parse.request( parse.Object.create, "countertest" ) :data( { counter = "1", yes = "kkk", }) :response() --macro parse.macro.findWhereEqual( "countertest", "counter", "1" ) --Class, key, value :response(cb) --query parse.request( parse.Object.query, "countertest" ) :where( { counter = "1" } ) --The search key query :response(function( ok, res ) if not ok then print('err', res) else print('yes', res) print( res.objectId ) --the actual id(I want this actual id,but it return nil) end end)

@wgh92281 can you be more specific of what is the problem and what are you trying to achieve here ? Its very hard to understand what you want to do exactly and your code is really not easy to read. Please use proper code formating and focus on the code that does not work.

@nmichaud

i edit my post,thanks anyway

You should look at res.result (as you are doing a query in this case). Careful here, it is a table…

Also, I would suggest you use a debugger in the future and put a breakpoint in the callback method. You will then be able to look at the values and then find out very quickly of the returned data. Its the best way to learn how to deal with methods you are unsure of the data you receive.

i very appreciate your help,but i use res.result  instead of res.objectId.(code line 27), it still return value=nil

and I found that I use res.objectId( code line 7)  it return value= s6Au2jeHmF

I don’t understand why it work on get method, but it don’t work on query method

I really want to know how to get my objectId that I create.

 local req = parse.request( parse.Object.get, "countertest","s6Au2jeHmF" ) req:response(function( ok, res ) if not ok then print('err', res) else print('get', res) print(res.counter, res.yes,res.objectId) end end) --]] ---[[parse.request( parse.Object.create, "countertest" ) :data( { counter = "1", yes = "kkk", }) :response() --]] parse.macro.findWhereEqual( "countertest", "counter", "1" ) --Class, key, value :response(cb) parse.request( parse.Object.query, "countertest" ) :where( { counter = "1" } ) --The search key query :response(function( ok, res ) if not ok then print('err', res) else -- parse.trace( res ) --parse.trace() outputs table data print('yes', res) print( res.result ) --the actual id end end)

Hi,

I’m pretty sure a “query” will always return a table array of the results , even if it’s only one record. So:

local function callback( ok, res )

  for _, result in ipairs( res ) do

    print( result.objectId )

  end

end

You should be able to see the structure in the debug output.

@nmichaud thanks for jumping in.

Cheers.