Giter Club home page Giter Club logo

satori-rtm-sdk-ruby's Introduction

Ruby SDK for Satori RTM

RTM is the realtime messaging service at the core of the Satori.

Ruby SDK makes it more convenient to use Satori RTM from Ruby programming language.

Installation

Ruby SDK works on Ruby >= 2.0 and JRuby.

Install it with RubyGems

gem install satori-rtm-sdk --pre

or add this to your Gemfile if you use Bundler:

gem "satori-rtm-sdk", ">= 0.0.1.rc1"

Documentation

Getting started

Here's an example how to use Satori RTM SDK to write publish / subscribe logic:

require 'satori-rtm-sdk'

endpoint = 'YOUR_ENDPOINT'
appkey = 'YOUR_APPKEY'

client = Satori::RTM::Client.new(endpoint, appkey)

client.connect

client.subscribe 'animals' do |_ctx, event|
  case event.type
  when :subscribed
    puts "Subscribed to the channel: #{event.data[:subscription_id]}"
  when :data
    event.data[:messages].each { |msg| puts "Animal is received #{msg}" }
  when :error
    puts "Subscription error: #{event.data[:error]} -- #{event.data[:reason]}"
  end
end

loop do
  client.publish 'animals', who: 'zebra', where: [34.13, -118.32]
  client.sock_read_repeatedly duration_in_secs: 2
end

EventMachine

Ruby SDK for Satori RTM doesn't lock you into using threading or event loop frameworks, but it's ready to be used with any of those.

The example of using Ruby SDK with EventMachine can be found in examples/eventmachine_quickstart.rb

Logging

You can enable dumping of all PDUs either from your code

Satori::RTM::Logger.use_std_logger(::Logger::DEBUG)

or by setting DEBUG_SATORI_SDK environment variable prior to running your application

$ DEBUG_SATORI_SDK=true ruby myapp.rb

Testing Your Changes

Tests require an active RTM to be available. The tests require credentials.json to be populated with the RTM properties.

The credentials.json file must include the following key-value pairs:

{
  "endpoint": "YOUR_ENDPOINT",
  "appkey": "YOUR_APPKEY",
  "auth_role_name": "YOUR_ROLE",
  "auth_role_secret_key": "YOUR_SECRET",
  "auth_restricted_channel": "YOUR_RESTRICTED_CHANNEL"
}
  • endpoint is your customer-specific endpoint for RTM access.
  • appkey is your application key.
  • auth_role_name is a role name that permits to publish / subscribe to auth_restricted_channel. Must be not default.
  • auth_role_secret_key is a secret key for auth_role_name.
  • auth_restricted_channel is a channel with subscribe and publish access for auth_role_name role only.

After setting up credentials.json, just type rspec spec at the command line.

satori-rtm-sdk-ruby's People

Contributors

satori-avasenin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.