bullet-train-client 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: a5c47e0b0313009db4ae84b4721fa39b87bc38f4660414a8ae8902520a204354
4
- data.tar.gz: acc7b67eb95509fe392efea7f258bd19fdf4a84c10c4fe3f7e50bd89363dc10a
2
+ SHA1:
3
+ metadata.gz: 700fb806fd2257ec039e885707d1d9d12e9b1d30
4
+ data.tar.gz: 9ab26fd436b94bb1d84a065c3dc8f38fe53e037c
5
5
  SHA512:
6
- metadata.gz: 5df011ddd786de343625b5a21b9e4b2067b6aa2e3c253c0f83dacc7d13211a8f47961eaef24014d91a440add3c693033fe57f211b4354b11ddd159ce1d8233b6
7
- data.tar.gz: f0134af7e9ce7a6b469b2978521336b30b08d08aff1bbffbadd7d33cfd1b30d17a5bb6f65b5d56aadf7834a5bb278cab0c81a956588f40bd4e464143ab35f6a5
6
+ metadata.gz: 50b6ec8f1f47c6c739fc83109aa3d517c2f28342cb0e785e192c1dd01d1857e8b337d9d1c72b2107f2dbee8c44c1996c9c6d492328a4c4e546bb774ead7f4611
7
+ data.tar.gz: f70d01cc775ddb42cf159bfa48df3b225cc5b33385c43c16e8fcf583372f8c4649b2209d90ca162ee26c576f6cd017ce41672e8fb77e4ca49f98b87858cb67e0
@@ -0,0 +1,5 @@
1
+ inherit_from: .rubocop_todo.yml
2
+ Layout/HashAlignment:
3
+ AllowMultipleStyles: true
4
+ EnforcedColonStyle: separator
5
+
@@ -0,0 +1,97 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2020-01-16 04:57:18 -1000 using RuboCop version 0.79.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 3
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: EnforcedStyle, IndentationWidth.
12
+ # SupportedStyles: special_inside_parentheses, consistent, align_braces
13
+ Layout/FirstHashElementIndentation:
14
+ Exclude:
15
+ - 'lib/bullet_train.rb'
16
+ - 'spec/bullet_train_spec.rb'
17
+
18
+ # Offense count: 8
19
+ # Cop supports --auto-correct.
20
+ # Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
21
+ # SupportedHashRocketStyles: key, separator, table
22
+ # SupportedColonStyles: key, separator, table
23
+ # SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
24
+ Layout/HashAlignment:
25
+ Exclude:
26
+ - 'lib/bullet_train.rb'
27
+ - 'spec/bullet_train_spec.rb'
28
+
29
+ # Offense count: 2
30
+ # Cop supports --auto-correct.
31
+ Layout/SpaceAroundKeyword:
32
+ Exclude:
33
+ - 'spec/bullet_train_spec.rb'
34
+
35
+ # Offense count: 1
36
+ # Cop supports --auto-correct.
37
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
38
+ # SupportedStyles: space, no_space
39
+ # SupportedStylesForEmptyBraces: space, no_space
40
+ Layout/SpaceInsideBlockBraces:
41
+ Exclude:
42
+ - 'Gemfile'
43
+
44
+ # Offense count: 1
45
+ # Cop supports --auto-correct.
46
+ # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
47
+ Lint/UnusedBlockArgument:
48
+ Exclude:
49
+ - 'Gemfile'
50
+
51
+ # Offense count: 1
52
+ # Configuration parameters: CountComments, ExcludedMethods.
53
+ # ExcludedMethods: refine
54
+ Metrics/BlockLength:
55
+ Max: 111
56
+
57
+ # Offense count: 1
58
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
59
+ # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
60
+ Naming/FileName:
61
+ Exclude:
62
+ - 'lib/bullet-train.rb'
63
+
64
+ # Offense count: 3
65
+ # Cop supports --auto-correct.
66
+ # Configuration parameters: EnforcedStyle.
67
+ # SupportedStyles: always, never
68
+ Style/FrozenStringLiteralComment:
69
+ Exclude:
70
+ - 'Gemfile'
71
+ - 'Rakefile'
72
+ - 'bullet-train-ruby.gemspec'
73
+
74
+ # Offense count: 1
75
+ # Cop supports --auto-correct.
76
+ # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
77
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
78
+ Style/HashSyntax:
79
+ Exclude:
80
+ - 'Rakefile'
81
+
82
+ # Offense count: 13
83
+ # Cop supports --auto-correct.
84
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
85
+ # SupportedStyles: single_quotes, double_quotes
86
+ Style/StringLiterals:
87
+ Exclude:
88
+ - 'Gemfile'
89
+ - 'Rakefile'
90
+ - 'bullet-train-ruby.gemspec'
91
+
92
+ # Offense count: 11
93
+ # Cop supports --auto-correct.
94
+ # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
95
+ # URISchemes: http, https
96
+ Layout/LineLength:
97
+ Max: 188
data/README.md CHANGED
@@ -11,7 +11,7 @@ These instructions will get you a copy of the project up and running on your loc
11
11
 
12
12
  ### VIA gem
13
13
  ```gem install bullet-train-client```
14
-
14
+
15
15
  ## Usage
16
16
  **Retrieving feature flags for your project**
17
17
 
@@ -21,11 +21,11 @@ require "bullet-train-ruby-client"
21
21
 
22
22
  bt = BulletTrain.new("<<Your API KEY>>")
23
23
 
24
- if bt.getValue("font_size")
24
+ if bt.get_value("font_size")
25
25
  # Do something awesome with the font size
26
26
  end
27
27
 
28
- if bt.hasFeature("does_not_exist")
28
+ if bt.feature_enabled?("does_not_exist")
29
29
  #do something
30
30
  else
31
31
  #do nothing, or something else
@@ -36,22 +36,20 @@ end
36
36
 
37
37
  | Property | Description | Required | Default Value |
38
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/
39
+ | ```api_key``` | Defines which project environment you wish to get flags for. *example ACME Project - Staging.* | **YES** | null
40
+ | ```url``` | 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
41
 
44
42
  **Available Functions**
45
43
 
46
- | Property | Description |
44
+ | Property | Description |
47
45
  | ------------- |:-------------:|
48
46
  | ```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
47
+ | ```feature_enabled?(key)``` | Get the value of a particular feature e.g. ```bulletTrain.feature_enabled?("powerUserFeature") // true```
48
+ | ```feature_enabled?(key, user_id, default = false)``` | Get the value of a particular feature for a user e.g. ```bulletTrain.feature_enabled?("powerUserFeature", 1234) // true```
49
+ | ```get_value(key)``` | Get the value of a particular feature e.g. ```bulletTrain.get_value("font_size") // 10```
50
+ | ```get_value(key, user_id, default = nil)``` | Get the value of a particular feature for a specificed user e.g. ```bulletTrain.get_value("font_size", 1234) // 15```
51
+ | ```get_flags()``` | Trigger a manual fetch of the environment features, if a user is identified it will fetch their features
52
+ | ```get_flags(user_id)``` | Trigger a manual fetch of the environment features with a given user id
55
53
 
56
54
 
57
55
  **Identifying users**
@@ -66,7 +64,7 @@ Please read [CONTRIBUTING.md](https://gist.github.com/kyle-ssg/c36a03aebe492e45c
66
64
 
67
65
  ## Getting Help
68
66
 
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.
67
+ 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
68
 
71
69
  ## Get in touch
72
70
 
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "bullet-train-client"
3
- spec.version = "1.1.0"
4
- spec.authors = ["Tom Stuart"]
5
- spec.email = ["tom@solidstategroup.com"]
3
+ spec.version = "1.1.1"
4
+ spec.authors = ["Tom Stuart", "Brian Moelk"]
5
+ spec.email = ["tom@solidstategroup.com", "bmoelk@gmail.com"]
6
6
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
7
7
 
8
8
  spec.summary = "Bullet Train - Ship features with confidence"
@@ -10,7 +10,10 @@ Gem::Specification.new do |spec|
10
10
  spec.homepage = "https://bullet-train.io"
11
11
 
12
12
  spec.add_development_dependency 'bundler'
13
+ spec.add_development_dependency 'gem-release'
13
14
  spec.add_development_dependency 'rake'
14
15
  spec.add_development_dependency 'rspec'
16
+ spec.add_development_dependency 'rubocop'
15
17
  spec.add_dependency 'faraday'
18
+ spec.add_dependency 'faraday_middleware'
16
19
  end
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'faraday'
4
+ require 'faraday_middleware'
3
5
 
6
+ # Ruby client for bullet-train.io
4
7
  class BulletTrain
5
8
  attr_reader :bt_api
6
9
 
7
10
  def initialize(opts = {})
8
- @opts = {
9
- api_key: opts[:api_key] || self.class.api_key,
10
- url: opts[:url] || self.class.api_url
11
- }
11
+ @opts = determine_opts(opts)
12
12
 
13
13
  @bt_api = Faraday.new(url: @opts[:url]) do |faraday|
14
14
  faraday.headers['Accept'] = 'application/json'
@@ -48,7 +48,12 @@ class BulletTrain
48
48
  def set_trait(user_id, trait, value)
49
49
  raise StandardError, 'user_id cannot be nil' if user_id.nil?
50
50
 
51
- res = @bt_api.post('traits/', { identity: { identifier: user_id }, trait_key: normalize_key(trait), trait_value: value }.to_json)
51
+ trait = {
52
+ identity: { identifier: user_id },
53
+ trait_key: normalize_key(trait),
54
+ trait_value: value
55
+ }
56
+ res = @bt_api.post('traits/', trait.to_json)
52
57
  res.body
53
58
  end
54
59
 
@@ -86,7 +91,10 @@ class BulletTrain
86
91
 
87
92
  def traits_to_hash(user_flags)
88
93
  result = {}
89
- user_flags['traits']&.each { |t| result[normalize_key(t['trait_key'])] = t['trait_value'] }
94
+ user_flags['traits']&.each do |t|
95
+ key = normalize_key(t['trait_key'])
96
+ result[key] = t['trait_value']
97
+ end
90
98
  result
91
99
  end
92
100
 
@@ -94,10 +102,19 @@ class BulletTrain
94
102
  key.to_s.downcase
95
103
  end
96
104
 
97
- alias :hasFeature :feature_enabled?
98
- alias :getValue :get_value
99
- alias :getFlags :get_flags
100
- alias :getFlagsForUser :get_flags
105
+ def determine_opts(opts)
106
+ opts = { api_key: opts } if opts.is_a? String
107
+
108
+ {
109
+ api_key: opts[:api_key] || self.class.api_key,
110
+ url: opts[:url] || self.class.api_url
111
+ }
112
+ end
113
+
114
+ alias hasFeature feature_enabled?
115
+ alias getValue get_value
116
+ alias getFlags get_flags
117
+ alias getFlagsForUser get_flags
101
118
 
102
119
  def self.api_key
103
120
  ENV['BULLETTRAIN_API_KEY']
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet-train-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Stuart
8
+ - Brian Moelk
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2020-01-16 00:00:00.000000000 Z
12
+ date: 2020-01-17 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -24,6 +25,20 @@ dependencies:
24
25
  - - ">="
25
26
  - !ruby/object:Gem::Version
26
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: gem-release
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
27
42
  - !ruby/object:Gem::Dependency
28
43
  name: rake
29
44
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +67,20 @@ dependencies:
52
67
  - - ">="
53
68
  - !ruby/object:Gem::Version
54
69
  version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rubocop
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
55
84
  - !ruby/object:Gem::Dependency
56
85
  name: faraday
57
86
  requirement: !ruby/object:Gem::Requirement
@@ -66,15 +95,32 @@ dependencies:
66
95
  - - ">="
67
96
  - !ruby/object:Gem::Version
68
97
  version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: faraday_middleware
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
69
112
  description: Ruby Client for Bullet-Train. Ship features with confidence using feature
70
113
  flags and remote config. Host yourself or use our hosted version at https://bullet-train.io
71
114
  email:
72
115
  - tom@solidstategroup.com
116
+ - bmoelk@gmail.com
73
117
  executables: []
74
118
  extensions: []
75
119
  extra_rdoc_files: []
76
120
  files:
77
121
  - ".gitignore"
122
+ - ".rubocop.yml"
123
+ - ".rubocop_todo.yml"
78
124
  - Gemfile
79
125
  - LICENCE
80
126
  - README.md
@@ -100,7 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
146
  - !ruby/object:Gem::Version
101
147
  version: '0'
102
148
  requirements: []
103
- rubygems_version: 3.0.4
149
+ rubyforge_project:
150
+ rubygems_version: 2.6.14
104
151
  signing_key:
105
152
  specification_version: 4
106
153
  summary: Bullet Train - Ship features with confidence