Method: Urbanairship::Devices::OpenChannel#create

Defined in:
lib/urbanairship/devices/open_channel.rb

#createObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/urbanairship/devices/open_channel.rb', line 29

def create()
  fail TypeError, 'address must be set to create open channel' unless address.is_a? String
  fail TypeError, 'open_platform must be set to create open channel' unless open_platform.is_a? String
  fail TypeError, 'opt_in must be boolean' unless [true, false].include? opt_in

  channel_data = {
    'type': 'open',
    'open': {:open_platform_name => open_platform},
    'opt_in': opt_in,
    'address': address,
    'tags': tags
  }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs

  set_identifiers

  body = {'channel': channel_data}

  response = @client.send_request(
    method: 'POST',
    path: open_channel_path,
    body: JSON.dump(body),
    content_type: 'application/json'
  )
  logger.info("Registering open channel with address: #{address}")
  response
end