fake_http 0.1.0

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: f61ea5010682a14232d3b81aac1797c75255935a
4
+ data.tar.gz: b811bbf26fb5c18d628e42aa1ea7197130759bd6
5
+ SHA512:
6
+ metadata.gz: 1a9d24702d7628f54d8cac226dfa2b10cda5b478405d7a28a6a1d3a6e90316e84c3914a9e008fecf2ab165b1fb68f87c66423e91f2f8cd047d2a0a5b4f17d028
7
+ data.tar.gz: 924c8da4487f16bdc5940a4c8578a90a6f9e98059ba2364be7feb47d1c992ba33eb25efbc3bfb30e9c6dbc5d8c877097a1dd70e5464b9399811fbb7984b4f362
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2017 []().
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # FakeHttp
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/fake_http.svg)](http://badge.fury.io/rb/fake_http)
4
+
5
+ <!-- Tocer[start]: Auto-generated, don't remove. -->
6
+
7
+ # Table of Contents
8
+
9
+ - [Features](#features)
10
+ - [Screencasts](#screencasts)
11
+ - [Requirements](#requirements)
12
+ - [Setup](#setup)
13
+ - [Usage](#usage)
14
+ - [Tests](#tests)
15
+ - [Versioning](#versioning)
16
+ - [Code of Conduct](#code-of-conduct)
17
+ - [Contributions](#contributions)
18
+ - [License](#license)
19
+ - [History](#history)
20
+ - [Credits](#credits)
21
+
22
+ <!-- Tocer[finish]: Auto-generated, don't remove. -->
23
+
24
+ # Features
25
+
26
+ # Screencasts
27
+
28
+ # Requirements
29
+
30
+ 0. [Ruby 2.4.0](https://www.ruby-lang.org)
31
+
32
+ # Setup
33
+
34
+ For a secure install, type the following (recommended):
35
+
36
+ gem cert --add <(curl --location --silent /gem-public.pem)
37
+ gem install fake_http --trust-policy MediumSecurity
38
+
39
+ NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification
40
+ while allowing the installation of unsigned dependencies since they are beyond the scope of this
41
+ gem.
42
+
43
+ For an insecure install, type the following (not recommended):
44
+
45
+ gem install fake_http
46
+
47
+ Add the following to your Gemfile:
48
+
49
+ gem "fake_http"
50
+
51
+ # Usage
52
+
53
+ # Tests
54
+
55
+ To test, run:
56
+
57
+ bundle exec rake
58
+
59
+ # Versioning
60
+
61
+ Read [Semantic Versioning](http://semver.org) for details. Briefly, it means:
62
+
63
+ - Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.
64
+ - Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
65
+ - Major (X.y.z) - Incremented for any backwards incompatible public API changes.
66
+
67
+ # Code of Conduct
68
+
69
+ Please note that this project is released with a [CODE OF CONDUCT](CODE_OF_CONDUCT.md). By
70
+ participating in this project you agree to abide by its terms.
71
+
72
+ # Contributions
73
+
74
+ Read [CONTRIBUTING](CONTRIBUTING.md) for details.
75
+
76
+ # License
77
+
78
+ Copyright (c) 2017 []().
79
+ Read [LICENSE](LICENSE.md) for details.
80
+
81
+ # History
82
+
83
+ Read [CHANGES](CHANGES.md) for details.
84
+ Built with [Gemsmith](https://github.com/bkuhlmann/gemsmith).
85
+
86
+ # Credits
87
+
88
+ Developed by [Paul Sadauskas]() at
89
+ []().
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FakeHTTP
4
+ # Gem identity information.
5
+ module Identity
6
+ def self.name
7
+ "fake_http"
8
+ end
9
+
10
+ def self.label
11
+ "FakeHTTP"
12
+ end
13
+
14
+ def self.version
15
+ "0.1.0"
16
+ end
17
+
18
+ def self.version_label
19
+ "#{label} #{version}"
20
+ end
21
+ end
22
+ end
data/lib/fake_http.rb ADDED
@@ -0,0 +1,84 @@
1
+ require "fake_http/identity"
2
+
3
+ require "http"
4
+
5
+ class FakeHTTP
6
+ include HTTP::Chainable
7
+
8
+ def initialize(&block)
9
+ @builder = Builder.new
10
+ @builder.instance_eval(&block)
11
+ end
12
+
13
+ private
14
+
15
+ def branch(options)
16
+ Client.new(options, builder: @builder)
17
+ end
18
+
19
+ class Client
20
+ include HTTP::Chainable
21
+
22
+ def initialize(options, builder:)
23
+ @options, @builder = options, builder
24
+ end
25
+
26
+ def request(*args)
27
+ @builder.request(*args)
28
+ end
29
+
30
+ def branch(options)
31
+ self.class.new(@options.merge(options), builder: @builder)
32
+ end
33
+ end
34
+
35
+ class Builder
36
+
37
+ def initialize
38
+ @fakes = Hash.new { |h,k| h[k] = Array.new }
39
+ end
40
+
41
+ def get(pattern, &block)
42
+ responder = Responder.new(pattern, block)
43
+ @fakes[:get] << responder
44
+ end
45
+
46
+ def request(verb, uri, options = {})
47
+ responder = @fakes[verb].detect { |responder| responder.match(uri) }
48
+ responder.call(uri, options)
49
+ end
50
+
51
+ end
52
+
53
+ require "mustermann"
54
+ class Responder
55
+ def initialize(pattern, code)
56
+ @pattern, @code = Mustermann.new(pattern), code
57
+ end
58
+
59
+ def match(uri)
60
+ @pattern.match(uri)
61
+ end
62
+
63
+ def call(uri, options)
64
+ params = @pattern.params(uri)
65
+ status 200
66
+ content_type "application/json"
67
+ body = instance_exec(params, options, &@code)
68
+ HTTP::Response.new(status: status, version: "1.1", headers: headers, body: body.to_json)
69
+ end
70
+
71
+ def status(new_status=nil)
72
+ @status = new_status if new_status
73
+ @status
74
+ end
75
+
76
+ def content_type(mime_type)
77
+ headers["Content-Type"] = mime_type
78
+ end
79
+
80
+ def headers
81
+ @headers ||= {}
82
+ end
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,204 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fake_http
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Sadauskas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
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: mustermann
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gemsmith
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '8.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '8.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-state
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.5'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.5'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '4.7'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '4.7'
139
+ - !ruby/object:Gem::Dependency
140
+ name: reek
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '4.5'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '4.5'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.46'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.46'
167
+ description:
168
+ email:
169
+ - psadauskas@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files:
173
+ - README.md
174
+ - LICENSE.md
175
+ files:
176
+ - LICENSE.md
177
+ - README.md
178
+ - lib/fake_http.rb
179
+ - lib/fake_http/identity.rb
180
+ homepage: ''
181
+ licenses:
182
+ - MIT
183
+ metadata: {}
184
+ post_install_message:
185
+ rdoc_options: []
186
+ require_paths:
187
+ - lib
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ requirements: []
199
+ rubyforge_project:
200
+ rubygems_version: 2.6.8
201
+ signing_key:
202
+ specification_version: 4
203
+ summary: ''
204
+ test_files: []