Pushing to 'ios' channel gives "Parse::ParseProtocolError: 115: Can't set channels for a query-targeted push."
jasonschock opened this issue · comments
Just attempting a simple push via Parse. This is almost straight from the README.
Gemfile:
gem 'parse-ruby-client', git: 'git://github.com/adelevie/parse-ruby-client.git'
Commit SHA is cac0493
.
This returns an error:
parse = Parse.create(
application_id: ENV['parse_application_id'],
api_key: ENV['parse_api_key'],
quiet: false)
push = parse.push({alert: 'Hello.'}, 'user_e3929e0df56e163acc3072df2b2748')
push.type='ios'
push.save
Response:
I, [2015-06-17T13:47:18.870459 #9008] INFO -- : post https://api.parse.com/1/push
I, [2015-06-17T13:47:19.329457 #9008] INFO -- Status: 400
Parse::ParseProtocolError: 115: Can't set channels for a query-targeted push.
from /opt/boxen/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/parse-ruby-client-cac04938900c/lib/faraday/extended_parse_json.rb:25:in `process_response'
This works fine:
push = parse.push({alert: 'Hello.'}, 'user_e3929e0df56e163acc3072df2b2748')
# Don't set the type
push.save
Response:
I, [2015-06-17T13:53:29.577909 #9008] INFO -- : post https://api.parse.com/1/push
I, [2015-06-17T13:53:30.024296 #9008] INFO -- Status: 200
=> {"result"=>true}
Sorry, but what am I missing, or this a bug?
@jasonschock that's because you can't set the channel and the device type at the same time. See https://parse.com/questions/cant-set-channels-for-a-query-targeted-push - According to Parse you can either set a channel with the second argument as you did or set the device type (which act as a filter). If you want to set a channel AND the device type you have to use two strategies as the current library API goes:
1 - set push.channels instead of push.channel (it's confusing I know)
push = parse.push({alert: 'Hello.'})
push.channels = ['user_e3929e0df56e163acc3072df2b2748']
push.where = {deviceType: 'ios'}
Though I think like this it will send the push only to the devices that have only that channels set and not the devices that have that channels and optionally others.
2 - use the where all the way (my suggestion)
push = parse.push({alert: 'Hello.'})
push.where = {deviceType: 'ios', channels: { '$in': ['user_e3929e0df56e163acc3072df2b2748']}
push.save
@Xavdidtheshadow I think the mechanism @channel
/ @channels
needs some love and this seems a bug to me https://github.com/adelevie/parse-ruby-client/blob/master/lib/parse/push.rb#L46 (the where clause doesn't need a where key, just the conditions)