https://github.com/mastodon/ostatus2
A Ruby toolset for interacting with the OStatus suite of protocols
https://github.com/mastodon/ostatus2
ostatus salmon
Last synced: 18 days ago
JSON representation
A Ruby toolset for interacting with the OStatus suite of protocols
- Host: GitHub
- URL: https://github.com/mastodon/ostatus2
- Owner: mastodon
- License: mit
- Archived: true
- Created: 2016-02-19T01:16:00.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-01-12T14:33:31.000Z (almost 6 years ago)
- Last Synced: 2024-09-21T13:04:29.892Z (about 1 year ago)
- Topics: ostatus, salmon
- Language: Ruby
- Homepage:
- Size: 30.3 KB
- Stars: 31
- Watchers: 5
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
OStatus2
==========[][gem]
[][travis]
[][gemnasium][gem]: https://rubygems.org/gems/ostatus2
[travis]: https://travis-ci.org/tootsuite/ostatus2
[gemnasium]: https://gemnasium.com/tootsuite/ostatus2A Ruby toolset for interacting with the OStatus suite of protocols:
* Subscribing to and publishing feeds via PubSubHubbub
* Interacting with feeds via Salmon## Installation
gem install ostatus2
## Usage
When your feed updates and you need to notify subscribers:
p = OStatus2::Publication.new('http://url.to/feed', ['http://some.hub'])
p.publishWhen you want to subscribe to a feed:
token = 'abc123'
secret = 'def456's = OStatus2::Subscription.new('http://url.to/feed', token: token, secret: secret, webhook: 'http://url.to/webhook', hub: 'http://some.hub')
s.subscribeYour webhook URL will receive a HTTP **GET** request that you will need to handle:
if s.valid?(params['hub.topic'], params['hub.verify_token'])
# echo back params['hub.challenge']
else
# return 404
endOnce the subscription is established, your webhook URL will be receiving HTTP **POST** requests. Among the headers of such a request will be the hub's signature on the content: `X-Hub-Signature`. You can verify the integrity of the request:
body = request.body.read
signature = request.env['HTTP_X_HUB_SIGNATURE']if s.verify(body, signature)
# Do something with the data!
endWhen you want to notify a remote resource about an interaction (like a comment):
your_rsa_keypair = OpenSSL::PKey::RSA.new 2048
salmon = OStatus2::Salmon.new
envelope = salmon.pack(comment, your_rsa_keypair)salmon.post('http://remote.salmon/endpoint', envelope)
When you receive a Salmon notification about a remote interaction:
salmon = OStatus2::Salmon.new
comment = salmon.unpack(envelope)# Parse comment and determine who the remote author is pretending to be,
# fetch their public key via Webfinger or something like that, and finallyif salmon.verify(envelope, remote_public_key)
# You can be sure the salmon is genuine
end