napa 0.1.28 → 0.1.29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 921842df68ddfd43053accc0281962d797225ced
4
- data.tar.gz: 892d34f1952b7e73dba7dff8f485d2930d6b39ed
3
+ metadata.gz: 6b908b554665776da48de53dd708fa5aab073f75
4
+ data.tar.gz: 22d74ccfd70d4864121f527266e7de4b062a7068
5
5
  SHA512:
6
- metadata.gz: 3b9c94ad04f33374ffc54ec532ef07de33e915f03c5353e50d0ad43e823ff22d0dd731c2b8fd1917faf747945e68a43cc4f73fb6b401b75d37de3ea89bae4c46
7
- data.tar.gz: 651d69ad11fa10824d704f0c87b268f9e4a5c997b7408f483e04472f8c54d0a8844d9789d9b6a27317d5a1a191559ae721ae8f1cfcc4e0786024253acbde1c02
6
+ metadata.gz: 09c3b747af4ec25f35adbc5f65296139d365907901276c0dfcde2f9ebd8f86243ab55edad8ce83849869dde2f20d3487394ea745a222a79340b698ffc6ba4e4c
7
+ data.tar.gz: 4634f451434e794ad7ec3aa3767272e803348e799de9a8412e7cec54320069074ad95c0b03885022e7d36475491228b79fd8e196491458b66bc31b66aeda9e56
@@ -12,7 +12,7 @@ module Napa
12
12
  end
13
13
 
14
14
  def migration_filename
15
- "#{version}_#{migration_name}"
15
+ "#{version}_#{migration_name.underscore}"
16
16
  end
17
17
 
18
18
  def migration
@@ -1,7 +1,4 @@
1
1
  class <%= migration_name.classify %> < ActiveRecord::Migration
2
2
  def change
3
- # create_table :foo do |t|
4
- # t.string :name, :null => false
5
- # end
6
3
  end
7
4
  end
@@ -9,7 +9,7 @@ module Napa
9
9
  rack_response(Napa::JsonError.new(:record_not_found, 'record not found').to_json, 404)
10
10
  end
11
11
  modified_class.rescue_from ::ActiveRecord::RecordInvalid do |e|
12
- rack_response(Napa::JsonError.new(:record_invalid, 'record not found').to_json, 400)
12
+ rack_response(Napa::JsonError.new(:unprocessable_entity, e.message).to_json, 422)
13
13
  end
14
14
  end
15
15
  end
@@ -5,6 +5,15 @@ module Napa
5
5
  @app = app
6
6
  end
7
7
 
8
+ def normalize_path(path)
9
+ case
10
+ when path == '/'
11
+ 'root'
12
+ else
13
+ path.start_with?('/') ? path[1..-1] : path
14
+ end
15
+ end
16
+
8
17
  def call(env)
9
18
  # Mark the request time
10
19
  start = Time.now
@@ -16,12 +25,15 @@ module Napa
16
25
  stop = Time.now
17
26
 
18
27
  # Calculate total response time
19
- response_time = stop - start
28
+ response_time = (stop - start) * 1000
29
+
30
+ request = Rack::Request.new(env)
31
+ path = normalize_path(request.path_info)
32
+ stat = "#{Napa::Identity.name}.http.#{request.request_method.downcase}.#{path}".gsub('/', '.')
20
33
 
21
34
  # Emit stats to StatsD
22
- Napa::Stats.emitter.increment('api_requests')
23
- Napa::Stats.emitter.timing('api_response_time', response_time)
24
-
35
+ Napa::Stats.emitter.increment(stat + '.requests')
36
+ Napa::Stats.emitter.timing(stat + '.response_time', response_time)
25
37
  # Return the results
26
38
  [status, headers, body]
27
39
  end
data/lib/napa/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Napa
2
- VERSION = '0.1.28'
2
+ VERSION = '0.1.29'
3
3
 
4
4
  class Version
5
5
  class << self
@@ -10,18 +10,21 @@ describe Napa::Middleware::RequestStats do
10
10
  end
11
11
 
12
12
  it 'should increment api_requests counter' do
13
- Napa::Stats.emitter.should_receive(:increment).with('api_requests')
13
+ Napa::Stats.emitter.should_receive(:increment).with(Napa::Identity.name + ".http.get." + "test.path.requests")
14
14
  app = lambda { |env| [200, { 'Content-Type' => 'application/json' }, Array.new] }
15
15
  middleware = Napa::Middleware::RequestStats.new(app)
16
- env = Rack::MockRequest.env_for('/test')
16
+ env = Rack::MockRequest.env_for('/test/path')
17
17
  middleware.call(env)
18
18
  end
19
19
 
20
20
  it 'should send the api_response_time' do
21
- Napa::Stats.emitter.should_receive(:timing).with('api_response_time', an_instance_of(Float))
21
+ Napa::Stats.emitter.should_receive(:timing).with(
22
+ Napa::Identity.name + ".http.get." + "test.path.response_time",
23
+ an_instance_of(Float)
24
+ )
22
25
  app = lambda { |env| [200, { 'Content-Type' => 'application/json'}, Array.new] }
23
26
  middleware = Napa::Middleware::RequestStats.new(app)
24
- env = Rack::MockRequest.env_for('/test')
27
+ env = Rack::MockRequest.env_for('/test/path')
25
28
  middleware.call(env)
26
29
  end
27
30
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: napa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.28
4
+ version: 0.1.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darby Frey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-21 00:00:00.000000000 Z
11
+ date: 2014-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake