Module: Octokit::Client::PubSubHubbub

Included in:
Octokit::Client
Defined in:
lib/octokit/client/pub_sub_hubbub.rb

Overview

Methods for the PubSubHubbub API

Instance Method Summary collapse

Instance Method Details

#subscribe(topic, callback) ⇒ Boolean

Subscribe to a pubsub topic

Examples:

Subscribe to push events from one of your repositories, having an email sent when fired

client = Octokit::Client.new(:oauth_token = "token")
client.subscribe("https://github.com/joshk/devise_imapable/events/push", "github://[email protected]")

Parameters:

  • topic (String)

    A recoginized and supported pubsub topic

  • callback (String)

    A callback url to be posted to when the topic event is fired

Returns:

  • (Boolean)

    true if the subscribe was successful, otherwise an error is raised



16
17
18
19
20
21
22
23
24
25
# File 'lib/octokit/client/pub_sub_hubbub.rb', line 16

def subscribe(topic, callback)
  options = {
    :"hub.mode" => "subscribe",
    :"hub.topic" => topic,
    :"hub.callback" => callback
  }
  response = pub_sub_hubbub_request(options)

  response.status == 204
end

#subscribe_service_hook(repo, service_name, service_arguments = {}) ⇒ Object

Subscribe to a repository through pubsub

Examples:

Subscribe to push events to one of your repositories to Travis-CI

client = Octokit::Client.new(:oauth_token = "token")
client.subscribe_service_hook('joshk/device_imapable', 'Travis', { :token => "test", :domain => "domain", :user => "user" })

Parameters:

  • repo (String, Repository, Hash)

    A GitHub repository

  • service_name (String)

    service name owner

  • service_arguments (Hash) (defaults to: {})

    params that will be passed by subscribed hook. List of services is available @ github.com/github/github-services/tree/master/docs. Please refer Data node for complete list of arguments.



56
57
58
59
60
# File 'lib/octokit/client/pub_sub_hubbub.rb', line 56

def subscribe_service_hook(repo, service_name, service_arguments = {})
  topic = "#{Octokit.web_endpoint}#{Repository.new(repo)}/events/push"
  callback = "github://#{service_name}?#{service_arguments.collect{ |k,v| [ k,v ].join("=") }.join("&") }"
  subscribe(topic, callback)
end

#unsubscribe(topic, callback) ⇒ Boolean

Unsubscribe from a pubsub topic

Examples:

Unsubscribe to push events from one of your repositories, no longer having an email sent when fired

client = Octokit::Client.new(:oauth_token = "token")
client.unsubscribe("https://github.com/joshk/devise_imapable/events/push", "github://[email protected]")

Parameters:

  • topic (String)

    A recoginized pubsub topic

  • callback (String)

    A callback url to be unsubscribed from

Returns:

  • (Boolean)

    true if the unsubscribe was successful, otherwise an error is raised



35
36
37
38
39
40
41
42
43
44
# File 'lib/octokit/client/pub_sub_hubbub.rb', line 35

def unsubscribe(topic, callback)
  options = {
    :"hub.mode" => "unsubscribe",
    :"hub.topic" => topic,
    :"hub.callback" => callback
  }
  response = pub_sub_hubbub_request(options)

  response.status == 204
end

#unsubscribe_service_hook(repo, service_name) ⇒ Object

Unsubscribe repository through pubsub

Examples:

Subscribe to push events to one of your repositories to Travis-CI

client = Octokit::Client.new(:oauth_token = "token")
client.unsubscribe_service_hook('joshk/device_imapable', 'Travis')

Parameters:



70
71
72
73
74
# File 'lib/octokit/client/pub_sub_hubbub.rb', line 70

def unsubscribe_service_hook(repo, service_name)
  topic = "#{Octokit.web_endpoint}#{Repository.new(repo)}/events/push"
  callback = "github://#{service_name}"
  unsubscribe(topic, callback)
end