Class: Parse::Push
- Inherits:
- Object
- Object
- Parse::Push
- Includes:
- Client::Connectable
- Defined in:
- lib/parse/model/push.rb
Overview
This class represents the API to send push notification to devices that are available in the Installation table. Push notifications are implemented through the `Parse::Push` class. To send push notifications through the REST API, you must enable `REST push enabled?` option in the `Push Notification Settings` section of the `Settings` page in your Parse application. Push notifications targeting uses the Installation Parse class to determine which devices receive the notification. You can provide any query constraint, similar to using `Parse::Query`, in order to target the specific set of devices you want given the columns you have configured in your `Installation` class. The `Parse::Push` class supports many other options not listed here.
Instance Attribute Summary collapse
- #alert ⇒ String (also: #message)
- #badge ⇒ Integer
- #channels ⇒ Array
An array of strings for subscribed channels.
- #data ⇒ Hash
Specific payload data.
- #expiration_interval ⇒ Integer
- #expiration_time ⇒ Parse::Date
- #push_time ⇒ Parse::Date
- #query ⇒ Object
Returns the value of attribute query.
- #sound ⇒ String
The name of the sound file.
- #title ⇒ String
Class Method Summary collapse
- .send(payload) ⇒ Object
Send a push notification using a push notification hash.
Instance Method Summary collapse
- #as_json(*args) ⇒ Hash
A JSON encoded hash.
- #initialize(constraints = {}) ⇒ Push constructor
Initialize a new push notification request.
- #payload ⇒ Hash
This method takes all the parameters of the instance and creates a proper hash structure, required by Parse, in order to process the push notification.
- #send(message = nil) ⇒ Object
helper method to send a message.
- #to_json(*args) ⇒ String
A JSON encoded string.
- #where(constraints = nil) ⇒ Hash, Parse::Query
Apply a set of constraints.
- #where=(where_clausees) ⇒ Parse::Query
Set a hash of conditions for this push query.
Methods included from Client::Connectable
Constructor Details
#initialize(constraints = {}) ⇒ Push
Initialize a new push notification request.
85 86 87 | # File 'lib/parse/model/push.rb', line 85 def initialize(constraints = {}) self.where constraints end |
Instance Attribute Details
#alert ⇒ String Also known as: message
71 72 | # File 'lib/parse/model/push.rb', line 71 attr_accessor :query, :alert, :badge, :sound, :title, :data, :expiration_time, :expiration_interval, :push_time, :channels |
#badge ⇒ Integer
71 72 | # File 'lib/parse/model/push.rb', line 71 attr_accessor :query, :alert, :badge, :sound, :title, :data, :expiration_time, :expiration_interval, :push_time, :channels |
#channels ⇒ Array
Returns an array of strings for subscribed channels.
71 72 | # File 'lib/parse/model/push.rb', line 71 attr_accessor :query, :alert, :badge, :sound, :title, :data, :expiration_time, :expiration_interval, :push_time, :channels |
#data ⇒ Hash
Returns specific payload data.
71 72 | # File 'lib/parse/model/push.rb', line 71 attr_accessor :query, :alert, :badge, :sound, :title, :data, :expiration_time, :expiration_interval, :push_time, :channels |
#expiration_interval ⇒ Integer
71 72 | # File 'lib/parse/model/push.rb', line 71 attr_accessor :query, :alert, :badge, :sound, :title, :data, :expiration_time, :expiration_interval, :push_time, :channels |
#expiration_time ⇒ Parse::Date
71 72 | # File 'lib/parse/model/push.rb', line 71 attr_accessor :query, :alert, :badge, :sound, :title, :data, :expiration_time, :expiration_interval, :push_time, :channels |
#push_time ⇒ Parse::Date
71 72 | # File 'lib/parse/model/push.rb', line 71 attr_accessor :query, :alert, :badge, :sound, :title, :data, :expiration_time, :expiration_interval, :push_time, :channels |
#sound ⇒ String
Returns the name of the sound file.
71 72 | # File 'lib/parse/model/push.rb', line 71 attr_accessor :query, :alert, :badge, :sound, :title, :data, :expiration_time, :expiration_interval, :push_time, :channels |
#title ⇒ String
71 72 | # File 'lib/parse/model/push.rb', line 71 attr_accessor :query, :alert, :badge, :sound, :title, :data, :expiration_time, :expiration_interval, :push_time, :channels |
Class Method Details
.send(payload) ⇒ Object
Send a push notification using a push notification hash
79 80 81 | # File 'lib/parse/model/push.rb', line 79 def self.send(payload) client.push payload.as_json end |
Instance Method Details
#as_json(*args) ⇒ Hash
Returns a JSON encoded hash.
122 123 124 | # File 'lib/parse/model/push.rb', line 122 def as_json(*args) payload.as_json end |
#payload ⇒ Hash
This method takes all the parameters of the instance and creates a proper hash structure, required by Parse, in order to process the push notification.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | # File 'lib/parse/model/push.rb', line 134 def payload msg = { data: { alert: alert, badge: badge || "Increment", }, } msg[:data][:sound] = sound if sound.present? msg[:data][:title] = title if title.present? msg[:data].merge! @data if @data.is_a?(Hash) if @expiration_time.present? msg[:expiration_time] = @expiration_time.respond_to?(:iso8601) ? @expiration_time.iso8601(3) : @expiration_time end if @push_time.present? msg[:push_time] = @push_time.respond_to?(:iso8601) ? @push_time.iso8601(3) : @push_time end if @expiration_interval.is_a?(Numeric) msg[:expiration_interval] = @expiration_interval.to_i end if query.where.present? q = @query.dup if @channels.is_a?(Array) && @channels.empty? == false q.where :channels.in => @channels end msg[:where] = q.compile_where unless q.where.empty? elsif @channels.is_a?(Array) && @channels.empty? == false msg[:channels] = @channels end msg end |
#send(message = nil) ⇒ Object
helper method to send a message
170 171 172 173 174 | # File 'lib/parse/model/push.rb', line 170 def send( = nil) @alert = if .is_a?(String) @data = if .is_a?(Hash) client.push(payload.as_json) end |
#to_json(*args) ⇒ String
Returns a JSON encoded string.
127 128 129 | # File 'lib/parse/model/push.rb', line 127 def to_json(*args) as_json.to_json end |
#where(constraints = nil) ⇒ Hash, Parse::Query
Apply a set of constraints.
103 104 105 106 107 | # File 'lib/parse/model/push.rb', line 103 def where(constraints = nil) return query.compile_where unless constraints.is_a?(Hash) query.where constraints query end |
#where=(where_clausees) ⇒ Parse::Query
Set a hash of conditions for this push query.
95 96 97 | # File 'lib/parse/model/push.rb', line 95 def where=(where_clausees) query.where where_clauses end |