funneler 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 880aa82cecc26ab6df5c7a41625912a754581fe1
4
+ data.tar.gz: 163ec38d0b55d418d96a6b922706aaf1a109edc8
5
+ SHA512:
6
+ metadata.gz: 4a92f2ffde57b6a756699bb8842e2fabd99083f5eb46c5c16341acf17ffad426c430d7642db85b4ee412e949f58d13611a9df0846c3633232543732d445fb104
7
+ data.tar.gz: cbd8d719e15c1db8d7b333e027e60c384f0cf527ce47acc8df7056d2917ece1582fbd99b90ba25fe57a90869e2060c6325e8a7925b7f81d72cf836c70e1b41ee
data/CHANGELOG ADDED
@@ -0,0 +1,2 @@
1
+ v1.0
2
+ - Initial release of gem
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,31 @@
1
+ # Contributing
2
+
3
+ We welcome contributions to this repository. Feel free to submit issues for bugs you encounter and pull requests for code and documentation contributions.
4
+
5
+ In order to prevent licensing issues, we require all contributors to sign an individual contributor license agreement, which is reproduced below:
6
+
7
+ ## Individual Contributor License Agreement
8
+
9
+ In order to clarify the intellectual property license granted with Contributions from any person or entity, Doximity, Inc. ("Doximity") must have a Contributor License Agreement ("CLA") on file that has been signed by each Contributor, indicating agreement to the license terms below. This license is for your protection as a Contributor as well as the protection of Doximity; it does not change your rights to use your own Contributions for any other purpose.
10
+
11
+ You accept and agree to the following terms and conditions for Your present and future Contributions submitted to Doximity. Except for the license granted herein to Doximity and recipients of software distributed by Doximity, You reserve all right, title, and interest in and to Your Contributions.
12
+
13
+ ### Definitions
14
+
15
+ "You" (or "Your") shall mean the copyright owner or legal entity authorized by the copyright owner that is making this Agreement with Doximity. For legal entities, the entity making a Contribution and all other entities that control, are controlled by, or are under common control with that entity are considered to be a single Contributor. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16
+
17
+ 1. "Contribution" shall mean any original work of authorship, including any modifications or additions to an existing work, that is intentionally submitted by You to Doximity for inclusion in, or documentation of, any of the products owned or managed by Doximity (the "Work"). For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to Doximity or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, Doximity for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by You as "Not a Contribution."
18
+
19
+ 2. Grant of Copyright License. Subject to the terms and conditions of this Agreement, You hereby grant to Doximity and to recipients of software distributed by Doximity a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works.
20
+
21
+ 3. Grant of Patent License. Subject to the terms and conditions of this Agreement, You hereby grant to Doximity and to recipients of software distributed by Doximity a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by You that are necessarily infringed by Your Contribution(s) alone or by combination of Your Contribution(s) with the Work to which such Contribution(s) was submitted. If any entity institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a lawsuit) alleging that your Contribution, or the Work to which you have contributed, constitutes direct or contributory patent infringement, then any patent licenses granted to that entity under this Agreement for that Contribution or Work shall terminate as of the date such litigation is filed.
22
+
23
+ 4. You represent that you are legally entitled to grant the above license. If your employer(s) has rights to intellectual property that you create that includes your Contributions, you represent that you have received permission to make Contributions on behalf of that employer, that your employer has waived such rights for your Contributions to Doximity, or that your employer has executed a separate Corporate CLA with Doximity.
24
+
25
+ 5. You represent that each of Your Contributions is Your original creation (see section 7 for submissions on behalf of others). You represent that Your Contribution submissions include complete details of any third-party license or other restriction (including, but not limited to, related patents and trademarks) of which you are personally aware and which are associated with any part of Your Contributions.
26
+
27
+ 6. You are not expected to provide support for Your Contributions, except to the extent You desire to provide support. You may provide support for free, for a fee, or not at all. Unless required by applicable law or agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON- INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
28
+
29
+ 7. Should You wish to submit work that is not Your original creation, You may submit it to Doximity separately from any Contribution, identifying the complete details of its source and of any license or other restriction (including, but not limited to, related patents, trademarks, and license agreements) of which you are personally aware, and conspicuously marking the work as "Submitted on behalf of a third-party: [[]named here]".
30
+
31
+ 8. You agree to notify Doximity of any facts or circumstances of which you become aware that would make these representations inaccurate in any respect.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ funneler (1.0.1)
5
+ jwt
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (8.2.1)
11
+ coderay (1.1.0)
12
+ diff-lcs (1.2.5)
13
+ jwt (1.5.4)
14
+ method_source (0.8.2)
15
+ pry (0.10.3)
16
+ coderay (~> 1.1.0)
17
+ method_source (~> 0.8.1)
18
+ slop (~> 3.4)
19
+ pry-byebug (3.3.0)
20
+ byebug (~> 8.0)
21
+ pry (~> 0.10)
22
+ rake (10.5.0)
23
+ rspec (3.4.0)
24
+ rspec-core (~> 3.4.0)
25
+ rspec-expectations (~> 3.4.0)
26
+ rspec-mocks (~> 3.4.0)
27
+ rspec-core (3.4.1)
28
+ rspec-support (~> 3.4.0)
29
+ rspec-expectations (3.4.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.4.0)
32
+ rspec-mocks (3.4.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.4.0)
35
+ rspec-support (3.4.1)
36
+ slop (3.6.0)
37
+ timecop (0.8.0)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bundler (~> 1.11)
44
+ funneler!
45
+ pry-byebug
46
+ rake (~> 10.0)
47
+ rspec (~> 3.0)
48
+ timecop
49
+
50
+ BUNDLED WITH
51
+ 1.13.4
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2016 Doximity, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Funneler
2
+
3
+ A simple gem for helping coordinate moving a user through a set of
4
+ routes. The gem uses a token to keep track of the current place in the funnel.
5
+ The simplest way to use that token is by including a module into the controller
6
+ and passing the token in the route. However since the token is simply a string
7
+ it can easily be kept in session or any other datastore if needed.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'funneler'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install funneler
24
+
25
+ ## Usage
26
+
27
+ 1. Add the gem to your web application. The gem is not dependent upon
28
+ any particular framework. It's only dependency is the [`jwt` gem](https://github.com/jwt/ruby-jwt]
29
+
30
+ 2. Generate a token for a given set of routes, and route your user to
31
+ the first page:
32
+ ```ruby
33
+ funnel = Funneler.build(routes: ['/welcome', '/setup', '/complete'])
34
+ redirect_to funnel.first_page
35
+ ```
36
+
37
+ 3. Modify those pages to include the `Funneler::ControllerMethods`
38
+ helper for reconstituting a funnel from the given token
39
+
40
+ 4. Use the helper to determine the next page like this:
41
+ ```erb
42
+ <%= link_to funnel.next_page, "Next" %>
43
+ ```
44
+
45
+ ## Details
46
+
47
+ The `Funneler::Funnel` is the core maintaining the state of the flow of
48
+ pages and building the paths with valid tokens.
49
+
50
+
51
+ ## Development
52
+
53
+ 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.
54
+
55
+ 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](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/doximity/funneler. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
60
+
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "funneler"
5
+
6
+ require "pry"
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/funneler.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'funneler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "funneler"
8
+ spec.version = Funneler::VERSION
9
+ spec.authors = ["Ryan Stawarz"]
10
+ spec.email = ["ryan@stawarz.com"]
11
+
12
+ spec.summary = %q{A light-weight approach for routing users through a pre-determined set of routes.}
13
+ spec.description = %q{}
14
+ spec.homepage = "https://github.com/doximity/funneler"
15
+ spec.license = "Apache 2.0"
16
+
17
+ spec.files = Dir['.rspec', 'CHANGELOG', 'CONTRIBUTING.md', 'Gemfile', 'Gemfile.lock', 'LICENSE.txt', 'README.md', 'Rakefile', 'bin/*', 'funneler.gemspec', 'lib/**/*'].select { |f| File.file?(f) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'jwt'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "timecop"
28
+ spec.add_development_dependency "pry-byebug"
29
+ end
@@ -0,0 +1,13 @@
1
+ module Funneler
2
+ class Configuration
3
+ attr_accessor :jwt_key,
4
+ :jwt_algorithm,
5
+ :expires_in_days
6
+
7
+ def initialize(options = {})
8
+ @jwt_key = options[:jwt_key]
9
+ @jwt_algorithm = options[:jwt_algorithm]
10
+ @expires_in_days = options.fetch(:expires_in_days, 14)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Funneler
2
+ module ControllerMethods
3
+ def funnel
4
+ @funnel ||= Funneler.from_token(token: params[:funnel_token])
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,79 @@
1
+ module Funneler
2
+ class Funnel
3
+
4
+ attr_reader :data
5
+
6
+ def initialize(data = {})
7
+ @data = data
8
+ @url_cache = Hash.new {|h, key| h[key] = generate_page_for_index(key) }
9
+ end
10
+
11
+ def first_page(additional_params = {})
12
+ url = @url_cache[0]
13
+ return url if additional_params.empty?
14
+
15
+ add_params_to_url(url, additional_params)
16
+ end
17
+
18
+ def next_page
19
+ @url_cache[next_index]
20
+ end
21
+
22
+ def previous_page
23
+ @url_cache[previous_index]
24
+ end
25
+
26
+ def is_last_page?
27
+ routes.empty? || (current_page_index + 1) >= routes.length
28
+ end
29
+
30
+ def current_page
31
+ @url_cache[current_page_index]
32
+ end
33
+
34
+ def current_page_index
35
+ data.fetch('current_page_index', 0)
36
+ end
37
+
38
+ def token
39
+ TokenHandler.generate_token(data: data)
40
+ end
41
+
42
+ private
43
+
44
+ def generate_page_for_index(index)
45
+ return if bad_index?(index)
46
+
47
+ token = TokenHandler.generate_token(data: data.merge('current_page_index' => index))
48
+ add_params_to_url(routes[index], "funnel_token" => token)
49
+ end
50
+
51
+ def add_params_to_url(path, new_params)
52
+ uri = URI.parse(path)
53
+ params = URI.decode_www_form(uri.query || "").concat(new_params.to_a)
54
+ uri.query = URI.encode_www_form(params)
55
+
56
+ uri.to_s
57
+ end
58
+
59
+ def routes
60
+ data.fetch('routes', [])
61
+ end
62
+
63
+ def next_index
64
+ current_page_index + 1
65
+ end
66
+
67
+ def previous_index
68
+ index = current_page_index - 1
69
+ index < 0 ? 0 : index
70
+ end
71
+
72
+ def bad_index?(index)
73
+ index.nil? ||
74
+ index < 0 ||
75
+ index >= routes.length
76
+ end
77
+ end
78
+ end
79
+
@@ -0,0 +1,13 @@
1
+ module Funneler
2
+ class FunnelFactory
3
+
4
+ class << self
5
+ def build(route_generator:, params: {}, expires_in_days: nil)
6
+ return nil unless route_generator.respond_to?(:call)
7
+
8
+ routes = route_generator.call(params)
9
+ Funnel.new('routes' => routes, 'expires_in_days' => expires_in_days)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ require 'jwt'
2
+
3
+ module Funneler
4
+ class TokenHandler
5
+ class << self
6
+ def generate_token(data:, expires_in_days: nil)
7
+ key = Funneler.configuration.jwt_key
8
+ algorithm = Funneler.configuration.jwt_algorithm
9
+
10
+ expires_in_days ||= Funneler.configuration.expires_in_days
11
+ if expires_in_days
12
+ expiration = Time.now + (expires_in_days * 24 * 60 * 60)
13
+ data = { exp: expiration.to_i }.merge(data)
14
+ end
15
+
16
+ JWT.encode(data, key, algorithm)
17
+ end
18
+
19
+ def extract_data_from(token)
20
+ key = Funneler.configuration.jwt_key
21
+ algorithm = Funneler.configuration.jwt_algorithm
22
+ verify = (algorithm != nil || key != nil)
23
+ data, _ = JWT.decode(token, key, verify, algorithm: algorithm)
24
+ data
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Funneler
2
+ VERSION = "1.0.1"
3
+ end
data/lib/funneler.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'jwt'
2
+
3
+ require "funneler/version"
4
+ require "funneler/configuration"
5
+ require "funneler/token_handler"
6
+ require "funneler/funnel"
7
+ require "funneler/funnel_factory"
8
+ require "funneler/controller_methods"
9
+
10
+ module Funneler
11
+ Error = Class.new(StandardError)
12
+ InvalidTokenError = Class.new(Error)
13
+ UnknownFunnelType = Class.new(Error)
14
+
15
+ class << self
16
+ attr_reader :configuration
17
+
18
+ def configuration
19
+ @configuration ||= Funneler::Configuration.new
20
+ end
21
+
22
+ def configure
23
+ yield(configuration)
24
+ end
25
+
26
+ def from_token(token:)
27
+ data = Funneler::TokenHandler.extract_data_from(token)
28
+ Funneler::Funnel.new(data)
29
+ rescue JWT::DecodeError => e
30
+ raise InvalidTokenError, "Invalid token '#{token}': #{e.message}"
31
+ end
32
+
33
+ def build(route_generator:, params: {}, expires_in_days: nil)
34
+ Funneler::FunnelFactory.build(route_generator: route_generator,
35
+ params: params,
36
+ expires_in_days: expires_in_days)
37
+ end
38
+
39
+ def from_routes(routes: {})
40
+ Funnel.new('routes' => routes, 'current_page_index' => 0)
41
+ end
42
+
43
+ def from_url(url:)
44
+ uri = URI.parse(url)
45
+ params = Hash[URI.decode_www_form(uri.query || "")]
46
+ token = params['funnel_token']
47
+ from_token(token: token)
48
+ end
49
+ end
50
+
51
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: funneler
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Stawarz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: timecop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: ''
98
+ email:
99
+ - ryan@stawarz.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - CHANGELOG
105
+ - CONTRIBUTING.md
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - funneler.gemspec
114
+ - lib/funneler.rb
115
+ - lib/funneler/configuration.rb
116
+ - lib/funneler/controller_methods.rb
117
+ - lib/funneler/funnel.rb
118
+ - lib/funneler/funnel_factory.rb
119
+ - lib/funneler/token_handler.rb
120
+ - lib/funneler/version.rb
121
+ homepage: https://github.com/doximity/funneler
122
+ licenses:
123
+ - Apache 2.0
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.5.1
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: A light-weight approach for routing users through a pre-determined set of
145
+ routes.
146
+ test_files: []