Class: Urbanairship::Push::Push

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

Overview

A Push Notification.

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) ⇒ Push

Initialize a Push Object

Parameters:

  • client (Object)


28
29
30
# File 'lib/urbanairship/push/push.rb', line 28

def initialize(client)
  @client = client
end

Instance Attribute Details

#audienceObject

Returns the value of attribute audience.



13
14
15
# File 'lib/urbanairship/push/push.rb', line 13

def audience
  @audience
end

#campaignsObject

Returns the value of attribute campaigns.



13
14
15
# File 'lib/urbanairship/push/push.rb', line 13

def campaigns
  @campaigns
end

#client=(value) ⇒ Object (writeonly)

Sets the attribute client

Parameters:

  • value

    the value to set the attribute client to.



11
12
13
# File 'lib/urbanairship/push/push.rb', line 11

def client=(value)
  @client = value
end

#device_typesObject

Returns the value of attribute device_types.



13
14
15
# File 'lib/urbanairship/push/push.rb', line 13

def device_types
  @device_types
end

#in_appObject

Returns the value of attribute in_app.



13
14
15
# File 'lib/urbanairship/push/push.rb', line 13

def in_app
  @in_app
end

#localizationsObject

Returns the value of attribute localizations.



13
14
15
# File 'lib/urbanairship/push/push.rb', line 13

def localizations
  @localizations
end

#messageObject

Returns the value of attribute message.



13
14
15
# File 'lib/urbanairship/push/push.rb', line 13

def message
  @message
end

#notificationObject

Returns the value of attribute notification.



13
14
15
# File 'lib/urbanairship/push/push.rb', line 13

def notification
  @notification
end

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/urbanairship/push/push.rb', line 13

def options
  @options
end

Instance Method Details

#payloadObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/urbanairship/push/push.rb', line 32

def payload
  compact_helper({
    audience: audience,
    notification: notification,
    options: options,
    device_types: device_types,
    message: message,
    in_app: in_app,
    campaigns: campaigns,
    localizations: localizations
  })
end

#send_pushPushResponse

Send the Push Object

Returns:

  • (PushResponse)

    with ‘push_ids` and other response data.

Raises:



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/urbanairship/push/push.rb', line 51

def send_push
  response = @client.send_request(
    method: 'POST',
    body: JSON.dump(payload),
    path: push_path,
    content_type: 'application/json'
  )
  pr = PushResponse.new(http_response_body: response['body'], http_response_code: response['code'].to_s)
  logger.info { pr.format }
  pr
end