bullet-train-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83febba5a52e7d5602a6f1ffe57254707e930e9f
4
+ data.tar.gz: 2429172817181761da746db54512eebfa0e234d2
5
+ SHA512:
6
+ metadata.gz: acdd435953e9112efae4ec8c1e8f98b08ecd2c04474ea4373efbfc04f3df112023d9fd5a5ae54ab6f21e1ac3682e476df52e35478c1fc928e43c2b9b1f0aacd9
7
+ data.tar.gz: 1fcf557da0d03cbe3d1bb588e1652f85d43df2d75612af660e931c866c30bd7cb3859309787fb58693aaf4ecfffc3702f0711498eadb3c8909abca7bcb28b353
@@ -0,0 +1,57 @@
1
+ .vscode/*
2
+ !.vscode/settings.json
3
+ !.vscode/tasks.json
4
+ !.vscode/launch.json
5
+ !.vscode/extensions.json
6
+
7
+
8
+ *.gem
9
+ *.rbc
10
+ /.config
11
+ /coverage/
12
+ /InstalledFiles
13
+ /pkg/
14
+ /spec/reports/
15
+ /spec/examples.txt
16
+ /test/tmp/
17
+ /test/version_tmp/
18
+ /tmp/
19
+
20
+ # Used by dotenv library to load environment variables.
21
+ # .env
22
+
23
+ ## Specific to RubyMotion:
24
+ .dat*
25
+ .repl_history
26
+ build/
27
+ *.bridgesupport
28
+ build-iPhoneOS/
29
+ build-iPhoneSimulator/
30
+
31
+ ## Specific to RubyMotion (use of CocoaPods):
32
+ #
33
+ # We recommend against adding the Pods directory to your .gitignore. However
34
+ # you should judge for yourself, the pros and cons are mentioned at:
35
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
36
+ #
37
+ # vendor/Pods/
38
+
39
+ ## Documentation cache and generated files:
40
+ /.yardoc/
41
+ /_yardoc/
42
+ /doc/
43
+ /rdoc/
44
+
45
+ ## Environment normalization:
46
+ /.bundle/
47
+ /vendor/bundle
48
+ /lib/bundler/man/
49
+
50
+ # for a library or gem, you might want to ignore these files since the code is
51
+ # intended to run in multiple environments; otherwise, check them in:
52
+ # Gemfile.lock
53
+ # .ruby-version
54
+ # .ruby-gemset
55
+
56
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
57
+ .rvmrc
@@ -0,0 +1,15 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Debug Local File",
9
+ "type": "Ruby",
10
+ "request": "launch",
11
+ "cwd": "${workspaceRoot}",
12
+ "program": "${workspaceRoot}/lib/bullet-train.rb"
13
+ }
14
+ ]
15
+ }
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/SolidStateGroup/bullet-train-ruby-client" }
4
+
5
+ # Specify your gem's dependencies in bullet-train-ruby.gemspec
6
+ gemspec
data/LICENCE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (c) 2018 Solid State Technology Ltd (https://www.solidstategroup.com/) and individual contributors.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ 3. Neither the name of the Sentry nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,73 @@
1
+ <img width="100%" src="https://raw.githubusercontent.com/SolidStateGroup/bullet-train-frontend/master/hero.png"/>
2
+
3
+ # Bullet Train Client
4
+ The SDK clients for Ruby [https://bullet-train.io/](https://www.bullet-train.io/). Bullet Train allows you to manage feature flags and remote config across multiple projects, environments and organisations.
5
+
6
+ ## Getting Started
7
+
8
+ These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See running in production for notes on how to deploy the project on a live system.
9
+
10
+ ## Installing
11
+
12
+ ### VIA gem
13
+ ```gem install bullet-train-client```
14
+
15
+ ## Usage
16
+ **Retrieving feature flags for your project**
17
+
18
+ **For full documentation visit [https://docs.bullet-train.io](https://docs.bullet-train.io)**
19
+ ```ruby
20
+ require "bullet-train-ruby-client"
21
+
22
+ bt = BulletTrain.new(<<Your API KEY>>")
23
+
24
+ if bt.getValue("font_size")
25
+ # Do something awesome with the font size
26
+ end
27
+
28
+ if bt.hasFeature("does_not_exist")
29
+ #do something
30
+ else
31
+ #do nothing, or something else
32
+ end
33
+
34
+ ```
35
+ **Available Options**
36
+
37
+ | Property | Description | Required | Default Value |
38
+ | ------------- |:-------------:| -----:| -----:|
39
+ | ```environmentID``` | Defines which project environment you wish to get flags for. *example ACME Project - Staging.* | **YES** | null
40
+ | ```onError``` | Callback function on failure to retrieve flags. ``` (error)=>{...} ``` | **NO** | null
41
+ | ```defaultFlags``` | Defines the default flags if there are any | **NO** | null
42
+ | ```api``` | Use this property to define where you're getting feature flags from, e.g. if you're self hosting. | **NO** | https://bullet-train-api.dokku1.solidstategroup.com/api/v1/
43
+
44
+ **Available Functions**
45
+
46
+ | Property | Description |
47
+ | ------------- |:-------------:|
48
+ | ```init``` | Initialise the sdk against a particular environment
49
+ | ```hasFeature(key)``` | Get the value of a particular feature e.g. ```bulletTrain.hasFeature("powerUserFeature") // true```
50
+ | ```hasFeature(key, userId)``` | Get the value of a particular feature for a user e.g. ```bulletTrain.hasFeature("powerUserFeature", 1234) // true```
51
+ | ```getValue(key)``` | Get the value of a particular feature e.g. ```bulletTrain.getValue("font_size") // 10```
52
+ | ```getValue(keym userId)``` | Get the value of a particular feature for a specificed user e.g. ```bulletTrain.getValue("font_size", 1234) // 15```
53
+ | ```getFlags()``` | Trigger a manual fetch of the environment features, if a user is identified it will fetch their features
54
+ | ```getFlagsForUser(1234)``` | Trigger a manual fetch of the environment features with a given user id
55
+
56
+
57
+ **Identifying users**
58
+
59
+ Identifying users allows you to target specific users from the [Bullet Train dashboard](https://www.bullet-train.io/).
60
+ You can include an optional user identifier as part of the `hasFeature` and `getValue` methods to retrieve unique user flags and variables.
61
+
62
+
63
+ ## Contributing
64
+
65
+ Please read [CONTRIBUTING.md](https://gist.github.com/kyle-ssg/c36a03aebe492e45cbd3eefb21cb0486) for details on our code of conduct, and the process for submitting pull requests to us.
66
+
67
+ ## Getting Help
68
+
69
+ If you encounter a bug or feature request we would like to hear about it. Before you submit an issue please search existing issues in order to prevent duplicates.
70
+
71
+ ## Get in touch
72
+
73
+ If you have any questions about our projects you can email <a href="mailto:projects@solidstategroup.com">projects@solidstategroup.com</a>.
@@ -0,0 +1,11 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "bullet-train-client"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["Tom Stuart"]
5
+ spec.email = ["tom@solidstategroup.com"]
6
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
7
+
8
+ spec.summary = "Bullet Train - Ship features with confidence"
9
+ spec.description = "Ruby Client for Bullet-Train. Ship features with confidence using feature flags and remote config. Host yourself or use our hosted version at https://bullet-train.io"
10
+ spec.homepage = "https://bullet-train.io"
11
+ end
@@ -0,0 +1,76 @@
1
+ # require "bullet/train/ruby/version"
2
+ require "open-uri"
3
+ require "json"
4
+
5
+ class BulletTrainClient
6
+ @@apiUrl = ""
7
+ @@environmentKey = ""
8
+
9
+ def initialize(apiKey = nil, apiUrl = "https://api.bullet-train.io/api/v1/")
10
+ @@environmentKey = apiKey
11
+ @@apiUrl = apiUrl
12
+ end
13
+
14
+ def getJSON(method = nil)
15
+ response = open(@@apiUrl + "" + method.concat("?format=json"),
16
+ "x-environment-key" => @@environmentKey).read
17
+ return JSON.parse(response)
18
+ end
19
+
20
+ def processFlags(inputFlags)
21
+ flags = {}
22
+
23
+ for feature in inputFlags
24
+ featureName = feature["feature"]["name"].downcase.gsub(/\s+/, "_")
25
+ enabled = feature["enabled"]
26
+ state = feature["feature_state_value"]
27
+ flags[featureName] = {"enabled" => enabled, "value" => state}
28
+
29
+ return flags
30
+ end
31
+
32
+ return flags
33
+ end
34
+
35
+ def getFlagsForUser(identity = nil)
36
+ processFlags(getJSON("flags/#{identity}"))
37
+ end
38
+
39
+ def getFlags()
40
+ processFlags(getJSON("flags"))
41
+ end
42
+
43
+ def getValue(key, userId = nil)
44
+ flags = nil
45
+ # Get the features
46
+ if userId != nil
47
+ flags = getFlagsForUser(userId)
48
+ else
49
+ flags = getFlags()
50
+ end
51
+ # Return the value
52
+ return flags[key]["value"]
53
+ end
54
+
55
+ def hasFeature(key, userId = nil)
56
+ # Get the features
57
+ flags = nil
58
+ if userId != nil
59
+ flags = getFlagsForUser(userId)
60
+ else
61
+ flags = getFlags()
62
+ end
63
+
64
+ # Work out if this feature exists
65
+ if flags[key] == nil
66
+ return false
67
+ else
68
+ return flags[key]["enabled"]
69
+ end
70
+ end
71
+ end
72
+
73
+ # bt = BulletTrain.new("QjgYur4LQTwe5HpvbvhpzK")
74
+ # print bt.getFlags()
75
+ # print bt.getValue("font_size")
76
+ # print bt.hasFeature("font_size")
data/test.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "bullet-train"
2
+
3
+ bt = BulletTrain.new("QjgYur4LQTwe5HpvbvhpzK")
4
+
5
+ if bt.getValue("font_size")
6
+ # Do something awesome with the font size
7
+ puts bt.getValue("font_size")
8
+ end
9
+
10
+ if bt.hasFeature("does_not_exist")
11
+ #do something
12
+ else
13
+ #do nothing, or something else
14
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bullet-train-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tom Stuart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby Client for Bullet-Train. Ship features with confidence using feature
14
+ flags and remote config. Host yourself or use our hosted version at https://bullet-train.io
15
+ email:
16
+ - tom@solidstategroup.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".vscode/launch.json"
23
+ - Gemfile
24
+ - LICENCE
25
+ - README.md
26
+ - bullet-train-ruby.gemspec
27
+ - lib/bullet-train.rb
28
+ - test.rb
29
+ homepage: https://bullet-train.io
30
+ licenses: []
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.5.2
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Bullet Train - Ship features with confidence
52
+ test_files: []