minimo 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 39fa9ca781ed4bb203e6288d605c624190547c46
4
+ data.tar.gz: bf21e5e7c660e66f3014aa68daa69baedd5ff3f2
5
+ SHA512:
6
+ metadata.gz: 4736beaef7fb60543664ce19a7ce3562f1f78e1c3e9ffc335c5d87736f43a6c3b29e36e2be1f65a78570d62e225d5bfa22a7e8f1189a281fc1791e1409e406e6
7
+ data.tar.gz: 3ad3e18ad7337258a306e20bfff3130f2d8c5d5867b56a3e2e455f8fe970a592fd45e4fddde7c005b895684dcddc30826f6c4637ec89403c6e3590397753da1c
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /coverage
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at kazu69web@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in substitute.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 kazu69
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.
@@ -0,0 +1,99 @@
1
+ minimo
2
+ -------
3
+
4
+ > Mini Mock server
5
+ > Rack based REST corresponding server
6
+
7
+ Install
8
+ ========
9
+
10
+ ```ruby
11
+ gem install minimo
12
+ ```
13
+
14
+ Usage
15
+ ======
16
+
17
+ It is placed in the directory you specify a response file.
18
+ For example, in the case of the json response to the POST method.
19
+ To place the json file in ```response/POST/hello/world.json```.
20
+
21
+ ```sh
22
+ $ mkdir -p response/POST/hello
23
+ $ cd response/POST/hello
24
+ $ vi world.json
25
+
26
+ {
27
+ "hello": "world"
28
+ }
29
+ ```
30
+
31
+ To start the minimo server.
32
+
33
+ ```ruby
34
+ # initialize.rb
35
+ require 'minimo'
36
+
37
+ # set response file dir
38
+ set :fixture_path, File.dirname( __FILE__ ) + '/response'
39
+
40
+ # set log file dir
41
+ set :log_dir, File.dirname( __FILE__ ) + '/log'
42
+
43
+ # set http header
44
+ set :headers, { 'Vary' => 'Accept-Encoding' }
45
+
46
+ Rack::Handler::WEBrick.run minimo::Application, Port: 9292
47
+ ```
48
+
49
+ And run the POST method.
50
+
51
+ ```sh
52
+ $ curl -X POST http://localhost:9292/hello/world/ -d "{ hey: 'ok' }"
53
+ {
54
+ "hello": "world"
55
+ }
56
+ ```
57
+
58
+ You can check the log file
59
+
60
+ ```sh
61
+ $ cat log/minimo.log
62
+
63
+ - -> /hello/world/
64
+ ::1 - - [14/Jul/2016:21:45:17 JST] "POST /hello/world/ HTTP/1.1" 201 16
65
+ ```
66
+
67
+ ### Other
68
+
69
+ The response can be created json, xml, in the text.
70
+ In addition to the POST, HEAD, PUT, corresponds to DELETE.
71
+
72
+ ```sh
73
+ # To place the response file in response/GET/hello/world.(txt|jso|xml)
74
+ # http status 200
75
+ $ curl -X GET http://localhost:9292/hello/world/
76
+
77
+ # To place the response file in response/HEAD/hello/world.(txt|jso|xml)
78
+ # http status 200
79
+ $ curl -I http://localhost:9292/hello/world/
80
+
81
+ # To place the response file in response/PUT/hello/world.(txt|jso|xml)
82
+ # http status 204
83
+ $ curl -X PUT http://localhost:9292/hello/world/
84
+
85
+ # To place the response file in response/DELETE/hello/world.(txt|jso|xml)
86
+ # http status 204
87
+ $ curl -X DELETE http://localhost:9292/hello/world/
88
+ ```
89
+
90
+ Contributing
91
+ ===============
92
+
93
+ Contributions to this gem are always welcome :smile:
94
+ See [CONTRIBUTING](https://github.com/kazu69/minimo/master/CODE_OF_CONDUCT.md) for more information on how to get started.
95
+
96
+ License
97
+ ========
98
+
99
+ This project is licensed under the terms of the MIT license. See the [LICENSE](https://github.com/kazu69/minimo/master/LICENSE.txt) file.
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task :default => :spec
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'minimo'
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,128 @@
1
+ require 'minimo/version'
2
+ require 'minimo/logger'
3
+ require 'rack'
4
+
5
+ module Minimo
6
+ class Base
7
+
8
+ NO_CONTENT_METHOD = %w(DELETE PATCH PUT)
9
+ CREATED_METHOD =%w(POST)
10
+ CONTENT_TYPE = {
11
+ json: 'application/json; charset=utf-8',
12
+ xml: 'application/xml; charset=utf-8',
13
+ text: 'application/text; charset=utf-8'
14
+ }
15
+
16
+ def initialize
17
+ @headers = default_header
18
+ @fixture_path = './response'.freeze
19
+ end
20
+
21
+ attr_accessor :headers, :fixture_path, :log_path
22
+
23
+ def set(key, value)
24
+ instance_variable_set "@#{key.to_s}", value
25
+ end
26
+
27
+ def call(env)
28
+ response_body = []
29
+ $stdout.sync = true
30
+
31
+ @request = Rack::Request.new(env)
32
+ verb = @request.request_method
33
+ file_path = fixture_path(verb)
34
+
35
+ response = Rack::Response.new do |r|
36
+ r.status = status_code(verb)
37
+ end
38
+
39
+ CONTENT_TYPE.keys.push(nil).each do |ext|
40
+ break if file_path.nil?
41
+ separator = ext.nil? ? '' : '.'
42
+ file = [file_path, ext].join(separator)
43
+ if File.exist? file
44
+ response_body << File.read(file)
45
+ @headers['Content-Type'] = header_content_type(ext)
46
+ break
47
+ end
48
+ end
49
+
50
+ if response_body.empty?
51
+ response.status = 404
52
+ @headers['Content-Type'] = header_content_type(:text)
53
+ response_body << "Oops! No route for #{verb} #{@request.path_info}"
54
+ end
55
+
56
+ @headers.map { |k,v| response.set_header(k,v) }
57
+ response.write response_body.join("\n")
58
+
59
+ if @log_dir
60
+ logger = Minimo::Logger.new @log_dir
61
+ msg = "#{verb} #{@request.path_info} #{env['SERVER_PROTOCOL']} #{response.status}"
62
+ logger.write msg
63
+ end
64
+
65
+ response.finish
66
+ end
67
+
68
+ def version
69
+ VERSION
70
+ end
71
+
72
+ private
73
+
74
+ def status_code(verb)
75
+ if NO_CONTENT_METHOD.include? verb
76
+ 204
77
+ elsif CREATED_METHOD.include? verb
78
+ 201
79
+ else
80
+ 200
81
+ end
82
+ end
83
+
84
+ def default_header
85
+ headers = {}
86
+ headers['Server'] = "minimo #{version}"
87
+ headers['X-UA-Compatible'] = 'IE=Edge,chrome=1'
88
+ headers['X-Content-Type-Options'] = 'nosniff'
89
+
90
+ headers
91
+ end
92
+
93
+ def header_content_type(type = nil)
94
+ type = :text if type.nil?
95
+ CONTENT_TYPE[type]
96
+ end
97
+
98
+ def fixture_path(verb)
99
+ method = verb
100
+ method = 'GET' if verb == 'HEAD'
101
+ requested_path = @request.path_info
102
+ "#{@fixture_path}/#{method}/#{requested_path[1..-1].chomp('/').gsub(/\//, '_')}"
103
+ end
104
+ end
105
+
106
+ Application = Base.new
107
+
108
+ module Delegator
109
+ def self.delegate(*methods)
110
+ Array(methods).each do |method_name|
111
+ define_method(method_name) do |*args, &block|
112
+ Delegator.target.send(method_name, *args, &block)
113
+ end
114
+ private method_name
115
+ end
116
+ end
117
+
118
+ delegate :set
119
+
120
+ class << self
121
+ attr_accessor :target
122
+ end
123
+
124
+ self.target = Application
125
+ end
126
+ end
127
+
128
+ include Minimo::Delegator
@@ -0,0 +1,16 @@
1
+ require 'logger'
2
+
3
+ module Minimo
4
+ class Logger
5
+ def initialize(dir, level = ::Logger::INFO)
6
+ @dir, @level = dir, level
7
+ end
8
+
9
+ def write(msg)
10
+ logger = ::Logger.new(File.new("#{@dir}/minimo.log", 'a+'), 'daily')
11
+ logger.level = @level
12
+ logger.info msg
13
+ logger.close
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Minimo
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'minimo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'minimo'
8
+ spec.version = Minimo::VERSION
9
+ spec.authors = ['kazu69']
10
+ spec.email = ['kazu.69.web+minimo@gmail.com']
11
+
12
+ spec.summary = 'Mini Http response mocking server'
13
+ spec.description = '
14
+ minimo is the server to mock a minimum of http response using the rack.'
15
+ spec.homepage = 'https://github.com/kazu69/minimo'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ # if spec.respond_to?(:metadata)
21
+ # spec.metadata['allowed_push_host'] = ''
22
+ # else
23
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency 'rack'
32
+ spec.add_development_dependency 'pry'
33
+ spec.add_development_dependency 'bundler', '~> 1.12'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rspec'
36
+ spec.add_development_dependency 'rack-test'
37
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minimo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kazu69
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |2-
98
+
99
+ minimo is the server to mock a minimum of http response using the rack.
100
+ email:
101
+ - kazu.69.web+minimo@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/minimo.rb
115
+ - lib/minimo/logger.rb
116
+ - lib/minimo/version.rb
117
+ - minimo.gemspec
118
+ homepage: https://github.com/kazu69/minimo
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.5.1
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Mini Http response mocking server
142
+ test_files: []