class CirclerPusherClient

Public Instance Methods

bind(channel, event) { |data| ... } click to toggle source
# File lib/circler/networking/pusher_client.rb, line 12
def bind(channel, event)
  @socket.subscribe(channel)
  @socket[channel].bind(event) do |data|
    yield data
  end
end
bind_event_json(channel, event) { |json| ... } click to toggle source
# File lib/circler/networking/pusher_client.rb, line 19
def bind_event_json(channel, event)
  bind(channel, event) do |data|
    JSON.parse(data).each { |json| yield(json) }
  end
end
connect() click to toggle source
# File lib/circler/networking/pusher_client.rb, line 6
def connect
  PusherClient.logger.level = Logger::ERROR
  @socket = PusherClient::Socket.new(app_key, pusher_options)
  @socket.connect(true)
end
unsubscribe(channel) click to toggle source
# File lib/circler/networking/pusher_client.rb, line 25
def unsubscribe(channel)
  @socket.unsubscribe(channel)
end

Private Instance Methods

app_key() click to toggle source
# File lib/circler/networking/pusher_client.rb, line 31
def app_key
  '1cf6e0e755e419d2ac9a'
end
auth(socket_id, channel) click to toggle source
# File lib/circler/networking/pusher_client.rb, line 43
def auth(socket_id, channel)
  data = { socket_id: socket_id, channel_name: channel.name }
  token = ENV['CIRCLE_CI_TOKEN'] || ask('Circle CI token ? :')
  res = connection.post("/auth/pusher?circle-token=#{token}", data)
  JSON.parse(res.body)['auth']
end
connection() click to toggle source
# File lib/circler/networking/pusher_client.rb, line 50
def connection
  Faraday.new(url: 'https://circleci.com') do |f|
    f.request :url_encoded
    f.adapter Faraday.default_adapter
  end
end
pusher_options() click to toggle source
# File lib/circler/networking/pusher_client.rb, line 35
def pusher_options
  {
    secure: true,
    auth_method: proc { |a, b| auth(a, b) },
    logger: Logger.new('/dev/null')
  }
end