Class: ActionPush::Delivery::Gorush

Inherits:
Object
  • Object
show all
Defined in:
lib/action_push/delivery/gorush.rb

Overview

cli = ActionPush::Delivery::Gorush.new(url: ‘localhost:8088/api/push’, topic: ‘com.app.id’)

push = ActionPush::Ios::Message.new do |p|

p.title = 'Title'
p.thread_id = 'comments'
p.badge = 10
p.body = 'Body'
p.token = '4589***A938'

end

cli.send_to_apple(push)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) {|_self| ... } ⇒ Gorush

Returns a new instance of Gorush.

Yields:

  • (_self)

Yield Parameters:



24
25
26
27
# File 'lib/action_push/delivery/gorush.rb', line 24

def initialize(params = {})
  params.each { |key, value| public_send("#{key}=", value) }
  yield(self) if block_given?
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



21
22
23
# File 'lib/action_push/delivery/gorush.rb', line 21

def logger
  @logger
end

#topicObject

Returns the value of attribute topic.



22
23
24
# File 'lib/action_push/delivery/gorush.rb', line 22

def topic
  @topic
end

#urlObject

Returns the value of attribute url.



20
21
22
# File 'lib/action_push/delivery/gorush.rb', line 20

def url
  @url
end

Instance Method Details

#send_to_apple(push) ⇒ Net::HTTPResponse

rubocop:disable Metrics/MethodLength

Parameters:

Returns:

  • (Net::HTTPResponse)


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
61
62
63
64
65
66
67
# File 'lib/action_push/delivery/gorush.rb', line 32

def send_to_apple(push)
  alert = push.alert

  notification = {
    tokens: [push.token],
    platform: 1,
    'thread-id': push.thread_id,
    content_available: push.content_available,
    topic: topic,
    badge: push.badge,
    category: push.category,
    data: push.payload,
    alert: {
      title: alert.title,
      body: alert.body,
      'action-loc-key': alert.action_loc_key,
      'launch-image': alert.launch_image,
      'loc-args': alert.loc_args,
      'loc-key': alert.loc_key,
      'title-loc-args': alert.title_loc_args,
      'title-loc-key': alert.title_loc_key
    }
  }

  # #nil? check to be able tos specify: push.sound = false
  unless (sound = push.sound).nil?
    notification[:sound] = { name: sound }
  end

  response = post(notifications: [notification])

  push.delivery_response = response
  push.delivered = response.is_a?(Net::HTTPSuccess)

  response
end