Class: Github::Client::Activity::Watching

Inherits:
API
  • Object
show all
Defined in:
lib/github_api2/client/activity/watching.rb

Overview

Watching a Repository registers the user to receive notificactions on new discussions, as well as events in the user’s activity feed.

Constant Summary

Constants included from MimeType

MimeType::MEDIA_LOOKUP

Constants included from Github::Constants

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

Instance Attribute Summary

Attributes inherited from API

#current_options

Instance Method Summary collapse

Methods inherited from API

after_callbacks, after_request, #api_methods_in, #arguments, before_callbacks, before_request, clear_request_methods!, #disable_redirects, #execute, extend_with_actions, extra_methods, #extract_basic_auth, extract_class_name, #filter_callbacks, inherited, #initialize, internal_methods, method_added, #method_missing, #module_methods_in, namespace, request_methods, require_all, #respond_to?, root!, #run_callbacks, #set, #yield_or_eval

Methods included from Request::Verbs

#delete_request, #get_request, #head_request, #options_request, #patch_request, #post_request, #put_request

Methods included from RateLimit

#ratelimit, #ratelimit_remaining, #ratelimit_reset

Methods included from MimeType

#lookup_media, #parse

Methods included from 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 Also known as: subscribe

Create subscription to a repository

Examples:

github = Github.new
github.activity.watching.create 'user-name', 'repo-name'
github.activity.watching.create user: 'user-name', repo: 'repo-name'

Parameters:

See Also:



95
96
97
98
99
# File 'lib/github_api2/client/activity/watching.rb', line 95

def create(*args)
  arguments(args, required: [:user, :repo])

  put_request("/repos/#{arguments.user}/#{arguments.repo}/subscription", arguments.params)
end

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

Delete a repository subscription

Examples:

github = Github.new oauth_token: '...'
github.activity.watching.delete 'user-name', 'repo-name'
github.activity.watching.delete user: 'user-name', repo: 'repo-name'

See Also:



114
115
116
117
118
# File 'lib/github_api2/client/activity/watching.rb', line 114

def delete(*args)
  arguments(args, required: [:user, :repo])

  delete_request("/repos/#{arguments.user}/#{arguments.repo}/subscription", arguments.params)
end

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

List repository watchers

Examples:

github = Github.new
github.activity.watching.list user: 'user-name', repo: 'repo-name'
github.activity.watching.list user: 'user-name', repo: 'repo-name' { |watcher| ... }

See Also:



19
20
21
22
23
24
25
# File 'lib/github_api2/client/activity/watching.rb', line 19

def list(*args)
  arguments(args, required: [:user, :repo])

  response = get_request("/repos/#{arguments.user}/#{arguments.repo}/subscribers", arguments.params)
  return response unless block_given?
  response.each { |el| yield el }
end

#subscribed?(*args) ⇒ Boolean

Check if you are subscribed to a repository

Examples:

github = Github.new
github.activity.watching.subscribed? 'user-name', 'repo-name'
github.activity.watching.subscribed? user: 'user-name', repo: 'repo-name'

Returns:

  • (Boolean)

See Also:



68
69
70
71
72
73
74
75
# File 'lib/github_api2/client/activity/watching.rb', line 68

def subscribed?(*args)
  arguments(args, required: [:user, :repo])

  get_request("/repos/#{arguments.user}/#{arguments.repo}/subscription", arguments.params)
  true
rescue Github::Error::NotFound
  false
end

#unwatch(*args) ⇒ Object

Stop watching a repository

You need to be authenticated to stop watching a repository.

Examples:

github = Github.new
github.activity.watching.unwatch 'user-name', 'repo-name'

See Also:



170
171
172
173
174
# File 'lib/github_api2/client/activity/watching.rb', line 170

def unwatch(*args)
  arguments(args, required: [:user, :repo])

  delete_request("/user/subscriptions/#{arguments.user}/#{arguments.repo}", arguments.params)
end

#watch(*args) ⇒ Object

Watch a repository

You need to be authenticated to watch a repository

Examples:

github = Github.new
github.activity.watching.watch 'user-name', 'repo-name'

See Also:



153
154
155
156
157
# File 'lib/github_api2/client/activity/watching.rb', line 153

def watch(*args)
  arguments(args, required: [:user, :repo])

  put_request("/user/subscriptions/#{arguments.user}/#{arguments.repo}", arguments.params)
end

#watched(*args) ⇒ Object

List repos being watched by a user

List repos being watched by the authenticated user

Examples:

github = Github.new
github.activity.watching.watched user: 'user-name'
github = Github.new oauth_token: '...'
github.activity.watching.watched

See Also:



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/github_api2/client/activity/watching.rb', line 43

def watched(*args)
  arguments(args)
  params = arguments.params

  response = if (user_name = params.delete('user'))
    get_request("/users/#{user_name}/subscriptions", params)
  else
    get_request('/user/subscriptions', params)
  end
  return response unless block_given?
  response.each { |el| yield el }
end

#watching?(*args) ⇒ Boolean

Check if you are watching a repository

Examples:

github = Github.new
github.activity.watching.watching? 'user-name', 'repo-name'

Returns:

  • (Boolean)

    Returns true if this repo is watched by you, false otherwise.

See Also:



133
134
135
136
137
138
139
140
# File 'lib/github_api2/client/activity/watching.rb', line 133

def watching?(*args)
  arguments(args, required: [:user, :repo])

  get_request("/user/subscriptions/#{arguments.user}/#{arguments.repo}", arguments.params)
  true
rescue Github::Error::NotFound
  false
end