Class: Thredded::PushoverNotifier
- Inherits:
-
Object
- Object
- Thredded::PushoverNotifier
- Defined in:
- lib/thredded/pushover_notifier.rb,
lib/thredded/pushover_notifier/content_helper.rb
Defined Under Namespace
Classes: ContentHelper
Constant Summary collapse
- VERSION =
'1.0.0'
Instance Method Summary collapse
- #human_name ⇒ Object
-
#initialize(pushover_app_token, root_url) ⇒ PushoverNotifier
constructor
A new instance of PushoverNotifier.
- #key ⇒ Object
- #new_post(post, users) ⇒ Object
- #new_private_post ⇒ Object
- #send_message(user_key, message, title, url) ⇒ Object
Constructor Details
#initialize(pushover_app_token, root_url) ⇒ PushoverNotifier
Returns a new instance of PushoverNotifier.
9 10 11 12 |
# File 'lib/thredded/pushover_notifier.rb', line 9 def initialize(pushover_app_token, root_url) @pushover_app_token = pushover_app_token @root_url = root_url end |
Instance Method Details
#human_name ⇒ Object
18 19 20 |
# File 'lib/thredded/pushover_notifier.rb', line 18 def human_name I18n.t('pushover_notifier.by_pushover') end |
#key ⇒ Object
14 15 16 |
# File 'lib/thredded/pushover_notifier.rb', line 14 def key 'pushover' end |
#new_post(post, users) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/thredded/pushover_notifier.rb', line 22 def new_post(post, users) require 'thredded/pushover_notifier/content_helper' helper = Thredded::PushoverNotifier::ContentHelper.new(@root_url, post) args = [helper., helper.title_for_new_topic_post, helper.post_url] users.map(&:pushover_user_key).each do |user_key| (user_key, *args) if user_key.present? end end |
#new_private_post ⇒ Object
31 |
# File 'lib/thredded/pushover_notifier.rb', line 31 def new_private_post; end |
#send_message(user_key, message, title, url) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/thredded/pushover_notifier.rb', line 33 def (user_key, , title, url) pushover_url = URI.parse('https://api.pushover.net/1/messages.json') req = Net::HTTP::Post.new(pushover_url.path) data = { token: @pushover_app_token, user: user_key, message: , title: title, url: url, url_title: 'View topic' } req.set_form_data(data) res = Net::HTTP.new(pushover_url.host, pushover_url.port) res.use_ssl = true res.verify_mode = OpenSSL::SSL::VERIFY_PEER res.start { |http| http.request(req) } end |