From 7056cf04940bf657a98612c2d842728104f54206 Mon Sep 17 00:00:00 2001 From: Hakan Ensari Date: Tue, 13 May 2014 03:08:14 +0100 Subject: [PATCH 1/7] Remove .ruby-version --- .ruby-version | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 3e3c2f1..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.1.1 From 814087a602e2f852f9a9894fcdb2400b80c9601c Mon Sep 17 00:00:00 2001 From: Hakan Ensari Date: Tue, 13 May 2014 03:08:21 +0100 Subject: [PATCH 2/7] Bump Ruby version --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c094718..3e62e85 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' -ruby '2.1.1' +ruby '2.1.2' gem 'fixer' gem 'honeybadger' From a73e9ddc7d067d3f6514210970abd215c9c1ea5b Mon Sep 17 00:00:00 2001 From: Hakan Ensari Date: Tue, 13 May 2014 03:08:33 +0100 Subject: [PATCH 3/7] Handle malformed query --- lib/api.rb | 2 +- lib/snapshot.rb | 1 + spec/api_spec.rb | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/api.rb b/lib/api.rb index 6303e48..f5ba937 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -26,7 +26,7 @@ helpers do end def halt_with_meaningful_response(status, message) - halt status, "#{message}. Please read http://fixer.io." + halt status, message end end diff --git a/lib/snapshot.rb b/lib/snapshot.rb index 42a4e3d..c1fb0a6 100644 --- a/lib/snapshot.rb +++ b/lib/snapshot.rb @@ -28,6 +28,7 @@ class Snapshot def rebase(rates) if base.upcase! != 'EUR' denominator = rates.update('EUR' => 1.0).delete(base) + raise ArgumentError, 'Invalid base' unless denominator rates.each do |iso_code, rate| rates[iso_code] = round(rate / denominator) diff --git a/spec/api_spec.rb b/spec/api_spec.rb index a6de438..a111a2f 100644 --- a/spec/api_spec.rb +++ b/spec/api_spec.rb @@ -44,4 +44,9 @@ describe 'the API' do get '/' last_response.status.must_equal 404 end + + it 'handles malformed queries' do + get 'latest?base=USD?callback=?' + last_response.must_be :unprocessable? + end end From 4b6fa38af991d76063ea4eb934be4a18269d3145 Mon Sep 17 00:00:00 2001 From: Hakan Ensari Date: Tue, 13 May 2014 11:39:00 +0100 Subject: [PATCH 4/7] Remove async delivery --- config/initializers/honeybadger.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config/initializers/honeybadger.rb b/config/initializers/honeybadger.rb index c4dbcf3..73066cf 100644 --- a/config/initializers/honeybadger.rb +++ b/config/initializers/honeybadger.rb @@ -3,8 +3,4 @@ require 'honeybadger' Honeybadger.configure do |config| config.environment_name = App.env config.api_key = ENV['HONEYBADGER_API_KEY'] - - config.async do |notice| - Thread.new { notice.deliver } - end end From 235a9e0c271b49b7b87290cef684d84655fc8936 Mon Sep 17 00:00:00 2001 From: Hakan Ensari Date: Tue, 13 May 2014 11:39:27 +0100 Subject: [PATCH 5/7] Move middleware to api file --- config.ru | 1 - lib/api.rb | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config.ru b/config.ru index 7072c37..1012048 100644 --- a/config.ru +++ b/config.ru @@ -1,5 +1,4 @@ require './config/environment' require 'api' -use Honeybadger::Rack run Sinatra::Application diff --git a/lib/api.rb b/lib/api.rb index f5ba937..356d07b 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -7,6 +7,8 @@ set :root, File.expand_path('..', File.dirname(__FILE__)) configure :production do require 'newrelic_rpm' + + use Honeybadger::Rack end helpers do From 6753fcc49fab526ff9732e3ac3321988507f2873 Mon Sep 17 00:00:00 2001 From: Hakan Ensari Date: Tue, 13 May 2014 11:39:38 +0100 Subject: [PATCH 6/7] Add Librato Rack --- Gemfile | 1 + Gemfile.lock | 11 +++++++++++ lib/api.rb | 2 ++ 3 files changed, 14 insertions(+) diff --git a/Gemfile b/Gemfile index 3e62e85..04984ed 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ ruby '2.1.2' gem 'fixer' gem 'honeybadger' gem 'newrelic_rpm' +gem 'librato-rack' gem 'rake' gem 'sequel_pg' gem 'sinatra-jsonp' diff --git a/Gemfile.lock b/Gemfile.lock index 010ba59..e014fec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,7 @@ GEM remote: http://rubygems.org/ specs: + aggregate (0.2.2) axiom-types (0.1.1) descendants_tracker (~> 0.0.4) ice_nine (~> 0.11.0) @@ -10,6 +11,8 @@ GEM descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) equalizer (0.0.9) + faraday (0.9.0) + multipart-post (>= 1.2, < 3) fixer (0.5.0) nokogiri (~> 1.5) honeybadger (1.13.0) @@ -17,9 +20,16 @@ GEM ice_nine (0.11.0) json (1.8.1) kgio (2.9.2) + librato-metrics (1.3.2) + aggregate (~> 0.2.2) + faraday (~> 0.7) + multi_json + librato-rack (0.4.4) + librato-metrics (~> 1.1) mini_portile (0.5.3) minitest (5.3.3) multi_json (1.9.3) + multipart-post (2.0.0) newrelic_rpm (3.8.0.218) nokogiri (1.6.1) mini_portile (~> 0.5.0) @@ -63,6 +73,7 @@ PLATFORMS DEPENDENCIES fixer honeybadger + librato-rack minitest newrelic_rpm rack-test diff --git a/lib/api.rb b/lib/api.rb index 356d07b..7f975ea 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -7,8 +7,10 @@ set :root, File.expand_path('..', File.dirname(__FILE__)) configure :production do require 'newrelic_rpm' + require 'librato-rack' use Honeybadger::Rack + use Librato::Rack end helpers do From 864b26999281b9dc847eec8902d3c0d8d15bb083 Mon Sep 17 00:00:00 2001 From: Hakan Ensari Date: Tue, 13 May 2014 11:43:58 +0100 Subject: [PATCH 7/7] Enable GC profiler --- config/initializers/gc_profiler.rb | 1 + 1 file changed, 1 insertion(+) create mode 100644 config/initializers/gc_profiler.rb diff --git a/config/initializers/gc_profiler.rb b/config/initializers/gc_profiler.rb new file mode 100644 index 0000000..0a0a152 --- /dev/null +++ b/config/initializers/gc_profiler.rb @@ -0,0 +1 @@ +GC::Profiler.enable