class ActionPush::Delivery::Gorush
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)
Attributes
logger[RW]
topic[RW]
url[RW]
Public Class Methods
new(params = {}) { |self| ... }
click to toggle source
# 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
Public Instance Methods
send_to_apple(push)
click to toggle source
@param [Ios::Message] @return [Net::HTTPResponse] rubocop:disable Metrics/MethodLength
# 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
Private Instance Methods
post(json = {})
click to toggle source
# File lib/action_push/delivery/gorush.rb, line 76 def post(json = {}) req = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json') req.body = json.to_json transport.start do |h| h.request(req) end end
transport()
click to toggle source
# File lib/action_push/delivery/gorush.rb, line 84 def transport @transport ||= begin http = Net::HTTP.new(uri.host, uri.port) http.set_debug_output(logger) if logger http end end
uri()
click to toggle source
rubocop:enable Metrics/MethodLength
# File lib/action_push/delivery/gorush.rb, line 72 def uri @uri ||= URI(url) end