urbanairship / ruby-library

A Ruby wrapper for the Urban Airship API.
Other
200 stars 117 forks source link

Can't send push notifications to an audience based on tags #89

Closed dawner closed 8 years ago

dawner commented 8 years ago

There appears to be no support for specifying a group in the audience when sending a push notification, although it is allowed in the UrbanAirship API here.

tag A tag is an arbitrary bit of metadata used to group different devices together. A tag specifier may or may not have an associated group declaration, which specifies what tag group the tag belongs to. If no tag group is specified, the default "device" group is used.

This is an issue because setting up ChannelTags and NamedUserTags now requires a group_name to be passed in, which is making it impossible to send push notifications based on a tag.

My set up is as follows:

require 'urbanairship'
UA = Urbanairship

def client
  UA::Client.new(key: ENV['UA_APPLICATION_KEY'], secret: ENV['UA_MASTER_SECRET'])
end

def register_tags(named_user_id)
  named_user_tags = UA::NamedUserTags.new(client: client)
  named_user_tags.set_audience(user_ids: [named_user_id])
  named_user_tags.add(group_name: 'custom-group-name', tags: ['tag1', 'tag2'])
  named_user_tags.send_request
end

def send_push_notification(tag_name, message)
  push = client.create_push
  push.audience = UA.tag(tag_name)
  push.notification = UA.notification(alert: message)
  push.device_types = UA.all
  push.send_push
end

Executing it with the following, returns 200 successfully but sends no push notification, as it is defaulting to the device group_name. I would expect instead to be able to specify the group_name associated with the tag somehow.

register_tags('user-1')
send_push_notification('tag1', 'Hello World')
jkvoorhis commented 8 years ago

@dawner Thank you for finding this bug. If you haven't already could you please fill out and submit a contributors agreement, found here https://github.com/urbanairship/ruby-library#contributing. Once that is received we will be able to bring in your changes.

jkvoorhis commented 8 years ago

Merging your PR and performing a release, should be out by EOD today.