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.
-
#url ⇒ Object
The full target URL for the binding when used with #subscribe_direct.
-
#user_agent ⇒ Object
The user agent value to send on the request to github See: developer.github.com/v3/#user-agent-required.
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
. -
#subscribe_direct(opts) ⇒ bool success
Subscribe directly to a fixed URL, rather than a calculated URL for an instance of App.
-
#unsubscribe(opts) ⇒ bool success
Unsubscribe an instance of App hosted at
base_url
to a hook forowner
/repo_name
, authenticating withoauth_token
. -
#unsubscribe_direct(opts) ⇒ bool success
Unsubscribe directly to a fixed URL, rather than a calculated URL for an instance of App.
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
, event_type
, and user_agent
].
39 40 41 42 43 44 45 46 |
# File 'lib/right_hook/subscriber.rb', line 39 def initialize(default_opts = {}) @base_url = default_opts[:base_url] @url = default_opts[:url] @oauth_token = default_opts[:oauth_token] @owner = default_opts[:owner] @event_type = default_opts[:event_type] @user_agent = default_opts[:user_agent] 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.
24 25 26 |
# File 'lib/right_hook/subscriber.rb', line 24 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.
17 18 19 |
# File 'lib/right_hook/subscriber.rb', line 17 def oauth_token @oauth_token end |
#owner ⇒ Object
The owner of the named repository.
20 21 22 |
# File 'lib/right_hook/subscriber.rb', line 20 def owner @owner end |
#url ⇒ Object
The full target URL for the binding when used with #subscribe_direct.
13 14 15 |
# File 'lib/right_hook/subscriber.rb', line 13 def url @url end |
#user_agent ⇒ Object
The user agent value to send on the request to github See: developer.github.com/v3/#user-agent-required
28 29 30 |
# File 'lib/right_hook/subscriber.rb', line 28 def user_agent @user_agent 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.
59 60 61 |
# File 'lib/right_hook/subscriber.rb', line 59 def subscribe(opts) hub_request_with_mode('subscribe', opts) end |
#subscribe_direct(opts) ⇒ bool success
Subscribe directly to a fixed URL, rather than a calculated URL for an instance of App.
89 90 91 |
# File 'lib/right_hook/subscriber.rb', line 89 def subscribe_direct(opts) direct_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.)
75 76 77 |
# File 'lib/right_hook/subscriber.rb', line 75 def unsubscribe(opts) hub_request_with_mode('unsubscribe', opts) end |
#unsubscribe_direct(opts) ⇒ bool success
Unsubscribe directly to a fixed URL, rather than a calculated URL for an instance of App.
103 104 105 |
# File 'lib/right_hook/subscriber.rb', line 103 def unsubscribe_direct(opts) direct_hub_request_with_mode('unsubscribe', opts) end |