class Denotificator::Runtime
Attributes
api_client[R]
Public Class Methods
new()
click to toggle source
# File lib/denotificator/runtime.rb, line 15 def initialize @api_client = APIClient.new "https://api.github.com", "denotificator/#{Denotificator::VERSION} (https://github.com/marcosvm/denotificator)", Denotificator.auth_token end
run!()
click to toggle source
# File lib/denotificator/runtime.rb, line 10 def run! new.run! end
Public Instance Methods
run!()
click to toggle source
# File lib/denotificator/runtime.rb, line 21 def run! notifications = load_github_notifications process_notifications(notifications) end
Private Instance Methods
load_github_notifications()
click to toggle source
# File lib/denotificator/runtime.rb, line 28 def load_github_notifications response = api_client.get_http_response '/notifications' JSON.parse response.body end
process_notifications(notifications)
click to toggle source
# File lib/denotificator/runtime.rb, line 33 def process_notifications(notifications) notifications.each do |notification| id = notification["id"] reason = notification["reason"] title = notification["subject"]["title"] if reason == 'subscribed' subscription_uri = "/notifications/threads/#{id}/subscription" subscription_response = api_client.get_http_response subscription_uri if subscription_response.status == 404 subscription_url = notification['subject']['url'] puts "#{id}:unsubscribing at #{subscription_url} on #{title}" payload = { "subscribed" => false, "ignored" => true }.to_json api_client.put_http_response subscription_uri, payload end else puts "#{id}:#{reason}:#{title}" end end end