adelevie / parse-ruby-client

A simple Ruby client for the parse.com REST API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Push not working

skmvasu opened this issue · comments

Hey,

I'm trying to integrate Parse inside my rails app to automatically delilver push notifications to the users.

I am evaluating this gem to see if this can simplify my job. So far I've not been able to get it to work. I followed the guide in the Readme.

require 'parse-ruby-client'

Parse.init :application_id => "<your_app_id>",
           :api_key        => "<your_api_key>"
data = {:alert=>"Test push notification - Vasu", :bookid=>"52d0263869702d0905990000"}
push = Parse::Push.new data
push.type = "ios"
push.save

I'm getting a success response, but the push is not delivered to my devise.

I, [2014-09-02T20:13:30.591722 #12864] INFO -- : post https://api.parse.com/1/push
I, [2014-09-02T20:13:32.273484 #12864] INFO -- Status: 200
=> {"result"=>true}

However, I'm able to get it working with a simple CURL request,

curl -X POST \
-H "X-Parse-Application-Id: 'app_id' "
-H "X-Parse-REST-API-Key: 'rest_key' "
-H "Content-Type: application/json"
-d '{
"data":{
"alert": "Hey jag check the notification",
"bookid": "52d0263869702d0905990000"
},"where":{"deviceType":"ios"}
}'
https://api.parse.com/1/push

This successfully delivers the notification. I'm not sure what's the issue here. I went through the push.rb code, and noticed that it defaults the channels to "", so I'm guessing that's not the issue. Please help me with this.

Hey, did some one get a chance to take a look at this? I'm really stuck with this issue and any help would be highly appreciated.

"" (empty) channel is a Broadcast channel. So you should add channel to your installations. By default there is no channel for your installations. I guess it's the reason you doesn't receive push notifications.

iOS/Android SDK can subscribe installation to the channels. So you be able to subscribe your installations from SDKs.

Hey, Sorry about the delay in my response. I'm not sure that I understand. I'm not using the Channel parameter with my curl request either, and that works like a breeze. I don't see why it would cause any issue here.

Parse::Push using "" (broadcast) channel by default https://github.com/adelevie/parse-ruby-client/blob/master/lib/parse/push.rb#L16

You are be able to check generated request from Notification page at Parse.com

The same is happening here.
Testing cURL POSTs without channels as bellow, returns success and delivers a notification on my iPhone.

curl -X POST \
  -H "X-Parse-Application-Id: app_id" \
  -H "X-Parse-REST-API-Key: rest_key" \
  -H "Content-Type: application/json" \
  -d '{
        "data": {
          "alert": "My message!"
        },
        "where": {
          "deviceType": "ios" 
        }
      }' \
  https://api.parse.com/1/push

This push is showing "target: everyone" at Parse Push Inspector.

I guess I don't need channels. How can I do that?

By setting where to an empty object a push is sent to all clients.

data = { :alert => "This is a notification from Parse" }
push = Parse::Push.new(data)
push.where = {}
push.save

@koenpunt it works like a charm! Thanks a lot! 👍

I've made a PR for this issue you can check it here.
When a Push is created without any channel, it will be automatically sent to all devices (if no others constraints are set).