Class: Parse::Push

Inherits:
Object
  • Object
show all
Defined in:
lib/parse/push.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, channel = '', client = nil) ⇒ Push

Returns a new instance of Push.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/parse/push.rb', line 18

def initialize(data, channel = '', client = nil)
  @data = data

  # NOTE: if no channel is specified, by setting "where" to an empty clause
  # a push is sent to all clients.
  if !channel || channel.empty?
    @where = {}
  else
    @channels = [channel]
  end

  @client = client || Parse.client
end

Instance Attribute Details

#channelsObject

Returns the value of attribute channels.



9
10
11
# File 'lib/parse/push.rb', line 9

def channels
  @channels
end

#clientObject

Returns the value of attribute client.



16
17
18
# File 'lib/parse/push.rb', line 16

def client
  @client
end

#dataObject

Returns the value of attribute data.



15
16
17
# File 'lib/parse/push.rb', line 15

def data
  @data
end

#expiration_timeObject

Returns the value of attribute expiration_time.



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

def expiration_time
  @expiration_time
end

#expiration_time_intervalObject

Returns the value of attribute expiration_time_interval.



12
13
14
# File 'lib/parse/push.rb', line 12

def expiration_time_interval
  @expiration_time_interval
end

#push_timeObject

Returns the value of attribute push_time.



14
15
16
# File 'lib/parse/push.rb', line 14

def push_time
  @push_time
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#whereObject

Returns the value of attribute where.



10
11
12
# File 'lib/parse/push.rb', line 10

def where
  @where
end

Instance Method Details

#saveObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/parse/push.rb', line 32

def save
  body = { data: @data }

  if @type
    if @where
      @where[:deviceType] = @type
    else
      body[:deviceType] = @type
    end
  end

  # NOTE: Parse does not support channels and where at the same time
  # so we make channels part of the query conditions
  if @channels
    if @where
      @where[:channels] = { '$in' => @channels }
    else
      body[:channels] = @channels
    end
  end

  body[:where] = @where if @where

  body[:expiration_interval] = @expiration_time_interval if @expiration_time_interval
  body[:expiration_time] = @expiration_time if @expiration_time
  body[:push_time] = @push_time if @push_time

  @client.request Protocol.push_uri, :post, body.to_json
end