pubsubhubbub

Version, currently 0.1.32 versions

github.com/joseafga/pubsubhubbub.cr

Google PubSubHubbub subscriber library written in Crystal.

0 stars
1 dependent
License: MIT

Nothing has been indexed for 0.1.3 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  pubsubhubbub:
    github: joseafga/pubsubhubbub.cr
    version: ~> 0.1.3

Then run:

shards install

shard.yml

No shard.yml has been indexed for 0.1.3. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

PubSubHubbub.cr

PubSubHubbub subscriber library written in Crystal.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      pubsubhubbub:
        github: joseafga/pubsubhubbub.cr
  2. Run shards install

Usage

Basic

require "pubsubhubbub"

PubSubHubbub.configure do |settings|
  settings.callback = "https://www.example.com/pubsubhubbub/some/path"
end

subscriber = PubSubHubbub::Subscriber.new "https://www.youtube.com/xml/feeds/videos.xml?channel_id=SomeChannelId"
subscriber.subscribe

HTTP Server

Basic usage allows sending requests to the server but new requests will be sent to the host address (configured in PubSubHubbub.configure) and will expect a specific response. To deal with this, we will need an HTTP::Server, fortunately PubSubHubbub.cr already has a handler created to be used together with HTTP::Server, which should provide the necessary functions for the most of use cases.

require "pubsubhubbub"
require "http"

class MyClass
  class_getter subscriber = PubSubHubbub::Subscriber.new("https://www.youtube.com/xml/feeds/videos.xml?channel_id=SomeChannelId")

  # `SubscriberHandler` uses to handle incoming requests from Hub.
  # This is used to make more dynamic, so that it is possible to find a value from an array or
  # database.
  def self.find_subscriber!(topic : String?) : PubSubHubbub::Subscriber
    subscriber
  end
end

# This hook will execute when it receives a notification.
PubSubHubbub::Subscriber.on :notify do |subscriber, xml|
  puts "Receiving notification from #{subscriber.topic}: #{xml}"
end

server = HTTP::Server.new([
  PubSubHubbub::ErrorHandler.new,
  PubSubHubbub::SubscriberHandler(MyClass).new,
])

address = server.bind_tcp 8080
puts "Listening on http://#{address}"
server.listen

Contributing

  1. Fork it (https://github.com/joseafga/pubsubhubbub.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors