rack-reqorder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3e5ee5c3b78608fb23c33eccc40fad318829ee7a
4
+ data.tar.gz: 878a3139311546392b38b6ab1d7efff7cd320db9
5
+ SHA512:
6
+ metadata.gz: 608cd0e963785bc88d375272189556c062a1140b9b287ecd4ba4248e76487d44066244c317460734824eb3309397d78fa4d77be826aa56d738062921951b224d
7
+ data.tar.gz: 317dbb6df532175889814c2dae12c83910ce81eadf9ec4ab6f97d1f04dc5ed593045743d9df02f17595b0e942e5d9a3a5b8f8c46caaef9d064eb5f029ace19f5
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-reqorder.gemspec
4
+ gemspec
5
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Filippos Vasilakis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Rack::Reqorder
2
+
3
+ Simple gem that records requests and responses. Uses MongoDB.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rack-reqorder'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rack-reqorder
20
+
21
+ ## Usage
22
+ Just add it on the middleware pipeline and initialize it.
23
+
24
+ For instance, in Rails, in an initializer add:
25
+
26
+ ```ruby
27
+ Rack::Reqorder.configure do |config|
28
+ config.mongoid_yml = File.join(Rails.root, 'config', 'mongoid.yml')
29
+ end
30
+
31
+ Rack::Reqorder.boot!
32
+
33
+ Rails.application.config.middleware.insert(0, Rack::Reqorder::Logger)
34
+ ```
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( https://github.com/[my-github-username]/rack-reqorder/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rack/reqorder"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,44 @@
1
+ require 'rack/reqorder/version'
2
+ require 'active_support/inflector'
3
+ require 'mongoid'
4
+
5
+ module Rack
6
+ module Reqorder
7
+ class << self
8
+ attr_accessor :configuration
9
+ end
10
+
11
+ def self.configure
12
+ self.configuration ||= Configuration.new
13
+ yield(configuration)
14
+ end
15
+
16
+ def self.boot!
17
+ self.configuration.validate!
18
+
19
+ Mongoid.load!(
20
+ self.configuration.mongoid_yml,
21
+ self.configuration.environment
22
+ )
23
+ end
24
+
25
+ class Configuration
26
+ attr_accessor :mongoid_yml, :environment
27
+
28
+ def validate!
29
+ if mongoid_yml.blank?
30
+ raise 'You need to setup mongoid.yml before using this gem'
31
+ end
32
+
33
+ if environment.blank?
34
+ puts 'rack-reqorder: No environment found, assuming development environment'
35
+ self.environment = :development
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ require 'rack/reqorder/models/http_request'
43
+ require 'rack/reqorder/models/http_response'
44
+ require 'rack/reqorder/logger'
@@ -0,0 +1,48 @@
1
+ module Rack
2
+ module Reqorder
3
+ class Logger
4
+ include Rack::Reqorder::Models
5
+
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(environment)
11
+ #api_session = ApiSession.create(created_at: Time.now)
12
+ request = Rack::Request.new(environment)
13
+ #api_session.request
14
+
15
+ HttpRequest.create(
16
+ path: request.path,
17
+ full_path: request.fullpath,
18
+ headers: extract_all_headers(request),
19
+ parameters: request.params,
20
+ )
21
+
22
+ status, headers, body = @app.call(request.env)
23
+
24
+ response = Rack::Response.new(body, status, headers)
25
+
26
+ HttpResponse.create(
27
+ headers: response.headers,
28
+ #body: response.body.first,
29
+ status: response.status.to_i
30
+ )
31
+ =begin
32
+ response.finish
33
+ =end
34
+ return [status, headers, body]
35
+ end
36
+
37
+ def extract_all_headers(request)
38
+ Hash[
39
+ request.env.select{|k,v|
40
+ k.start_with? 'HTTP_'
41
+ }.map{|k,v|
42
+ [k.gsub('HTTP_','').upcase, v]
43
+ }
44
+ ]
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ module Rack::Reqorder::Models
2
+ class HttpRequest
3
+ include ::Mongoid::Document
4
+
5
+ field :path, type: String
6
+ field :full_path, type: String
7
+ field :headers, type: Hash
8
+ field :parameters, type: Hash
9
+ field :created_at, type: DateTime
10
+
11
+ has_one :http_response
12
+
13
+ before_create :set_created_at
14
+
15
+ def set_created_at
16
+ self.created_at = DateTime.now.utc
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ module Rack::Reqorder::Models
2
+ class HttpResponse
3
+ include ::Mongoid::Document
4
+
5
+ field :headers, type: Hash
6
+ field :status, type: Integer
7
+ #field :body, type: String
8
+ field :created_at, type: DateTime
9
+
10
+ before_create :set_created_at
11
+
12
+ def set_created_at
13
+ self.created_at = DateTime.now.utc
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ class NewRequestService
2
+ class << self
3
+ def save(request)
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ module Reqorder
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack/reqorder/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rack-reqorder"
8
+ spec.version = Rack::Reqorder::VERSION
9
+ spec.authors = ["Filippos Vasilakis"]
10
+ spec.email = ["vasilakisfil@gmail.com"]
11
+
12
+ spec.summary = %q{Request recorder and analyzer for rack apps}
13
+ spec.description = %q{Request recorder and analyzer for rack apps}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.8"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency "mongoid", "~> 4.0.0"
24
+ spec.add_dependency "activesupport", "~> 4.1.6"
25
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-reqorder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Filippos Vasilakis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mongoid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 4.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 4.1.6
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 4.1.6
69
+ description: Request recorder and analyzer for rack apps
70
+ email:
71
+ - vasilakisfil@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/rack/reqorder.rb
87
+ - lib/rack/reqorder/logger.rb
88
+ - lib/rack/reqorder/models/http_request.rb
89
+ - lib/rack/reqorder/models/http_response.rb
90
+ - lib/rack/reqorder/services/request_saver.rb
91
+ - lib/rack/reqorder/version.rb
92
+ - rack-reqorder.gemspec
93
+ homepage: ''
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.5
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Request recorder and analyzer for rack apps
117
+ test_files: []