Class: MashapeAnalytics::Frameworks::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/mashape-analytics/frameworks/rack.rb

Direct Known Subclasses

Rails

Instance Method Summary collapse

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, options = {})
  @app = app
  @service_token = options[:service_token]
  @environment = options[:environment] || ''
  @send_body = options[:send_body] || false
  host = options[: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