Class: RightHook::Subscriber
- Inherits:
-
Object
- Object
- RightHook::Subscriber
- Defined in:
- lib/right_hook/subscriber.rb
Overview
Subscriber can subscribe and unsubscribe GitHub hooks to a hosted instance of a specified App. See the README for sample usage.
Instance Attribute Summary collapse
-
#base_url ⇒ Object
The base URL for the binding (where your App is hosted).
-
#event_type ⇒ Object
The event type of the hook.
-
#oauth_token ⇒ Object
The OAuth token to use for authenticating with GitHub.
-
#owner ⇒ Object
The owner of the named repository.
Instance Method Summary collapse
-
#initialize(default_opts = {}) ⇒ Subscriber
constructor
Initialize takes options which will be used as default values in other methods.
-
#subscribe(opts) ⇒ bool success
Subscribe an instance of App hosted at
base_url
to a hook forowner
/repo_name
, authenticating withoauth_token
. -
#unsubscribe(opts) ⇒ bool success
Unsubscribe an instance of App hosted at
base_url
to a hook forowner
/repo_name
, authenticating withoauth_token
.
Constructor Details
#initialize(default_opts = {}) ⇒ Subscriber
Initialize takes options which will be used as default values in other methods. The valid keys in the options are [base_url
, oauth_token
, owner
, and event_type
].
25 26 27 28 29 30 |
# File 'lib/right_hook/subscriber.rb', line 25 def initialize(default_opts = {}) @base_url = default_opts[:base_url] @oauth_token = default_opts[:oauth_token] @owner = default_opts[:owner] @event_type = default_opts[:event_type] end |
Instance Attribute Details
#base_url ⇒ Object
The base URL for the binding (where your App is hosted).
10 11 12 |
# File 'lib/right_hook/subscriber.rb', line 10 def base_url @base_url end |
#event_type ⇒ Object
The event type of the hook. See developer.github.com/v3/repos/hooks/ for a complete list of valid types.
21 22 23 |
# File 'lib/right_hook/subscriber.rb', line 21 def event_type @event_type end |
#oauth_token ⇒ Object
The OAuth token to use for authenticating with GitHub. The token must belong to an account that has the repo
scope and collaborator privilege on the given repository.
14 15 16 |
# File 'lib/right_hook/subscriber.rb', line 14 def oauth_token @oauth_token end |
#owner ⇒ Object
The owner of the named repository.
17 18 19 |
# File 'lib/right_hook/subscriber.rb', line 17 def owner @owner end |
Instance Method Details
#subscribe(opts) ⇒ bool success
Subscribe an instance of App hosted at base_url
to a hook for owner
/repo_name
, authenticating with oauth_token
. repo_name
and secret
are required options and they are intentionally not stored as defaults on the Subscriber
instance.
35 36 37 |
# File 'lib/right_hook/subscriber.rb', line 35 def subscribe(opts) hub_request_with_mode('subscribe', opts) end |
#unsubscribe(opts) ⇒ bool success
Unsubscribe an instance of App hosted at base_url
to a hook for owner
/repo_name
, authenticating with oauth_token
. repo_name
and secret
are required options and they are intentionally not stored as defaults on the Subscriber
instance. (NB: It’s possible that GitHub’s API *doesn’t* require secret; I haven’t checked.)
43 44 45 |
# File 'lib/right_hook/subscriber.rb', line 43 def unsubscribe(opts) hub_request_with_mode('unsubscribe', opts) end |