class Rack::Monetize::ProcessMonetizeState

Public Class Methods

new(app) click to toggle source
# File lib/rack/monetize/process_monetize_state.rb, line 4
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/monetize/process_monetize_state.rb, line 8
def call(env)
  req = ::Rack::Request.new(env)

  # If there is no `monetization_state` field ignore this middleware
  return @app.call(env) unless req.params['monetization_state']

  # Otherwise calculate the signature and check that it matches
  if req.params['monetization_state'] && check_monetization_state(req.params['monetization_state'])
    @app.call(env)
  else
    [403, {}, ['']]
  end
end

Private Instance Methods

check_monetization_state(state) click to toggle source
# File lib/rack/monetize/process_monetize_state.rb, line 24
def check_monetization_state(state)
  if (state == 'stopped'|| state == 'pending' || state == 'started' || state == 'undefined')
    true
  end
end