Qwertie- / eventify_pro

Allows to publish events from Ruby-applications

Home Page:http://eventify.pro

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

EventifyPro

Client for EventifyPro API. Allows to publish events from Ruby-applications.

Installation

Add this line to your application's Gemfile:

gem 'eventify_pro'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install eventify_pro

Usage


Getting Started:

This guide assumes you have created an account and obtained an API key from EventifyPro

It's really easy to start publishing events with EventifyPro, just 2 lines of code:

client = EventifyPro::Client.new(api_key: 'secret')
client.publish(type: 'OrderCreated', data: { order_id: 1, amount: 500 })

Ruby On Rails

In a basic Ruby On Rails application you could create class under lib directory:

# lib/eventify.rb

class Eventify
  def self.client
    @client ||= EventifyPro::Client.new(api_key: 'secret', logger: Rails.logger)
  end

  def self.publish(event_type, data)
    client.publish(type: event_type, data: data)
  end
end

Great, now to publish event from any place of your app use:

Eventify.publish('UserSignedUp', user_id: 1, first_name: 'John', last_name: 'Doe')
  • type: type of the event

  • data: key and value pairs pertaining to the event

Don't forget to enable loading of the lib directory in application.rb file:

# config/application.rb

config.autoload_paths << Rails.root.join('lib')

Example:

class OrdersController < ApplicationController
  def create
    @order = Order.new(params[:order])

    if @order.save
      Eventify.publish(type: 'OrderCreated', data: { order_id: @order.id, amount: @order.amount })
      redirect_to @order, notice: 'Post was successfully created.'
    else
      render :new
    end
  end
end

Configuration

raise_errors:

  • By default, EventifyPro::Client will swallow errors. It will return true or false depending on the result of publishing.
  • It's possible to pass raise_errors: true. In that case client will throw EventifyPro::Error exception if something went wrong.

Example:

client = EventifyPro::Client.new(api_key: 'secret', raise_errors: true)
begin
  client.publish(type: 'OrderCreated', data: { order_id: 1, amount: 1500 })
rescue EventifyPro::Error
  # exception handling
end

logger

  • By default, client will use STDOUT to print error details.
  • You can provide any logger that responds to .info(message). For example Rails.logger.

Example:

client = EventifyPro::Client.new(api_key: 'secret', logger: Rails.logger)

async for publish

By default publishing will happen in async way in the separate thread. To publish event in synchronous way, just specify async: false option

client = EventifyPro::Client.new(api_key: 'secret')
client.publish(type: 'OrderCreated', data: { amount: 500 }, async: false)

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Eventify project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

Allows to publish events from Ruby-applications

http://eventify.pro

License:MIT License


Languages

Language:Ruby 99.1%Language:Shell 0.9%