http_sim 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1d34b11fafc50dc00080712a9a8486e65c8e3d1a
4
+ data.tar.gz: bad07a227278bfefc44dcdd0599a5671a9970e99
5
+ SHA512:
6
+ metadata.gz: 0de209fcf1debc3225379e2443ee6dc91607cddd318a1cdb24ffe41928dc500cc7db114f5535f80e81bc0017ece02e81c5e7f66c254659f2c1d12eae99486fa2
7
+ data.tar.gz: 1c412c2dc5197e70dbe0690c11ed5ac83ded8892493869e23a8526c7d39ab38ccab39d2ead6929312cb45084236dca12118144adbe97827937f967e7613b6b5f
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea
16
+ *.iml
17
+ *.gem
data/.rbenv-gemsets ADDED
@@ -0,0 +1 @@
1
+ -global
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in scaffold.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Jean de Klerk
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,31 @@
1
+ # Scaffold
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'scaffold'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install scaffold
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/scaffold/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
data/example.rb ADDED
@@ -0,0 +1,5 @@
1
+ require_relative 'lib/http_sim'
2
+
3
+ HttpSimulator.register_endpoint 'GET', '/hi', 'yasssss'
4
+ HttpSimulator.register_endpoint 'POST', '/bye', 'byeeeee'
5
+ HttpSimulator.run!
data/http_sim.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'http_sim'
7
+ spec.version = '0.0.1'
8
+ spec.authors = ['Jean de Klerk']
9
+ spec.email = ['jadekler@gmail.com']
10
+ spec.summary = 'Simulate your external HTTP integrations.'
11
+ spec.description = 'A set of utilities for creating simulators for your external HTTP integrations, great for acceptance tests and fallback services.'
12
+ spec.homepage = 'http://github.com/jadekler/http_sim'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_runtime_dependency 'sinatra', '~> 1.4'
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ end
data/lib/http_sim.rb ADDED
@@ -0,0 +1,106 @@
1
+ require 'sinatra/base'
2
+
3
+ class Endpoint
4
+ attr_reader :method, :path, :default_response, :response
5
+ attr_accessor :requests
6
+
7
+ @@supported_methods = ['GET', 'PUT', 'PATCH', 'POST', 'DELETE']
8
+
9
+ def initialize(method, path, default_response)
10
+ raise "Unsupported method #{method}" unless @@supported_methods.include? method
11
+
12
+ @method = method
13
+ @path = path
14
+ @response = default_response
15
+ @default_response = default_response
16
+ @requests = []
17
+ end
18
+
19
+ def add_request(request)
20
+ @requests.push request
21
+ end
22
+ end
23
+
24
+ module HttpSimulator
25
+ def self.read_file(path)
26
+ lines = []
27
+ File.open(path, 'r') do |f|
28
+ f.each_line do |line|
29
+ lines.push line
30
+ end
31
+ end
32
+ lines.join
33
+ end
34
+
35
+ @@erb_files = {
36
+ index: self.read_file('lib/index.html.erb'),
37
+ request: self.read_file('lib/request.html.erb'),
38
+ response: self.read_file('lib/response.html.erb')
39
+ }
40
+ @@endpoints = []
41
+
42
+ def self.run!
43
+ Sinatra::Base.get '/' do
44
+ ERB.new(@@erb_files[:index]).result binding
45
+ end
46
+
47
+ Class.new(Sinatra::Base) {
48
+ include HttpSimulator
49
+ }.run!
50
+ end
51
+
52
+ def self.register_endpoint(method, path, default_response)
53
+ raise '/ is a reserved path' if path == '/'
54
+
55
+ endpoint = Endpoint.new(method, path, default_response)
56
+ @@endpoints.push endpoint
57
+
58
+ case endpoint.method
59
+ when 'GET'
60
+ Sinatra::Base.get endpoint.path do
61
+ endpoint.add_request request.body.read
62
+ endpoint.default_response
63
+ end
64
+ when 'PUT'
65
+ Sinatra::Base.put endpoint.path do
66
+ endpoint.add_request request.body.read
67
+ endpoint.default_response
68
+ end
69
+ when 'PATCH'
70
+ Sinatra::Base.patch endpoint.path do
71
+ endpoint.add_request request.body.read
72
+ endpoint.default_response
73
+ end
74
+ when 'POST'
75
+ Sinatra::Base.post endpoint.path do
76
+ endpoint.add_request request.body.read
77
+ endpoint.default_response
78
+ end
79
+ when 'DELETE'
80
+ Sinatra::Base.delete endpoint.path do
81
+ endpoint.add_request request.body.read
82
+ endpoint.default_response
83
+ end
84
+ end
85
+
86
+ Sinatra::Base.get "#{endpoint.path}/response" do
87
+ ERB.new(@@erb_files[:response]).result binding
88
+ end
89
+
90
+ Sinatra::Base.put "#{endpoint.path}/response" do
91
+ endpoint.response = request.body.read
92
+ end
93
+
94
+ Sinatra::Base.delete "#{endpoint.path}/response" do
95
+ endpoint.response = endpoint.default_response
96
+ end
97
+
98
+ Sinatra::Base.get "#{endpoint.path}/requests" do
99
+ ERB.new(@@erb_files[:request]).result binding
100
+ end
101
+
102
+ Sinatra::Base.delete "#{endpoint.path}/requests" do
103
+ endpoint.requests = []
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,40 @@
1
+ <html>
2
+ <head>
3
+ <style>
4
+ body {
5
+ padding: 20px;
6
+ }
7
+
8
+ table {
9
+ border-collapse: collapse;
10
+ }
11
+
12
+ td, th {
13
+ padding: 10px;
14
+ text-align: left;
15
+ border: 1px solid gray;
16
+ }
17
+ </style>
18
+ </head>
19
+ <body>
20
+ <h2>Simulators</h2>
21
+ <table>
22
+ <thead>
23
+ <tr>
24
+ <th>Simulated endpoint</th>
25
+ <th>Response</th>
26
+ <th>Requests</th>
27
+ </tr>
28
+ </thead>
29
+ <tbody>
30
+ <% @@endpoints.each do |endpoint| %>
31
+ <tr>
32
+ <td><%= endpoint.method %> <%= endpoint.path %></td>
33
+ <td><a href="<%= endpoint.path %>/response"><%= endpoint.path %>/response</a></td>
34
+ <td><a href="<%= endpoint.path %>/requests"><%= endpoint.path %>/requests</a></td>
35
+ </tr>
36
+ <% end %>
37
+ </tbody>
38
+ </table>
39
+ </body>
40
+ </html>
@@ -0,0 +1,17 @@
1
+ <html>
2
+ <head></head>
3
+ <body>
4
+ <h2>Requests for: <%= endpoint.method %> <%= endpoint.path %></h2>
5
+
6
+ <table>
7
+ <tbody>
8
+ <% endpoint.requests.each_with_index do |request, index| %>
9
+ <tr>
10
+ <td><%= index %>:</td>
11
+ <td><pre><%= request %></pre></td>
12
+ </tr>
13
+ <% end %>
14
+ </tbody>
15
+ </table>
16
+ </body>
17
+ </html>
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head></head>
3
+ <body>
4
+ <h2>Response for: <%= endpoint.method %> <%= endpoint.path %></h2>
5
+
6
+ <div>Response stuff goes here</div>
7
+ </body>
8
+ </html>
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: http_sim
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jean de Klerk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: A set of utilities for creating simulators for your external HTTP integrations,
56
+ great for acceptance tests and fallback services.
57
+ email:
58
+ - jadekler@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rbenv-gemsets"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - example.rb
70
+ - http_sim.gemspec
71
+ - lib/http_sim.rb
72
+ - lib/index.html.erb
73
+ - lib/request.html.erb
74
+ - lib/response.html.erb
75
+ homepage: http://github.com/jadekler/http_sim
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Simulate your external HTTP integrations.
99
+ test_files: []