Last active
January 7, 2016 18:57
-
-
Save Heath101/44ef3a9557fc2eb15a8f to your computer and use it in GitHub Desktop.
Middlewares example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SalesForce | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
puts "SalesForce Handler" | |
puts "SalesForce AXID found" | |
env[:axids] << "AXID01234567890" | |
env[:salesforce] = {customer: {}} | |
@app.call(env) | |
end | |
end | |
class Zuora | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
puts "Zuora Handler" | |
env[:zuora] = {} | |
@app.call(env) | |
end | |
end | |
class NicodemusSubscriptions | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
puts "NicodemusSubscriptions Handler" | |
env[:nicodemus_subscriptions] = {} | |
@app.call(env) | |
end | |
end | |
class B2Church | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
puts "B2Church Handler" | |
env[:b2church] = {relevant_data: "Foo"} | |
@app.call(env) | |
end | |
end | |
stack = Middleware::Builder.new do |d| | |
d.use SalesForce | |
d.use Zuora | |
d.use B2Church | |
d.use NicodemusSubscriptions | |
end | |
stack.call({emails: ["[email protected]"], axids: []}) | |
# Outputs this: | |
#=> SalesForce Handler | |
#=> SalesForce AXID found | |
#=> Zuora Handler | |
#=> B2Church Handler | |
#=> NicodemusSubscriptions Handler | |
#=> => {:emails=>["[email protected]"], | |
#=> :axids=>["AXID01234567890"], | |
#=> :salesforce=>{:customer=>{}}, | |
#=> :zuora=>{}, | |
#=> :b2church=>{:relevant_data=>"Foo"}, | |
#=> :nicodemus_subscriptions=>{}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment