LeanMotion LeanCloud SDK 封装

我要开发同款
匿名用户2014年12月15日
20阅读
开发技术Ruby
所属分类Web应用开发、网站API
授权协议MIT

作品详情

LeanCloud,一个为移动应用提供数据统计、数据存储、消息推送、发送短信、发送邮件等云服务商。

LeanMotion是一个RubyMotion的Gem,可以更加方便地使用LeanCloudSDK。用更Ruby的写法来操作LeanCloud的数据,类Rails的ActiveRecord,增删查改。

安装说明

1、安装gem

gem install lean_motion

2、创建项目

lean_motion create app-name

3、修改app_delegate.rb设置LeanCloud的AppID和AppKey

app_id   = "your_app_id"app_key  = "your_app_key"

4、运行

rake使用说明

1、在LeanCloud后台创建一个Class,比如Product,并添加以下字段

name: Stringdescription: Stringurl: String

2、添加model文件product.rb,建议放在app/models/目录下

class Product  include LM::Model  fields :name, :description, :urlend

3、操作数据

新建产品

product = Product.newproduct.name        = 'iPhone 6'product.description = '目前最好的智能手机'product.url         = 'https://www.apple.com'product.save

产品数量

Product.count

查询产品

Product.where(:name=>'iPhone 6').find

获得第一条记录

Product.first

排序

Product.sort(:createdAt=>:desc).find

分页(默认是20条记录/页)

Product.page(current_page, pagesize)

4、帐号相关注册帐号

user = User.newuser.username = '用户名,必须唯一'user.password = '必填'user.signUp

登录

User.login('用户名', '密码') do |user, error|  if !error    p '登录成功'  endend

退出

User.logout

判断是否已登录

User.login?end

判断用户是否已存在

User.exist? username
查看全文
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论