Giter VIP home page Giter VIP logo

hook-corona-sdk's Introduction

hook-corona-sdk

CoronaSDK client for hook.

Check the usage example with instructions to setup.

Usage

Initialize hook client with valid credentials

local hook = require('hook.client').setup({
  endpoint = "http://localhost:4665/",
  app_id = "1",
  key = "0473fae7392cc9653029f59b79126ace" -- your application "device" key
})

Collection examples

hook:collection("scores"):create({
  name = "Endel",
  score = 10
}):onSuccess(function(data)
  print("Created successfully.")
  print("Name: " .. data.name .. ", Score: " .. data.score .. ", Created at: " .. data.created_at)
end):onError(function(data)
  print("error on create")
end)
-- where and first
hook:collection("scores"):where("score", "<", 10):first():onSuccess(function(data)
  print("Score < 10?")
  print(json.encode(data))
end):onError(function()
  print("Not found!")
end)
-- where and count
hook:collection("scores"):where({
  score = 10
}):count():onSuccess(function(data)
  print("Total scores: " .. data)
end)
-- multiple wheres
hook:collection("scores"):
  where("score", 10):
  where("name", "Endel"):
  sort("created_at", -1):
  onSuccess(function(data)
  print("Number of rows: " .. #data .. ", first._id: " .. data[1]._id .. ", last._id: " .. data[#data]._id)
end)
-- aggregation
hook:collection("scores"):
  sum("score"):
  onSuccess(function(data)
  print("Sum of all scores: " .. data)
end)

Authentication examples

-- user registration
hook.auth:register({
  email = "[email protected]",
  password = "123456"
}):onSuccess(function(data)
  print(json.encode(data))
end):onError(function(data)
  print("auth:register error: " .. data.error)
end)
-- user login
hook.auth:login({
  email = "[email protected]",
  password = "test"
}):onSuccess(function(data)
  print("Logged in: " .. json.encode(data))
end):onError(function(data)
  print("auth:login error: " .. data.error)
end)

TODO

  • Write test units
  • Push notifications
  • Channels API
  • Remove CoronaSDK dependency and publish a luarocks package.

This library was tested only against CoronaSDK 2014.2511. It possible runs on older versions. Please create a pull-request if you find any problem.

License

MIT

hook-corona-sdk's People

Contributors

endel avatar

Watchers

 avatar James Cloos avatar  avatar

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.