{"id":15431824,"url":"https://github.com/alternatelabs/bifrost-ruby-client","last_synced_at":"2025-04-15T07:40:24.727Z","repository":{"id":62554192,"uuid":"129970953","full_name":"alternatelabs/bifrost-ruby-client","owner":"alternatelabs","description":"A Ruby client helper for the bifrost crystal websockets server","archived":false,"fork":false,"pushed_at":"2018-04-30T20:23:14.000Z","size":14,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-29T20:22:52.995Z","etag":null,"topics":["ruby","ruby-on-rails","websocket-server","websockets"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alternatelabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-17T22:12:25.000Z","updated_at":"2019-04-11T15:31:20.000Z","dependencies_parsed_at":"2022-11-03T05:00:31.431Z","dependency_job_id":null,"html_url":"https://github.com/alternatelabs/bifrost-ruby-client","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alternatelabs%2Fbifrost-ruby-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alternatelabs%2Fbifrost-ruby-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alternatelabs%2Fbifrost-ruby-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alternatelabs%2Fbifrost-ruby-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alternatelabs","download_url":"https://codeload.github.com/alternatelabs/bifrost-ruby-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249029867,"owners_count":21201157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ruby","ruby-on-rails","websocket-server","websockets"],"created_at":"2024-10-01T18:24:10.679Z","updated_at":"2025-04-15T07:40:24.704Z","avatar_url":"https://github.com/alternatelabs.png","language":"Ruby","readme":"# Bifrost Ruby Client\n\n[![Build Status](https://travis-ci.org/alternatelabs/bifrost-ruby-client.svg?branch=master)](https://travis-ci.org/alternatelabs/bifrost-ruby-client)\n\nA ruby client library for the [bifrost crystal](https://github.com/alternatelabs/bifrost) websockets server.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'bifrost-client'\n```\n\nAnd then execute:\n\n```sh\n$ bundle\n```\n\n## Configuration\n\nBy default Bifrost::Client will look for environment variables:\n\n```sh\nJWT_SECRET=9c3ed1aa0ba8405effdb363839caa3cc\nBIFROST_URL=https://bifrost-server.myapp.com\n```\n\nAnd you can create a Bifrost client like so:\n\n```ruby\nclient = Bifrost::Client.new\n```\n\nOr you can pass in configuration directly:\n\n```ruby\nclient = Bifrost::Client.new(\n  jwt_secret: \"9c3ed1aa0ba8405effdb363839caa3cc\",\n  bifrost_server_url: \"https://bifrost-server.myapp.com\"\n)\n```\n\n## Usage\n\n### Token helper\n\nThis helps you generate a JWT to give an end user permission to connect to a channel called `user:thor`\n\n```ruby\ntoken = client.token_for(channels: %w[user:thor]) # =\u003e \"eyJhbGciOiJIUzUxMiJ9.eyJjaGFubmVscyI6WyJ1c2VyOnRob3IiXX0.SBgGNE-n7S8gVtYQ3wg7_WG2TqOGNFf-jy0GW57_YV-B-xjekm4KCQwTZIqxL_TXoqbWW3tThT9YTt4GLD4Y7A\"\n```\n\nOnce you have this token [follow the instructions on the bifrost repo](https://github.com/alternatelabs/bifrost#1-create-an-api-endpoint-in-your-application-that-can-give-users-a-realtime-token) to provide that token to client side JS and connect using ReconnectingWebsocket.\n\n### Broadcast events\n\nUse `client#broadcast` when you want to send an event out to all members of a channel. Payload must be a string, we recommend you encode it to JSON and can safely `JSON.parse(payload)` in your client side code upon receiving the message.\n\n```ruby\nbegin\n  payload = JSON.dump({ name: \"Hela\" })\n  channel = \"user:thor\"\n  client.broadcast(channel, event: \"invader_detected\", data: payload) # =\u003e { deliveries: 1 }\nrescue Bifrost::ServerError =\u003e e\n  # Do something with the error\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/alternatelabs/bifrost-ruby-client.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falternatelabs%2Fbifrost-ruby-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falternatelabs%2Fbifrost-ruby-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falternatelabs%2Fbifrost-ruby-client/lists"}