Class: Urbanairship::Devices::NamedUser

Inherits:
Object
  • Object
show all
Includes:
Common, Loggable
Defined in:
lib/urbanairship/devices/named_user.rb

Constant Summary

Constants included from Common

Common::CONTENT_TYPE

Instance Attribute Summary collapse

Instance Method Summary collapse

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')) ⇒ NamedUser

Returns a new instance of NamedUser.



10
11
12
13
# File 'lib/urbanairship/devices/named_user.rb', line 10

def initialize(client: required('client'))
  @client = client
  @named_user_id =  nil
end

Instance Attribute Details

#named_user_idObject

Returns the value of attribute named_user_id.



8
9
10
# File 'lib/urbanairship/devices/named_user.rb', line 8

def named_user_id
  @named_user_id
end

Instance Method Details

#associate(channel_id: required('channel_id'), device_type: nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/urbanairship/devices/named_user.rb', line 26

def associate(channel_id: required('channel_id'), device_type: nil)
  fail ArgumentError,
       'named_user_id is required for association' if @named_user_id.nil?

  payload = {}
  payload['channel_id'] = channel_id
  payload['device_type'] = device_type unless device_type.nil?
  payload['named_user_id'] = @named_user_id.to_s

  response = @client.send_request(
    method: 'POST',
    body: JSON.dump(payload),
    path: named_users_path('associate'),
    content_type: CONTENT_TYPE
  )
  logger.info { "Associated channel_id #{channel_id} with named_user #{@named_user_id}" }
  response
end

#disassociate(channel_id: required('channel_id'), device_type: nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/urbanairship/devices/named_user.rb', line 45

def disassociate(channel_id: required('channel_id'), device_type: nil)
  payload = {}
  payload['channel_id'] = channel_id
  payload['device_type'] = device_type unless device_type.nil?
  payload['named_user_id'] = @named_user_id unless @named_user_id.nil?
  response = @client.send_request(
    method: 'POST',
    body: JSON.dump(payload),
    path: named_users_path('disassociate'),
    content_type: CONTENT_TYPE
  )
  logger.info { "Dissociated channel_id #{channel_id}" }
  response
end

#lookupObject



60
61
62
63
64
65
66
67
68
69
# File 'lib/urbanairship/devices/named_user.rb', line 60

def lookup
  fail ArgumentError,
     'named_user_id is required for lookup' if @named_user_id.nil?
  response = @client.send_request(
    method: 'GET',
    path: named_users_path('?id=' + @named_user_id),
  )
  logger.info { "Retrieved information on named_user_id #{@named_user_id}" }
  response
end

#update_attributes(attributes: required('attributes')) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/urbanairship/devices/named_user.rb', line 15

def update_attributes(attributes: required('attributes'))
  response = @client.send_request(
    method: 'POST',
    body: Urbanairship::Attributes.new(attributes).payload.to_json,
    path: named_users_path("#{@named_user_id}/attributes"),
    content_type: CONTENT_TYPE,
  )
  logger.info { "Updated attributes for named_user #{@named_user_id}" }
  response
end