I am developing a web app on Ruby on Rails and an Android app. They have the same database structure, and now I want to sync the information between both apps. For this I am building a REST API on the rails app.
In the rails app I have devise for authenticating, but for the api I was trying to use doorkeeper which is a oauth2 provider, the problem is that I want to download all the users from the rails app to android app, and I want to give them the possibility to login in an offline mode, they can generate data in the offline mode, and after that, when they get online they will have to sync all the information with the web app. They also can generate data on the web app, so it has to be for both sides, to download information from the web app and to upload information to the web app. How can I achieve this? I have been reading a lot but I haven't found anything similar. I would really appreciate some help.
Sounds like you want to use a SyncAdapter (http://developer.android.com/training/sync-adapters/creating-sync-adapter.html). It supports background downloading/uploading and you can use that for your syncing process.
Related
I'm a 3rd year BSIT student who wants to pursue a career of Web Development in the near future. We decided for our thesis to make a Web App about a certain topic using Ruby on Rails since it's the tool that we used during our WebDev class. I've had several experiences and accomplished projects using RoR thanks to the help of this site.
Our Adviser suddenly suggested us to make an Android version of the app for the customer's side to utilize it's portability. what we would like to happen is the Customers can input and retrieve data through that android app from a database, on the other hand, the admin can also do the same using a Desktop Web App utilizing also the the same database used by the customers.
Is there any other recommendations of lightweight development and database tools that can help us make the desired Web App beside Android Studio and Eclipse? Much better if it can support Rails or Ruby.
Note: Also, we're planning to include a GPS feature where you can locate certain shops using the said android app
What you are looking for is an API. You have a Rails app, now you have to expose API endpoints from your Rails App which your Android App can access and send requests to.
I don't know if you learned about APIs yet but in short, you set up new links that retrieve information from the parameters and respond using either JSON or XML. Your android app will for example have a login form:
Name = john
Password = anything
When they submit the form, you take the name and password and send it using an HTTP request from Android to your Rails App.
#stupid example but this is how the link would somehow look like
http://www.your-site.com/api/login?name=john&password=anything
Your rails app should be setup to receive request via an API controller:
class ApiController < ApplicationController
def login
#authenticate user
#respond with json
end
end
Your Android app receives a JSON response from Rails, usually a status code telling Android that the authentication was successful or failed and then you have access to your Web App using Android but nothing is secure and you will have to setup tokens for each request, etc because API's don't have sessions like a browser. But since you are talking about a school project and not a production app maybe you can ignore the security part.
Read this blog post on how to build an API:
https://labs.kollegorna.se/blog/2015/04/build-an-api-now/
Say I have a rails webapp and I want to make a mobile app version of it; how would I get information from the webapp active record database and implement it in the Android app? And how would I post information to the web server so that I be added to the database.
Let me know if I am not clear enough.
Thank you.
I am sure there are different ways to do it but it is common for mobile apps to consume apis through json.
I've built a Rails 4 web application with PostgreSQL database and hosted it on Heroku. The future plan for that database is to also be used by one Android application.
I am not completely sure how can I accomplish that. Do I need to build another REST application and host it on Heroku and somehow connect to the same database or there is another way?
How to connect with Android application to that database which is used by the web site? I know I can't connect directly.
Thank you for your guidance.
You don't need another app - just build an API for current one and then you can communicate from Android app to your web application (web app will connect to db and return data).
Have a look at Twitter API as example - you can access different resources and manage them via Twitter API
https://dev.twitter.com/docs/api/1.1
You can build something similar - create rails controllers that access your database and respond with structure you want - preferably JSON format of your models (or something custom if you need)
From Android app you can send request to your API and parse JSON responses - then process data your own way on Android app.
Don't forget about authentication between your Android app and web application - let only your Android app to use it.
I encourage you to browse internet for best practices 'How to create an API' :)
I'm really new to mobile world, so I'd like to get some opinion from experienced people.
After several days searching over the internet, I'm wondering if it's possible
integrate Appcelerator Cloud Services to a custom website made with ASP.NET, for example.
Although my mobile application, built with Titanium, it's linked to ACS, and works fine, I don't know if
it's possible to manage data stored in ACS from a custom website. To clarify, in one point there is my mobile application
talks to a webserver (ACS, for example) and other point there is a website, to manage the data stored in ACS.
What do you think, someone achieved this?
Or is it preferable to write a webserver from the scratch, store my data in somewhere, and forget about ACS?
Thank you.
Appcelerator says
Appcelerator Cloud Services (ACS) is a Mobile Backend as a Service
(MBaaS), offering a fast and easy way to build connected mobile apps.
Choose from a library of services such as push notification, status
updates, photo storage, and social integration, or create your own
custom cloud services.
Here in this page - Getting Started: Using the Javascript SDK - you can see how we can use javascript SDK which lets you access the Appcelerator Cloud Services server through some simple to use JavaScript calls. You can use this to develop web-based app.
ACS has a REST API which you can access through anything that supports xhr (which .NET does). For instance, to create a new user in ACS, you use the following link:
https://api.cloud.appcelerator.com/v1/users/create.json?key=YOUR APP APP KEY?email=john.smith#company.com&role=teacher
There are other properties you can tag onto the querystring to create a new user from a REST call. They have a complete API using REST. It's all documented. You can even send push notifications to devices from your custom website using the REST API! It's pretty cool.
http://cloud.appcelerator.com/docs/api/v1/users/create#rest
Good luck!
I am new to both Android and Rails. I built a simple Rails app to log in to post comments and leave replies to others' comments as well. I am trying to see how to build a native Android app to respond to this Rails app and have come across a question with sessions/cookie.
In order for me to build a native android app that can allow a user to log in and browse through the rails app, do I have to write a code that receives cookie from the rails app and store it in android sqlite database? Thanks
Are you trying to load a view in HTML (an embedded browser), or render a view on the device using the native controls? If you're doing the former, surely Android already handles all this for you, just like a WebView in an iPhone app does?
If you're doing the latter, you should build an API that uses something like OAuth for authentication, rather than maintaining a session cookie. This approach means that you store a pair of (revokable) OAuth credentials on the device and that you don't need to work with the user's username/password.
I'm not sure on what your end goal is here.