我可以用什么来让Android应用程序与一个Rails应用程序进行通信

编程入门 行业动态 更新时间:2024-10-27 05:27:12
本文介绍了我可以用什么来让Android应用程序与一个Rails应用程序进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图创建一个应用程序,基本上可以让Android设备上的用户发送即时出现在Rails应用程序的消息。有没有人有建议,我会用什么来做到这一点?

I'm trying to create an application that basically lets a user on an android device send a message that instantly appears in the rails application. Does anyone have suggestions to what I would use to do this?

推荐答案

下面是一个快速演练。

让我们创建一个新的Rails应用程序

Let's create a new rails app

$ rails new simple-message $ cd simple-message/

我们现在要创建一个名为消息的REST风格的资源,将管理信息从你的手机来了。

We are now going to create a RESTful resource called Message, that will manage the messages coming from your mobiles.

$ rails generate scaffold Message title:string content:text

创建该表将包含消息:

Create the table that will contain the messages:

$ rake db:migrate

启动boundled服务器和浏览器指向 0.0.0.0:3000/messages

从那里你可以的手动的创建新的消息,这将显示为一个列表。

From there you can manually create new messages, that will show up as a list.

对于每一个页面,您可以使用浏览器浏览有一个允许其他客户端编程调用相应的视图。

For every page you can navigate with your browser there is a corresponding view that accepts programmatic calls from other clients.

如果您浏览 0.0.0.0:3000/messages.xml 你会得到一个包含所有的XML你的消息。随着卷曲:

If you browse 0.0.0.0:3000/messages.xml you will get an xml containing all you messages. With curl:

$ curl localhost:3000/messages.xml <?xml version="1.0" encoding="UTF-8"?> <messages type="array"> <message> <created-at type="datetime">2010-11-27T18:24:36Z</created-at> <title>Just a message</title> <updated-at type="datetime">2010-11-27T18:24:36Z</updated-at> <id type="integer">1</id> <content>With some content</content> </message> </messages>

它的时候添加新的消息:

Its time to add a new message:

$ curl -X POST -H 'Content-type: text/xml' -d '<message><title>Hello</title><content>How are you</content></message>' 0.0.0.0:3000/messages.xml <?xml version="1.0" encoding="UTF-8"?> <message> <created-at type="datetime">2010-11-27T18:40:44Z</created-at> <title>Hello</title> <updated-at type="datetime">2010-11-27T18:40:44Z</updated-at> <id type="integer">2</id> <content>How are you</content> </message>

您的Andr​​oid客户端将充当卷曲增加新的消息。

Your Android client will have to act as curl to add new messages.

现在,你需要一些认证,只允许特定的用户作为管理员,并restric使用您的API。在挖掘,以实现Rails的认证多种方式:

Now you need some authentication to allow only certain user to act as an admin and to restric the use of your API. Before digging for the various way to implement authentication in Rails:

  • 要发布的消息之前,您的用户进行身份验证?
  • 应在Web应用程序接受来自其他服务(如微博,Facebook,谷歌,OAuth的,OpenID的...),或者对你自己的用户数据库验证?
  • 是你的API开放给其他的客户端,或只是你的Andr​​oid客户端可以发帖?
  • 你需要知道的 的公布消息(即用户登录)?
  • 你想阻止单个用户或应用程序发布消息到您的Web应用程序?

您可以找到不同策略的一个很好的回顾here.

You can find a nice recap of different strategies here.

更多推荐

我可以用什么来让Android应用程序与一个Rails应用程序进行通信

本文发布于:2023-11-16 02:41:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1600268.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   可以用   通信   Android   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!