I have a Rails app from which I want to connect to Firebase and communicate with Rails. Basically I'll have the Rails app monitor Firebase for any changes and dynamically CRUD those changes in my views. I did a fair bit of searching but there's seems to be a lack of community resources on how to achieve this. What would be the best way to do this?
The solution I found was to use firebase-rails gem, it's description reads as follows:
Ruby wrapper for the Firebase REST API.
Changes are sent to all subscribed clients automatically, so you can update your clients in realtime from the backend.
Related
I'm trying to create an application that needs to use a backend. That backend will be used to sync an app created (initially) for iOS, macOS, watchOS. Hope to expand after.
Firebase looks like a nice tool to do that, but it only has so many SDK's. I'd like to unify the codebase as much as possible to utilize code reuse.
Seems like their REST API is the way to go: I just create a framework using REST and we're off: https://firebase.google.com/docs/database/rest/start
However, their authentication doesn't seem to support REST.
How do I get around this limitation? What should I do to get a valid auth token that Firebase will understand?
Please keep in mind that I'm not very experienced with web stuff and even after reading a lot of articles, I'm still confused about how to exactly approach this. For example, this user had a similar concern, but I'm not exactly understanding the answer.
Firebase now officially supports REST API:
https://firebase.google.com/docs/reference/rest/auth/
You can query the Firebase Auth backend through a REST API. This can be used for various operations such as creating new users, signing in existing ones and editing or deleting these users.
I am developing a Rails application that will be exposed by API only. The application has a real time chat system which involves users submitting data to the server (via API calls), but what I want to push this data to other clients.
what is the best way to send data/message to other client?
Even knowing that your question will be closed, because at least you need to put some code (what you have now) I recently came across a blog post that will guide you in the right direction.
What you need is the new Rails 5 (still in beta) and the new component called ActionCable. Here you have the blog post describing how to use it. Also you have the DHH ActionCable examples.
Under the wood it uses websockets for full-duplex communications, ensuring your users will get the notifications.
Since you want an API based solution, you may need more work to get it with your frontend framework.
Recently I've been looking for a solution to implement real-time updating web pages, for example, Twitter-like news feed or real-time chat. I've discovered some ways, as Pusher service, faye, and quite a lot of ruby gems, like private_pub or sync.
The problem is that this solutions don't seem to be a completely right way to follow. Pusher is rather expensive, and in fact I would not prefer to use other servie in my project. Faye seems insecure, and it is quite hard to implement security for it. Private_pub does the right thing, but last commit on github was in 2013 and in fact it is quite outdated.
All in all, ways that I have discovered do not seem to be professional-grade solutions for Rails startups. I have come up to the question whether I should completely switch to NodeJS or other technologies, or I can integrate NodeJS app inside a Rails one?
To sum up, is there such solution for Rails framework, or switch to another technologies is inevitable?
It may not help you right now, but at RailsConf last month DHH announced that Rails 5 will add support for websockets via a new library called ActionCable.
https://www.youtube.com/watch?v=oMlX9i9Icno
MessageBus might be a good fit. It's currently used in Discourse to implement live updates.
I'm also not sure what your security concerns about Faye are exactly. You should have no issues if everything is operating over HTTPS with proper CORS settings.
As for a mixed Node/Rails solution, you could push some list (e.g. post and list of those to be notified) on an update in the Rails app to a Redis instance. A Node app subscribed to Redis could then notify clients to make a request back to the Rails server for the latest updates.
I am currently have a running site. However, I need to do some task to sync some data to my friend's site.
So that, I need another app for fetching data from my running app's DB and submit data to another site using a gem call mechanize.
My problem will be:
Do I need a whole Rails app to do the job? If not, what would be the best practice in my case?
Is there any easy way for accessing my running app's DB? For now, the only thing I know is AR.
Thanks
API
What you're looking for is an API -- a way to connect to a source of data & use that data in some other application:
In computer programming, an application programming interface (API)
specifies how some software components should interact with each other
APIs are actually very simple -- you have a series of endpoints which an application can connect to, pulling data, typically as JSON objects. As noted by Rajarshi Das, these endpoints will likely be based on the RESTful resource structure
Rails
Rails, by design, is very good at providing API's:
This Railscast shows how to use the rails-api gem to create a RESTful API that your other app can connect to
I have a Heroku app with a PostgreSQL DB. Now I want to have a seperate process, possibly on a different machine, to access the DB. The suggestion on the Herkou site is actually what I wanted to do myself:
No, connecting to your database from machines outside of Heroku is not supported.
We recommend that you encapsulate data access in an API to manipulate it.
But I'm not sure how that's done best. I'd like to be able to send some JSON to the API and get back JSON as a result of that request. Like "give me all posts that are expired for a bunch of given userIds" or "update all users to be suspended if their posts contain any of the given words" in an example micropost app.
What's the best way to achieve that? Can I write an extra ruby program that is accessible via TCP and accepts JSON input? Is that even possible with Heroku? Or do I have to integrate the API into my rails app somehow? How?
Thankful for any ideas,
Tom
You will have to integrate the API to your rails app, there are many solutions for this, one of them is using a tool specialized for API building like Grape and mount it with your Rails app. This way you could have your Rails app running and also the API, both sharing the same codebase.