trailguide 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12093bc501e3daa2a035ad59e2ecc118a2bf9839b6db852763ae52e3e41ffd3a
4
- data.tar.gz: c40a654b9ec80c1dc602563647bfd23c9fdfe090b0bc43c2457d7c1e0f1ee1b4
3
+ metadata.gz: bcb676051862d84d744bf4a84c60adcd1ccba36b0cf319bc3c37c2f3ae774a0e
4
+ data.tar.gz: 7397a453afdef82edc8ced81f1a54b342324aaf508adcc5d159e0efb2bb958a0
5
5
  SHA512:
6
- metadata.gz: 100f0c9b8cb8f13cf98f3445afac2ab406bab9ad895a89947f0d7d7199eb7034b0fd29d75a993cc9f5c68d52894b38933438cf00ce3371bc18de122d1b365c98
7
- data.tar.gz: 1a5044225a220f9f1e0263953cb0a3019d96b3f4f43d5f2f0913b06809f0c4e13acc9ec3aa91778df669aba16984b8c60e59a6091e05055bec6b1a72e62fbc75
6
+ metadata.gz: fd5fdd35dd59f7fe8ea812c08d6773850ab0d9acec0a1a20da5d55db3f690bd43ea7aa11126d0a78408059fdef7940fec78504a43ae6d82caac897e11f75bcf0
7
+ data.tar.gz: 5042d43b78c5ef826854627308632e6db970d755963bc6c7c96e10060ea0ea0f09f42f6b6c0462c38845a708afc3456312cc412b8b513995ba2caa834d698127
data/README.md CHANGED
@@ -590,24 +590,114 @@ If you're using a custom adapter, you'll need to make sure that your adapter is
590
590
 
591
591
  ## JavaScript Client
592
592
 
593
- There is a simple javascript client available that mimics the ruby usage as closely as possible, and is ready to be used with the rails asset pipeline. This client uses axios to hit the API, and requires that you mount it in your routes.
593
+ There is a simple javascript client available that mimics the ruby usage as closely as possible, and is ready to be used with the rails asset pipeline or via webpack. This client uses axios to hit the API, and requires that you mount it in your routes.
594
+
595
+ ```ruby
596
+ # config/routes.rb
597
+
598
+ Rails.application.routes.draw do
599
+
600
+ mount TrailGuide::Engine => 'api/experiments'
601
+
602
+ # ...
603
+ end
604
+ ```
605
+
606
+ ### Rails Asset Pipeline
607
+
608
+ If you're using the rails asset pipeline, just require trailguide in your `application.js` and instantiate a client.
594
609
 
595
610
  ```javascript
596
- // require the trailguide client in your application.js or wherever makes sense
611
+ // require the trailguide client in your application.js or wherever makes sense for your project
597
612
  //= require trailguide
598
613
 
599
614
  // create a client instance
600
615
  // make sure to pass in the route path where you've mounted the trailguide engine
601
616
  var client = TrailGuide.client('/api/experiments');
617
+ ```
618
+
619
+ The client is just a wrapper around `axios`, so you can provide any of their [request configuration options](https://github.com/axios/axios#request-config).
620
+
621
+ ```javascript
622
+ var client = TrailGuide.client({
623
+ baseURL: '/api/experiments',
624
+ headers: {...},
625
+ transformRequest: (data,headers) => (...)
626
+ });
627
+ ```
628
+
629
+ ### Webpack
630
+
631
+ If you're using webpack, you can install the corresponding `trailguide` npm package with `yarn` or `npm`:
632
+
633
+ ```
634
+ yarn add trailguide
635
+ ```
636
+
637
+ ```
638
+ npm install trailguide
639
+ ```
602
640
 
641
+ Then use it in your project:
642
+
643
+ ```javascript
644
+ import { client } from 'trailguide'
645
+
646
+ // create a client instance
647
+ // make sure to pass in the route path where you've mounted the trailguide engine
648
+ export default client('/api/experiments')
649
+ ```
650
+
651
+ ```javascript
652
+ var TrailGuide = require('trailguide');
653
+
654
+ module.exports = {
655
+ // create a client instance
656
+ // make sure to pass in the route path where you've mounted the trailguide engine
657
+ client: TrailGuide.client('/api/experiments')
658
+ };
659
+ ```
660
+
661
+ The client is just a wrapper around `axios`, so you can provide any of their [request configuration options](https://github.com/axios/axios#request-config).
662
+
663
+ ```javascript
664
+ client({
665
+ baseURL: '/api/experiments',
666
+ headers: {...},
667
+ transformRequest: (data,headers) => (...)
668
+ })
669
+ ```
670
+
671
+ ### Usage
672
+
673
+ Once you have a handle on a client, the usage is the same. All methods return a promise with the `response` as a payload.
674
+
675
+ ```javascript
603
676
  // enroll in an experiment
604
- client.choose('experiment_name');
677
+ client.choose('experiment_name', {...optional_metadata...}).then(response => {
678
+ // response.data will be:
679
+ // { experiment: "experiment_name", variant: "assigned_variant_name", metadata: {...} }
680
+ })
605
681
 
606
682
  // convert for an experiment with an optional goal
607
- client.convert('experiment_name', 'optional_goal');
683
+ client.convert('experiment_name', 'optional_goal', {...optional_metadata...}).then(response => {
684
+ // response.data will be:
685
+ // { experiment: "experiment_name", checkpoint: "optional_goal", metadata: {...} }
686
+ })
608
687
 
609
688
  // return the participant's active experiments and their assigned variant group
610
- client.active();
689
+ client.active().then(response => {
690
+ // response.data will be:
691
+ // { experiments: { experiment_name: "assigned_variant_name" } }
692
+ })
693
+ ```
694
+
695
+ The client is just a wrapper around `axios`, and all the client methods support any of their [request configuration options](https://github.com/axios/axios#request-config) as the last argument.
696
+
697
+ ```javascript
698
+ client.active({ headers: {...}, transformRequest: (data,headers) => (...) }).then(...)
699
+ client.choose('experiment_name', {...optional_metadata...}, { headers: {...}, transformRequest: (data,headers) => (...) }).then(...)
700
+ client.convert('experiment_name', 'optional_goal', {...optional_metadata...}, { headers: {...}, transformRequest: (data,headers) => (...) }).then(...)
611
701
  ```
612
702
 
613
703
  ## Conversion Goals
@@ -71,6 +71,7 @@ module TrailGuide
71
71
  :storage_key, :combined?, :start_manually?, :reset_manually?,
72
72
  :allow_multiple_conversions?, :allow_multiple_goals?, :is_combined?,
73
73
  :enable_calibration?, :track_winner_conversions?, :callbacks, to: :class
74
+ delegate :context, to: :participant
74
75
 
75
76
  def initialize(participant)
76
77
  @participant = Experiments::Participant.new(self, participant)
@@ -2,6 +2,7 @@ module TrailGuide
2
2
  module Experiments
3
3
  class Participant
4
4
  attr_reader :experiment, :participant
5
+ delegate :context, to: :participant
5
6
 
6
7
  def initialize(experiment, participant)
7
8
  @experiment = experiment
@@ -2,7 +2,7 @@ module TrailGuide
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- PATCH = 0
5
+ PATCH = 1
6
6
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
 
8
8
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailguide
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rebec