Class: Urbanairship::Devices::ChannelTags
- Inherits:
-
Object
- Object
- Urbanairship::Devices::ChannelTags
- Defined in:
- lib/urbanairship/devices/channel_tags.rb
Direct Known Subclasses
Constant Summary
Constants included from Common
Instance Attribute Summary collapse
-
#add_group ⇒ Object
readonly
Returns the value of attribute add_group.
-
#audience ⇒ Object
readonly
Returns the value of attribute audience.
-
#client ⇒ Object
writeonly
Sets the attribute client.
-
#remove_group ⇒ Object
readonly
Returns the value of attribute remove_group.
-
#set_group ⇒ Object
readonly
Returns the value of attribute set_group.
Instance Method Summary collapse
- #add(group_name: required('group_name'), tags: required('tags')) ⇒ Object
-
#initialize(client: required('client')) ⇒ ChannelTags
constructor
A new instance of ChannelTags.
- #remove(group_name: required('group_name'), tags: required('tags')) ⇒ Object
- #send_request ⇒ Object
- #set(group_name: required('group_name'), tags: required('tags')) ⇒ Object
- #set_audience(ios: nil, android: nil, amazon: nil) ⇒ Object
Methods included from Loggable
create_logger, logger, #logger
Methods included from Common
#apid_path, #channel_path, #compact_helper, #create_and_send_path, #custom_events_path, #device_token_path, #experiments_path, #lists_path, #named_users_path, #open_channel_path, #pipelines_path, #push_path, #reports_path, #required, #schedules_path, #segments_path, #tag_lists_path, #try_helper
Constructor Details
#initialize(client: required('client')) ⇒ ChannelTags
Returns a new instance of ChannelTags.
12 13 14 15 16 17 18 19 |
# File 'lib/urbanairship/devices/channel_tags.rb', line 12 def initialize(client: required('client')) @client = client @audience = {} @add_group = {} @remove_group = {} @set_group = {} @path = channel_path('tags/') end |
Instance Attribute Details
#add_group ⇒ Object (readonly)
Returns the value of attribute add_group.
10 11 12 |
# File 'lib/urbanairship/devices/channel_tags.rb', line 10 def add_group @add_group end |
#audience ⇒ Object (readonly)
Returns the value of attribute audience.
10 11 12 |
# File 'lib/urbanairship/devices/channel_tags.rb', line 10 def audience @audience end |
#client=(value) ⇒ Object (writeonly)
Sets the attribute client
9 10 11 |
# File 'lib/urbanairship/devices/channel_tags.rb', line 9 def client=(value) @client = value end |
#remove_group ⇒ Object (readonly)
Returns the value of attribute remove_group.
10 11 12 |
# File 'lib/urbanairship/devices/channel_tags.rb', line 10 def remove_group @remove_group end |
#set_group ⇒ Object (readonly)
Returns the value of attribute set_group.
10 11 12 |
# File 'lib/urbanairship/devices/channel_tags.rb', line 10 def set_group @set_group end |
Instance Method Details
#add(group_name: required('group_name'), tags: required('tags')) ⇒ Object
33 34 35 |
# File 'lib/urbanairship/devices/channel_tags.rb', line 33 def add(group_name: required('group_name'), tags: required('tags')) @add_group[group_name] = end |
#remove(group_name: required('group_name'), tags: required('tags')) ⇒ Object
37 38 39 |
# File 'lib/urbanairship/devices/channel_tags.rb', line 37 def remove(group_name: required('group_name'), tags: required('tags')) @remove_group[group_name] = end |
#send_request ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/urbanairship/devices/channel_tags.rb', line 45 def send_request payload = {} fail ArgumentError, 'An audience is required for modifying tags' if @audience.empty? fail ArgumentError, 'A tag request cannot both add and set tags' if !@add_group.empty? and !@set_group.empty? fail ArgumentError, 'A tag request cannot both remove and set tags' if !@remove_group.empty? and !@set_group.empty? fail ArgumentError, 'A tag request must add, remove, or set a tag' if @remove_group.empty? and @add_group.empty? and @set_group.empty? payload['audience'] = @audience payload['add'] = @add_group unless @add_group.empty? payload['remove'] = @remove_group unless @remove_group.empty? payload['set'] = @set_group unless @set_group.empty? response = @client.send_request( method: 'POST', body: JSON.dump(payload), path: @path, content_type: 'application/json' ) logger.info("Set tags for audience: #{@audience}") response end |
#set(group_name: required('group_name'), tags: required('tags')) ⇒ Object
41 42 43 |
# File 'lib/urbanairship/devices/channel_tags.rb', line 41 def set(group_name: required('group_name'), tags: required('tags')) @set_group[group_name] = end |
#set_audience(ios: nil, android: nil, amazon: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/urbanairship/devices/channel_tags.rb', line 21 def set_audience(ios: nil, android: nil, amazon: nil) if ios @audience['ios_channel'] = ios end if android @audience['android_channel'] = android end if amazon @audience['amazon_channel'] = amazon end end |