Skip to content

Latest commit

 

History

History
74 lines (58 loc) · 1.44 KB

README.md

File metadata and controls

74 lines (58 loc) · 1.44 KB

pusher-platform-ruby

Pusher Platform SDK for Ruby.

Installation

Add pusher-platform to your Gemfile:

gem 'pusher-platform', '~> 0.6.0'

Usage

In order to access Pusher Platform, first instantiate an Instance object:

require 'pusher-platform'

pusher = Pusher::Instance.new(
  locator: 'your:instance:locator',
  key: 'key-id:key-secret',
  service_name: 'chatkit',
  service_version: 'v1'
)

Authentication (Rails + Devise)

Instance objects provide an authenticate method, which can be used in Rails controllers to build authentication endpoints. Authentication endpoints issue access tokens used by Pusher Platform clients to access the API.

Make sure you authenticate the user before issuing access tokens, e.g. by using the authenticate_user! Devise filter.

class AuthController < ActionController::Base
  before_action :authenticate_user!

  def auth
    render pusher.authenticate(request, {
      user_id: current_user.id,
    })
  end
end

Request API

Instance objects provide a low-level request API, which can be used to contact Pusher Platform.

begin
  response = pusher.request(
    method: "POST",
    path: "feeds/playground",
    headers: {
      "Content-Type": "application/json",
    },
    body: { items: ["test"] }.to_json
  )
  p response.status
  p response.headers
  p response.body
rescue Pusher::ErrorResponse => e
  p e.status
  p e.headers
  p e.description
rescue
  p e
end