Class: Maia::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/maia/message.rb

Direct Known Subclasses

DryRun, Poke

Instance Method Summary collapse

Instance Method Details

#badgeObject



34
35
# File 'lib/maia/message.rb', line 34

def badge
end

#bodyObject



21
22
# File 'lib/maia/message.rb', line 21

def body
end

#colorObject



37
38
# File 'lib/maia/message.rb', line 37

def color
end

#content_available?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/maia/message.rb', line 47

def content_available?
  false
end

#content_mutable?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/maia/message.rb', line 51

def content_mutable?
  false
end

#dataObject



40
41
# File 'lib/maia/message.rb', line 40

def data
end

#dry_run?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/maia/message.rb', line 55

def dry_run?
  false
end

#enqueue(worker, devices) ⇒ Object



12
13
14
15
16
# File 'lib/maia/message.rb', line 12

def enqueue(worker, devices)
  devices.in_batches(of: Maia::BATCH_SIZE) do |devices|
    worker.perform_later devices.pluck(:token), to_h.deep_stringify_keys
  end
end

#iconObject



27
28
# File 'lib/maia/message.rb', line 27

def icon
end

#notificationObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/maia/message.rb', line 59

def notification
  {
    title: title,
    body: body,
    icon: icon,
    sound: sound.to_s,
    badge: badge,
    color: color,
    click_action: on_click
  }.compact
end

#on_clickObject



24
25
# File 'lib/maia/message.rb', line 24

def on_click
end

#priorityObject



43
44
45
# File 'lib/maia/message.rb', line 43

def priority
  :normal
end

#send_to(pushable, job_options = {}) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/maia/message.rb', line 3

def send_to(pushable, job_options = {})
  devices = Device.owned_by pushable
  worker  = Messenger.set job_options

  enqueue worker, devices.android
  enqueue worker, devices.ios
  enqueue worker, devices.unknown
end

#soundObject



30
31
32
# File 'lib/maia/message.rb', line 30

def sound
  :default
end

#titleObject



18
19
# File 'lib/maia/message.rb', line 18

def title
end

#to_hObject



71
72
73
74
75
76
77
78
79
80
# File 'lib/maia/message.rb', line 71

def to_h
  {
    priority: priority.to_s,
    dry_run: dry_run?,
    content_available: content_available?,
    mutable_content: content_mutable?,
    data: data,
    notification: notification
  }.compact
end