1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
# frozen_string_literal: true
module Octokit
class Client
# Methods for the Notifications API
#
# @see https://developer.github.com/v3/activity/notifications/
module Notifications
# List your notifications
#
# @param options [Hash] Optional parameters
# @option options [Boolean] :all 'true' to show notifications marked as
# read.
# @option options [Boolean] :participating 'true' to show only
# notifications in which the user is directly participating or
# mentioned.
# @option options [String] :since Time filters out any notifications
# updated before the given time. The time should be passed in as UTC in
# the ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. Ex. '2012-10-09T23:39:01Z'
# @return [Array<Sawyer::Resource>] Array of notifications.
# @see https://developer.github.com/v3/activity/notifications/#list-your-notifications
# @example Get users notifications
# @client.notifications
# @example Get all notifications since a certain time.
# @client.notifications({all: true, since: '2012-10-09T23:39:01Z'})
def notifications(options = {})
paginate 'notifications', options
end
# List your notifications in a repository
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param options [Hash] Optional parameters
# @option options [Boolean] :all 'true' to show notifications marked as
# read.
# @option options [Boolean] :participating 'true' to show only
# notifications in which the user is directly participating or
# mentioned.
# @option options [String] :since Time filters out any notifications
# updated before the given time. The time should be passed in as UTC in
# the ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. Ex. '2012-10-09T23:39:01Z'
# @return [Array<Sawyer::Resource>] Array of notifications.
# @see https://developer.github.com/v3/activity/notifications/#list-your-notifications-in-a-repository
# @example Get your notifications for octokit/octokit.rb
# @client.repository_notifications('octokit/octokit.rb')
# @example Get your notifications for octokit/octokit.rb since a time.
# @client.repository_notifications({since: '2012-10-09T23:39:01Z'})
def repository_notifications(repo, options = {})
paginate "#{Repository.path repo}/notifications", options
end
alias repo_notifications repository_notifications
# Mark notifications as read
#
# @param options [Hash] Optional parameters
# @option options [Boolean] :unread Changes the unread status of the
# threads.
# @option options [Boolean] :read Inverse of 'unread'.
# @option options [String] :last_read_at ('Now') Describes the last point
# that notifications were checked. Anything updated since this time
# will not be updated. The time should be passed in as UTC in the
# ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. Ex. '2012-10-09T23:39:01Z'
# @return [Boolean] True if marked as read, false otherwise
# @see https://developer.github.com/v3/activity/notifications/#mark-as-read
#
# @example
# @client.mark_notifications_as_read
def mark_notifications_as_read(options = {})
request :put, 'notifications', options
last_response.status == 205
end
# Mark notifications from a specific repository as read
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
# @param options [Hash] Optional parameters
# @option options [Boolean] :unread Changes the unread status of the
# threads.
# @option options [Boolean] :read Inverse of 'unread'.
# @option options [String] :last_read_at ('Now') Describes the last point
# that notifications were checked. Anything updated since this time
# will not be updated. The time should be passed in as UTC in the
# ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. Ex. '2012-10-09T23:39:01Z'
# @return [Boolean] True if marked as read, false otherwise
# @see https://developer.github.com/v3/activity/notifications/#mark-notifications-as-read-in-a-repository
# @example
# @client.mark_notifications_as_read("octokit/octokit.rb")
def mark_repository_notifications_as_read(repo, options = {})
request :put, "#{Repository.path repo}/notifications", options
last_response.status == 205
end
alias mark_repo_notifications_as_read mark_repository_notifications_as_read
# List notifications for a specific thread
#
# @param thread_id [Integer] Id of the thread.
# @return [Array<Sawyer::Resource>] Array of notifications.
# @see https://developer.github.com/v3/activity/notifications/#view-a-single-thread
#
# @example
# @client.notification_thread(1000)
def thread_notifications(thread_id, options = {})
get "notifications/threads/#{thread_id}", options
end
# Mark thread as read
#
# @param thread_id [Integer] Id of the thread to update.
# @return [Boolean] True if updated, false otherwise.
# @see https://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read
# @example
# @client.mark_thread_as_read(1, :read => false)
def mark_thread_as_read(thread_id, options = {})
request :patch, "notifications/threads/#{thread_id}", options
last_response.status == 205
end
# Get thread subscription
#
# @param thread_id [Integer] Id of the thread.
# @return [Sawyer::Resource] Subscription.
# @see https://developer.github.com/v3/activity/notifications/#get-a-thread-subscription
# @example
# @client.thread_subscription(1)
def thread_subscription(thread_id, options = {})
get "notifications/threads/#{thread_id}/subscription", options
end
# Update thread subscription
#
# This lets you subscribe to a thread, or ignore it. Subscribing to a
# thread is unnecessary if the user is already subscribed to the
# repository. Ignoring a thread will mute all future notifications (until
# you comment or get @mentioned).
#
# @param thread_id [Integer] Id of the thread.
# @param options
# @option options [Boolean] :subscribed Determines if notifications
# should be received from this repository.
# @option options [Boolean] :ignored Deterimines if all notifications
# should be blocked from this repository.
# @return [Sawyer::Resource] Updated subscription.
# @see https://developer.github.com/v3/activity/notifications/#set-a-thread-subscription
# @example Subscribe to notifications
# @client.update_thread_subscription(1, :subscribed => true)
# @example Ignore notifications from a repo
# @client.update_thread_subscription(1, :ignored => true)
def update_thread_subscription(thread_id, options = {})
put "notifications/threads/#{thread_id}/subscription", options
end
# Delete a thread subscription
#
# @param thread_id [Integer] Id of the thread.
# @return [Boolean] True if delete successful, false otherwise.
# @see https://developer.github.com/v3/activity/notifications/#delete-a-thread-subscription
# @example
# @client.delete_thread_subscription(1)
def delete_thread_subscription(thread_id, options = {})
boolean_from_response :delete, "notifications/threads/#{thread_id}/subscription", options
end
end
end
end
|