Class: MashapeAnalytics::Frameworks::Rack
- Inherits:
-
Object
- Object
- MashapeAnalytics::Frameworks::Rack
- Defined in:
- lib/mashape-analytics/frameworks/rack.rb
Direct Known Subclasses
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Rack
constructor
A new instance of Rack.
Constructor Details
#initialize(app, options = {}) ⇒ Rack
Returns a new instance of Rack.
17 18 19 20 21 22 23 24 25 |
# File 'lib/mashape-analytics/frameworks/rack.rb', line 17 def initialize(app, = {}) @app = app @service_token = [:service_token] @environment = [:environment] || '' @send_body = [:send_body] || false host = [:host] || 'tcp://socket.analytics.mashape.com:5500' MashapeAnalytics::Capture.setOptions(host: host) end |
Instance Method Details
#call(env) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mashape-analytics/frameworks/rack.rb', line 27 def call(env) startedDateTime = Time.now status, headers, body = @app.call(env) if body.respond_to? :to_str response_body = [body.to_str] elsif body.respond_to?(:body) response_body = [body.body] elsif body.respond_to?(:each) response_body = body else raise TypeError, "stringable or iterable required" end record_alf startedDateTime, env, { :status => status, :headers => header_hash(headers), :body => response_body } [status, headers, body] end |