Class: SharedWorkforce::EndPoint
- Inherits:
-
Object
- Object
- SharedWorkforce::EndPoint
- Defined in:
- lib/shared_workforce/end_point.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #callback_path ⇒ Object
-
#initialize(app = nil) ⇒ EndPoint
constructor
A new instance of EndPoint.
- #process_response(body) ⇒ Object
Constructor Details
#initialize(app = nil) ⇒ EndPoint
Returns a new instance of EndPoint.
4 5 6 |
# File 'lib/shared_workforce/end_point.rb', line 4 def initialize(app = nil) @app = app end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/shared_workforce/end_point.rb', line 8 def call(env) if env["PATH_INFO"] =~ %r{^/#{callback_path}} request = Rack::Request.new(env) request.body.rewind process_response(request.body.read) else @app.call(env) if @app.respond_to? :call end end |
#callback_path ⇒ Object
34 35 36 |
# File 'lib/shared_workforce/end_point.rb', line 34 def callback_path SharedWorkforce.configuration.callback_path end |
#process_response(body) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/shared_workforce/end_point.rb', line 18 def process_response(body) body = JSON.parse(body) SharedWorkforce.logger.info "Processing Shared Workforce task callback" SharedWorkforce.logger.info { body.inspect } raise SecurityTransgression unless valid_api_key?(body['api_key']) SharedWorkforce::TaskResult.new(body).process! [ 200, { "Content-Type" => "text/html", "Content-Length" => "0" }, [""] ] end |