Question

I'm using pusher gem to manipulate my front-end from an external API. It works fine, no problem with that.

But the thing I wonder is if there is a possibility to use push notifications at the back-end of my application? I spent a serious amount of time investigating this but couldn't find something useful.

Let me summarize:

I have an application and another API application which is tightly interacting with other. Sometimes I want to use my API to send notification to my main application and I want to be able to manipulate data at the back-end of my main application regarding the data received from API side. These are things like 'an action was completed/started/succeed' etc...

I understand that 'pusher' receives push notifications by JavaScript at the front-end. But I believe that there must be a way to use those notifications at the back-end as well.

If there is another way (maybe Faye? Websocket) to do that I'd love to learn what it is. Any clue would be appreciated.

Is it something doable?

Thank you

Was it helpful?

Solution 2

I had asked the same question to the Pusher's support team and I got the exact answer I was looking for.

You can install a client library on your server (http://pusher.com/docs/client_libraries) if there is one for your server. You can then subscribe to a client channel this way.

In my case, I use Ruby gem which can be reached from https://github.com/pusher/pusher-ruby-client .

OTHER TIPS

Pusher is a backend system too (to "push" updates to channels)


Endpoints

I think you may be interested in endpoints

From what I can gather, it seems you're looking to trigger the transfer of data to an endpoint once an action occurs in your API? For example:

  • User signs up on "API" app
  • API app sends "notification" to main app
  • Main app increases user count by 1

The way I can see this working is by either using ajax, or sending a curl request to your main app's endpoint (set in routes), triggering the action:

#main_app/config/routes.rb
post "endpoint", to: "application#endpoint"

#main_app/controllers/application_controller.rb
def endpoint
    @count = Option.increment!(:user_count)
end

This will allow you to manipulate your data in the backend of your "main" app


API

The tricky, non-conventional part comes when you want to send the data from your API app to your Main app (this is where you got the "pusher" idea from)

I would personally look at sending a standard HTTP request to the Main app endpoint, probably with Curl (if from the backend):

You may want to install curb (CUrl RuBy) here: https://github.com/taf2/curb

I could write some code if you wanted?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top