Git Product home page Git Product logo

sixpack-rb's Introduction

Sixpack

Build Status

Ruby client library for SeatGeek's Sixpack ab testing framework.

Requirements

  • Ruby 1.9.3+ (2.x tested via travis)

Installation

Add this line to your application's Gemfile:

gem 'sixpack-client'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sixpack-client

Usage

Basic example:

require 'sixpack'

session = Sixpack::Session.new

# Participate in a test (creates the test if necessary)
resp = session.participate("new-test", ["alternative-1", "alternative-2"])
if resp["alternative"]["name"] == "alternative-1"
    css_style = "blue"
end

# Convert
session.convert("new-test")

Each session has a client_id associated with it that must be preserved across requests. Here's what the first request might look like:

session = Sixpack::Session.new
session.participate("new-test", ["alternative-1", "alternative-2"])
set_cookie_in_your_web_framework("sixpack-id", session.client_id)

For future requests, create the Session using the client_id stored in the cookie:

client_id = get_cookie_from_web_framework("sixpack-id")
session = Sixpack::Session.new(client_id)
session.convert("new-test")

Sessions can take an optional options hash that takes :base_url, and a params hash that takes :ip_address, and :user_agent a keys. If you would like to instantiate a session with a known client id, you can do that here. IP address and user agent can be passed to assist in bot detection.

options = {
    :base_url => 'http://mysixpacklocation.com'
}
params = {
    :ip_address => '1.2.3.4'
}
session = Session(client_id="123", options=options, params=params)

If Sixpack is unreachable or other errors occur, sixpack-rb will provide the control alternative object.

Configuration

You can configure the Sixpack in the configure block:

Sixpack.configure do |config|
  config.base_url = 'http://10.20.30.40:5000'
end

You can use the configure block when initializing your app, for instance in a Rails initializer.

Note that options, passed directly into Session constructor override the configuration options.

Sixpack.configure do |config|
  config.base_url = 'http://foo:5000'
end

s = Sixpack::Session.new(id, base_url: 'http://bar:6000')

expect(s.base_url).to eq 'http://bar:6000' #=> true

Configuration options

  • base_url - to set the base_url for the sixpack API server (can be overriden in the Session constructor)
  • user - set http basic authentication user
  • password - set http basic authentication password

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Write and run some tests with $ rake
  4. Commit your changes (git commit -am 'Added some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

sixpack-rb's People

Contributors

zackkitzmiller avatar mdirolf avatar dougdroper avatar jack7890 avatar subosito avatar erwaller avatar josegonzalez avatar sylg 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.