Class: Github::Activity::Notifications

Inherits:
Github::API show all
Defined in:
lib/github_api/activity/notifications.rb

Constant Summary

Constants included from Request

Request::METHODS, Request::METHODS_WITH_BODIES

Constants included from Connection

Connection::ALLOWED_OPTIONS

Constants included from Constants

Constants::ACCEPT, Constants::ACCEPTED_OAUTH_SCOPES, Constants::ACCEPT_CHARSET, Constants::CACHE_CONTROL, Constants::CONTENT_LENGTH, Constants::CONTENT_TYPE, Constants::DATE, Constants::ETAG, Constants::HEADER_LAST, Constants::HEADER_LINK, Constants::HEADER_NEXT, Constants::LOCATION, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::OAUTH_SCOPES, Constants::PARAM_PAGE, Constants::PARAM_PER_PAGE, Constants::PARAM_START_PAGE, Constants::RATELIMIT_LIMIT, Constants::RATELIMIT_REMAINING, Constants::SERVER, Constants::USER_AGENT

Constants included from MimeType

MimeType::MEDIA_LOOKUP

Instance Attribute Summary

Attributes inherited from Github::API

#current_options

Attributes included from Github::Authorization

#scopes

Instance Method Summary collapse

Methods inherited from Github::API

#api_methods_in, #append_arguments, #arguments, inherited, #initialize, #method_missing, #process_basic_auth, #set, #setup, #with, #yield_or_eval

Methods included from RateLimit

#ratelimit, #ratelimit_remaining

Methods included from Request

#delete_request, #get_request, #patch_request, #post_request, #put_request, #request

Methods included from Connection

#caching?, #clear_cache, #connection, #default_middleware, #default_options, #stack

Methods included from MimeType

#lookup_media, #parse

Methods included from Github::Authorization

#auth_code, #authenticated?, #authentication, #authorize_url, #basic_authed?, #client, #get_token

Constructor Details

This class inherits a constructor from Github::API

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Github::API

Instance Method Details

#create(*args) ⇒ Object

Create a 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).

Parameters

  • :subscribed - boolean - determines if notifications should be

    received from this thread.
    
  • :ignored - boolean - deterimines if all notifications should be

    blocked from this thread.
    

Examples

github = Github.new oauth_token: 'token'
github.activity.notifications.create 'thread-id',
  'subscribed': true
  'ignored': false


137
138
139
140
141
# File 'lib/github_api/activity/notifications.rb', line 137

def create(*args)
  arguments(args, :required => [:thread_id])

  put_request("/notifications/threads/#{thread_id}/subscription", arguments.params)
end

#delete(*args) ⇒ Object Also known as: remove

Delete a thread subscription

Examples

github = Github.new oauth_token: 'token'
github.activity.notifications.delete 'thread_id'


149
150
151
152
153
# File 'lib/github_api/activity/notifications.rb', line 149

def delete(*args)
  arguments(args, :required => [:thread_id])

  delete_request("/notifications/threads/#{thread_id}/subscription", arguments.params)
end

#get(*args) ⇒ Object Also known as: find

View a single thread

Examples

github = Github.new oauth_token: 'token'
github.activity.notifications.get 'thread_id'
github.activity.notifications.get 'thread_id' { |thread| ... }


53
54
55
56
57
58
59
# File 'lib/github_api/activity/notifications.rb', line 53

def get(*args)
  arguments(args, :required => [:thread_id])

  response = get_request("/notifications/threads/#{thread_id}", arguments.params)
  return response unless block_given?
  response.each { |el| yield el }
end

#list(*args) ⇒ Object Also known as: all

List your notifications

List all notifications for the current user, grouped by repository.

Parameters

  • :all - Optional boolean - true to show notifications marked as read.

  • :participating - Optional boolean - true to show only

    notifications in which the user is directly
    participating or mentioned.
    
  • :since - Optional string - 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.
    Example: “2012-10-09T23:39:01Z”.
    

Examples

github = Github.new oauth_token: 'token'
github.activity.notifications.list

List your notifications in a repository

Examples

github = Github.new
github.activity.notifications.list user: 'user-name', repo: 'repo-name'


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/github_api/activity/notifications.rb', line 30

def list(*args)
  params = arguments(args) do
    sift %w[ all participating since user repo]
  end.params

  response = if ( (user_name = params.delete("user")) &&
                  (repo_name = params.delete("repo")) )
    get_request("/repos/#{user_name}/#{repo_name}/notifications", params)
  else
    get_request("/notifications", params)
  end
  return response unless block_given?
  response.each { |el| yield el }
end

#mark(*args) ⇒ Object

Mark as read

Marking a notification as “read” removes it from the default view on GitHub.com.

Parameters

  • :unread - boolean - Changes the unread status of the threads.

  • :read - boolean - Inverse of “unread”

  • :last_read_at - optional string time - describes the last point

    that notifications were checked. Anything updated 
    since this time will not be updated. Default: Now.
    Expected in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
    Example: “2012-10-09T23:39:01Z”.
    

Examples

github = Github.new oauth_token: 'token'
github.activity.notifications.mark read: true

Mark notifications as read in a repository

Examples

github.activity.notifications.mark user: 'user-name', repo: 'repo-name',
  read: true

Mark a thread as read

Examples

github.activity.notifications.mark thread_id: 'id', read: true


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/github_api/activity/notifications.rb', line 91

def mark(*args)
  params = arguments(args) do
    sift %w[ unread read last_read_at user repo thread_id]
  end.params

  if ( (user_name = params.delete("user")) &&
       (repo_name = params.delete("repo")) )

    put_request("/repos/#{user_name}/#{repo_name}/notifications", params)
  elsif (thread_id = params.delete("thread_id"))
    patch_request("/notifications/threads/#{thread_id}", params)
  else
    put_request("/notifications", params)
  end
end

#subscribed?(*args) ⇒ Boolean

Check to see if the current user is subscribed to a thread.

Examples

github = Github.new oauth_token: 'token'
github.activity.notifications.subscribed? 'thread-id'

Returns:

  • (Boolean)


113
114
115
116
117
# File 'lib/github_api/activity/notifications.rb', line 113

def subscribed?(*args)
  arguments(args, :required => [:thread_id])

  get_request("/notifications/threads/#{thread_id}/subscription", arguments.params)
end