mashape-analytics 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/VERSION +1 -1
- data/lib/mashape-analytics/frameworks/rack.rb +33 -7
- data/mashape-analytics.gemspec +3 -3
- data/test/test_rack.rb +23 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 749a81257d08ac6fd003fea80ae9d24b7f2669da
|
4
|
+
data.tar.gz: 4dec0963179b2df21204485a642a632d26e1b31c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2009bfccf93d9f9cf95295990ef275cb4deea653b76c517e5f6b90c31401e7e47bd9704966c5028708a9c4e22def41a85e573b84c27beb30e884f01a2a5295db
|
7
|
+
data.tar.gz: 93cae7d08cfcecbb7a57e881ee5e2b434ee4a97a0d6bf4226934103a9294520af2fd43d3a667149cc5b4aff034941c2a531f27411692a50520f8069fe920f810
|
data/README.md
CHANGED
@@ -19,6 +19,8 @@ bundle install
|
|
19
19
|
|
20
20
|
### Ruby on Rails
|
21
21
|
|
22
|
+
Make sure to add `mashape-analytics` to your Gemfile.
|
23
|
+
|
22
24
|
Open your `config/environment.rb` file, and within the `Rails::Initializer.run` block, add the middleware as below:
|
23
25
|
|
24
26
|
```ruby
|
@@ -31,6 +33,13 @@ end
|
|
31
33
|
|
32
34
|
*In rails 4, put the `config.middleware.use` line in the `config/application.rb` file.*
|
33
35
|
|
36
|
+
```ruby
|
37
|
+
module MyApp
|
38
|
+
class Application < Rails::Application
|
39
|
+
config.middleware.use 'MashapeAnalytics::Frameworks::Rails', service_token: 'SERVICE_TOKEN', environment: 'production'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
34
43
|
|
35
44
|
### Sinatra
|
36
45
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.3
|
@@ -29,11 +29,11 @@ module MashapeAnalytics::Frameworks
|
|
29
29
|
status, headers, body = @app.call(env)
|
30
30
|
|
31
31
|
if body.respond_to? :to_str
|
32
|
-
|
32
|
+
response_body = [body.to_str]
|
33
33
|
elsif body.respond_to?(:body)
|
34
|
-
|
34
|
+
response_body = [body.body]
|
35
35
|
elsif body.respond_to?(:each)
|
36
|
-
|
36
|
+
response_body = body
|
37
37
|
else
|
38
38
|
raise TypeError, "stringable or iterable required"
|
39
39
|
end
|
@@ -41,7 +41,7 @@ module MashapeAnalytics::Frameworks
|
|
41
41
|
record_alf startedDateTime, env, {
|
42
42
|
:status => status,
|
43
43
|
:headers => header_hash(headers),
|
44
|
-
:body =>
|
44
|
+
:body => response_body
|
45
45
|
}
|
46
46
|
|
47
47
|
[status, headers, body]
|
@@ -98,12 +98,27 @@ module MashapeAnalytics::Frameworks
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
+
def stream_size(stream)
|
102
|
+
size = nil
|
103
|
+
io = StringIO.new
|
104
|
+
begin
|
105
|
+
stream.write io
|
106
|
+
io.flush
|
107
|
+
size = io.size
|
108
|
+
ensure
|
109
|
+
io.close
|
110
|
+
end
|
111
|
+
size
|
112
|
+
end
|
113
|
+
|
101
114
|
def request_content_size(request)
|
102
115
|
if request['HTTP_CONTENT_LENGTH']
|
103
116
|
request['HTTP_CONTENT_LENGTH'].to_i
|
104
117
|
else
|
105
118
|
if request['rack.input'].respond_to? :size
|
106
119
|
request['rack.input'].size
|
120
|
+
elsif request['rack.input'].respond_to? :write
|
121
|
+
stream_size(request['rack.input'])
|
107
122
|
else
|
108
123
|
-1 # Not available
|
109
124
|
end
|
@@ -126,10 +141,17 @@ module MashapeAnalytics::Frameworks
|
|
126
141
|
end
|
127
142
|
|
128
143
|
def response_content_size(response)
|
144
|
+
# puts 'BODY: ' << response[:body]
|
129
145
|
if response[:headers]['Content-Length']
|
130
146
|
response[:headers]['Content-Length'].to_i
|
131
147
|
else
|
132
|
-
response[:body].inject
|
148
|
+
if response[:body].respond_to? :inject
|
149
|
+
response[:body].inject(0) { |sum, b| sum + b.bytesize }
|
150
|
+
elsif response[:body].respond_to? :write
|
151
|
+
stream_size(response[:body])
|
152
|
+
else
|
153
|
+
-1 # Not available
|
154
|
+
end
|
133
155
|
end
|
134
156
|
end
|
135
157
|
|
@@ -193,8 +215,12 @@ module MashapeAnalytics::Frameworks
|
|
193
215
|
request['rack.input'].rewind
|
194
216
|
entry[:request][:content][:text] = Base64.strict_encode64(request['rack.input'].read)
|
195
217
|
|
196
|
-
|
197
|
-
|
218
|
+
|
219
|
+
# TODO Handle streams as well
|
220
|
+
if response[:body].respond_to? :join
|
221
|
+
entry[:response][:content][:encoding] = 'base64'
|
222
|
+
entry[:response][:content][:text] = Base64.strict_encode64(response[:body].join())
|
223
|
+
end
|
198
224
|
end
|
199
225
|
|
200
226
|
alf.add_entry entry
|
data/mashape-analytics.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: mashape-analytics 1.0.
|
5
|
+
# stub: mashape-analytics 1.0.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "mashape-analytics"
|
9
|
-
s.version = "1.0.
|
9
|
+
s.version = "1.0.3"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Kenneth Lee"]
|
14
|
-
s.date = "2015-06-
|
14
|
+
s.date = "2015-06-29"
|
15
15
|
s.description = "The ruby agent reports API traffic to http://apianalytics.com"
|
16
16
|
s.email = "kennethkl@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
data/test/test_rack.rb
CHANGED
@@ -13,6 +13,16 @@ class TestRack < MiniTest::Test
|
|
13
13
|
Rack::MockRequest.new(stack)
|
14
14
|
end
|
15
15
|
|
16
|
+
def compressed_app
|
17
|
+
app = proc do
|
18
|
+
sleep 0.05
|
19
|
+
[200, {'CONTENT-TYPE' => 'application/json'}, ['{"messages": "Test Response"}']]
|
20
|
+
end
|
21
|
+
stack = Rack::Deflater.new app
|
22
|
+
stack = MashapeAnalytics::Frameworks::Rack.new stack, service_token: 'SERVICE-TOKEN', host: @@host, send_body: @send_body
|
23
|
+
Rack::MockRequest.new(stack)
|
24
|
+
end
|
25
|
+
|
16
26
|
def setup
|
17
27
|
# Create our socket server
|
18
28
|
@zmq_pull = zmq_pull_socket(@@host)
|
@@ -67,5 +77,18 @@ class TestRack < MiniTest::Test
|
|
67
77
|
assert_entry_response_content entry, 'base64', 'eyJtZXNzYWdlcyI6ICJUZXN0IFJlc3BvbnNlIn0='
|
68
78
|
end
|
69
79
|
|
80
|
+
should 'send ALF with compressed body' do
|
81
|
+
response = compressed_app.get('/get?foo=bar&empty', {'HTTP_ACCEPT' => 'application/json'})
|
82
|
+
|
83
|
+
version, message = @zmq_pull.recv.split(' ', 2)
|
84
|
+
alf = JSON.parse(message)
|
85
|
+
|
86
|
+
assert_ruby_agent alf
|
87
|
+
|
88
|
+
entry = alf['har']['log']['entries'].first
|
89
|
+
assert_entry_request entry, 'GET', 'http://example.org/get?foo=bar&empty'
|
90
|
+
assert_entry_response entry, 200, 99
|
91
|
+
end
|
92
|
+
|
70
93
|
|
71
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mashape-analytics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenneth Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbczmq
|