TheKidCoder / Castle-Keep

Simplified version of the castle-rb gem. Minimized dependencies for maximum compatibility.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Castle::Keep

This is a minimal implementation of the Castle.io Server-Side API. This gem exists because the official castle-rb gem has quite a few external dependencies that can cause compatibility issues.

DEPRECATED.

This gem should not be used. The Official castle-rb gem has been updated to remove external dependencies.

The code for the initial version of this gem was taken directly from carlhoerberg's gist

Installation

Add this line to your application's Gemfile:

gem 'castle-keep'

Load and configure the library with your Castle API secret in an initializer or similar.

Castle.api_secret = 'YOUR_API_SECRET'

Usage

A new instance of Castle::Keep should be created for each request that comes through your stack. I recommend using a per-request global storage system like request_store

Rails Example:

class ApplicationController < ActionController::Base
  before_filter :_set_castle

  private
  def _set_castle
    RequestStore.store[:castle] = Castle::Keep.create_context(request)
  end
end

Once the helper is loaded you can then do:

begin
  RequestStore.store[:castle].track(
    name: '$login.succeeded',
    user_id: user.id)
rescue Castle::Error => e
  puts e.message
end

Development

After 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.

To 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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/thekidcoder/castle-keep.

About

Simplified version of the castle-rb gem. Minimized dependencies for maximum compatibility.


Languages

Language:Ruby 97.9%Language:Shell 2.1%