grape-librato 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=documentation
3
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## Changelog
2
+
3
+ ### Version 0.0.1
4
+ * Maybe it's working
5
+
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem "rake", "~> 10.0"
7
+ gem "bundler", "~> 1.0"
8
+ gem "rspec", "~> 2.6"
9
+ gem "rack-test", "~> 0.6.2"
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012-2013 Richard Huang, Sean Moon
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Libarto::Grape
2
+
3
+ Librato tracking for [Grape][0], based on code from [this NewRelic
4
+ gem][1], using [librato-rack][2]
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'grape-librato'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install grape-librato
19
+
20
+ Include it in your Grape API like this
21
+
22
+ class TestAPI < Grape::API
23
+ use Librato::Grape::Middleware
24
+
25
+ get 'hello' do
26
+ "Hello World"
27
+ end
28
+ end
29
+
30
+ *Make sure you are also using the librato-rack middleware*
31
+
32
+ Here's an example `config.ru`
33
+
34
+ require 'grape'
35
+ require 'librato-rack'
36
+ require 'grape-librato'
37
+
38
+ LIBRATO_CONFIGURATION = Librato::Rack::Configuration.new
39
+ LIBRATO_CONFIGURATION.user = ENV['LIBRATO_USER']
40
+ LIBRATO_CONFIGURATION.token = ENV['LIBRATO_TOKEN']
41
+ LIBRATO_CONFIGURATION.source = ENV['LIBRATO_SOURCE'] || 'localhost'
42
+
43
+ class API < Grape::API
44
+ use Librato::Grape::Middleware
45
+ get 'hello' do
46
+ "Hello World"
47
+ end
48
+ end
49
+
50
+ use Librato::Rack, config: LIBRATO_CONFIGURATION
51
+ run API
52
+
53
+ See how to set up the `Librato::Rack` object in the [librato-rack][2]
54
+ documentation.
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 5. Make a pull request
63
+
64
+ [0]: https://github.com/intridea/grape
65
+ [1]: https://github.com/flyerhzm/newrelic-grape
66
+ [2]: https://github.com/librato/librato-rack
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+
11
+ require 'rake'
12
+
13
+ require 'rspec/core'
14
+ require 'rspec/core/rake_task'
15
+
16
+ RSpec::Core::RakeTask.new(:spec) do |spec|
17
+ spec.pattern = FileList['spec/**/*_spec.rb']
18
+ end
19
+
20
+ task :default => :spec
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grape-librato/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "grape-librato"
8
+ gem.version = Librato::Grape::VERSION
9
+ gem.authors = ["Sean Moon"]
10
+ gem.email = ["ssamoon@ucla.edu"]
11
+ gem.description = %q{librato metrics for grape}
12
+ gem.summary = %q{librato metrics for grape}
13
+ gem.homepage = "https://github.com/seanmoon/grape-librato"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(spec)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency(%q<grape>)
21
+ gem.add_runtime_dependency(%q<librato-rack>)
22
+ end
@@ -0,0 +1,2 @@
1
+ require "grape-librato/version"
2
+ require "grape-librato/middleware"
@@ -0,0 +1,20 @@
1
+ require 'grape'
2
+ require 'librato-rack'
3
+
4
+ module Librato
5
+ module Grape
6
+ class Middleware < ::Grape::Middleware::Base
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ req = ::Rack::Request.new(env)
13
+ request_path = env['api.endpoint'].routes.first.route_path[1..-1].gsub("/", ".").sub(/\(\.:format\)\z/, "")
14
+ Librato.timing "#{req.request_method}.#{request_path}" do
15
+ @app.call(env)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module Librato
2
+ module Grape
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Librato::Grape::Middleware do
4
+
5
+ class TestAPI < Grape::API
6
+ use Librato::Grape::Middleware
7
+ get 'hello' do
8
+ "Hello World"
9
+ end
10
+ end
11
+
12
+ subject { TestAPI }
13
+
14
+ def app
15
+ subject
16
+ end
17
+
18
+ it "should send a timing event for each request" do
19
+ Librato.should_receive(:timing).and_yield
20
+ get "/hello"
21
+ last_response.status.should == 200
22
+ last_response.body.should == "Hello World"
23
+ end
24
+ end
25
+
26
+
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Librato::Grape do
4
+ it "has a version" do
5
+ Librato::Grape::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rack/test'
5
+
6
+ RSpec.configure do |config|
7
+ config.include Rack::Test::Methods
8
+ end
9
+
10
+ require 'grape'
11
+ require 'grape-librato'
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grape-librato
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sean Moon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: grape
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: librato-rack
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: librato metrics for grape
47
+ email:
48
+ - ssamoon@ucla.edu
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .rspec
55
+ - CHANGELOG.md
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - grape-librato.gemspec
61
+ - lib/grape-librato.rb
62
+ - lib/grape-librato/middleware.rb
63
+ - lib/grape-librato/version.rb
64
+ - spec/grape-librato/middleware_spec.rb
65
+ - spec/grape-librato/version_spec.rb
66
+ - spec/spec_helper.rb
67
+ homepage: https://github.com/seanmoon/grape-librato
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.25
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: librato metrics for grape
91
+ test_files:
92
+ - spec/grape-librato/middleware_spec.rb
93
+ - spec/grape-librato/version_spec.rb
94
+ - spec/spec_helper.rb
95
+ has_rdoc: