class RssNotifier::Adapter::Pushbullet

Attributes

access_token[R]
name[R]

Public Class Methods

new(name, access_token) click to toggle source
# File lib/rss_notifier/adapter/pushbullet.rb, line 11
def initialize(name, access_token)
  @name = name
  @access_token = access_token
end

Public Instance Methods

notify(item) click to toggle source
# File lib/rss_notifier/adapter/pushbullet.rb, line 16
def notify(item)
  body = JSON.dump({
    'type' => 'link',
    'title' => "#{item.feed.name}",
    'body' => item.title,
    'url' => item.link
  })

  RssNotifier.logger.debug("Adapter::Pushbullet #{name}, #{body}")

  response = HTTP.timeout(:per_operation, write: 5, connect: 7, read: 5)
    .headers(
      'Access-Token' => access_token,
      'Content-Type' => 'application/json'
    )
    .post('https://api.pushbullet.com/v2/pushes', body: body)

  if response.code != 200
    RssNotifier.logger.warn("Could not notify #{self}. Code=#{response.code}")
    false
  else
    RssNotifier.logger.debug("#{self} notified")
    true
  end
end
to_s() click to toggle source
# File lib/rss_notifier/adapter/pushbullet.rb, line 42
def to_s
  "<Adapter::Pushbullet #{name}>"
end