hoverfly 0.0.2

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: 9ea3d9618109d0f8e5181c050845e168ff36fd5e
4
+ data.tar.gz: 8feb22c719fba488f4c0155493cb3f5a23ae08b7
5
+ SHA512:
6
+ metadata.gz: c40742df721ad9465f8b1005ca9f682d07b31c1f6e0327c12c0534bb650bf2168b03e8ee0be0269384727fc35ebcd9106be8e24189d8da9799c8d1d1dda41412
7
+ data.tar.gz: 5723d1522fd4b21c588e68ae6238e91461ed9fd90739320787d4c85da6ac62ddc137aa5fa24b9fa88cc04d28d189f710fcfcaaf2f975241febe81fb8c7142995
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) Justin Commu <Justin.Commu@loblaw.ca>
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,89 @@
1
+ # Hoverfly Gem
2
+
3
+ Welcome to the Hoverfly Gem, a ruby written wrapper for Hoverfly!
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'hoverfly'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install hoverfly
20
+
21
+ ## Usage
22
+
23
+ This gem gives you full access to the Hoverfly API as well as the ability to spin up and tear down different Hoverfly instances. See below for examples, as well as a reference of the actions that can be done
24
+
25
+ ### Recording an API response
26
+ ```
27
+ require 'hoverfly'
28
+
29
+ Hoverfly.start('test')
30
+
31
+ # Set Hoverfly to capture mode
32
+ Hoverfly.update_mode('capture')
33
+
34
+ # Send the API request to be recorded
35
+ `curl --proxy http://localhost:8500 http://time.jsontest.com `
36
+
37
+ # Export the simulation that Hoverfly has recorded
38
+ file = File.open( "simulation.json", "w" )
39
+ file << Hoverfly.get_current_simulations
40
+ file.close
41
+
42
+ Hoverfly.stop
43
+ ```
44
+ ### Replaying an existing API response
45
+ ```
46
+ require 'hoverfly'
47
+
48
+ Hoverfly.start('test')
49
+
50
+ # Set Hoverfly to simulate mode
51
+ Hoverfly.update_mode('simulate')
52
+
53
+ # Import an existing simulation into Hoverfly
54
+ Hoverfly.import(['simulation.json'])
55
+
56
+ # Now when we make the API call, we will get the response that we imported into Hoverfly
57
+ `curl --proxy http://localhost:8500 http://time.jsontest.com `
58
+
59
+ Hoverfly.stop
60
+ ```
61
+
62
+ ### Available Methods
63
+ | Method | Description | Example |
64
+ |--------|-------------|---------|
65
+ |start(tag, ports)|This method starts up a new instance of Hoverfly. It takes in a tag, which is required, as well as an optional hash which allows you to specify the admin and proxy ports. If no hash is specified, then the default admin port (8888) and proxy port (8500) are used.| Hoverfly.start('test', {admin: 9000, proxy: 9001}|
66
+ |get_current_simulations|Returns the current simulation being used by Hoverfly|Hoverfly.get_current_simulations|
67
+ |get_current_simulation_schema|Returns the schema of the simulations currently being used by Hoverfly|Hoverfly.get_current_simulation_schema|
68
+ |get_config_info|Returns Hoverfly configuration info|Hoverfly.get_config_info|
69
+ |get_current_destination|Returns the current destination that has been set for Hoverfly. Once a destination has been set, Hoverfly only intercepts traffic for that URL|Hoverfly.get_current_destination|
70
+ |update_destinitation|Sets / updates the destination URL that Hoverfly looks at|Hoverfly.update_destination('http://time.jsontest.com')|
71
+ |get_current_middleware|Returns info about the middleware that Hoverfly is currently set to use|Hoverfly.get_current_middleware|
72
+ |middleware|This allows you to set the middleware to be used by Hoverfly. This method accepts a hash where the key specifies the type of middleware, and the value specifies the location. For example if wanted to use a remote server for your middleware, you would pass {remote: <server_url>} to this method|Hoverfly.middleware({remote: 'http://mymiddleware.com'})|
73
+ |get_current_mode|Returns the mode that Hoverfly is currently set to|Hoverfly.get_current_mode|
74
+ |update_mode|Changes the mode that Hoverfly in running in. By default, Hoverfly starts in simulate mdoe|Hoverfly.update_mode('capture')|
75
+ |get_usage|Returns usage info for Hoverfly|Hoverfly.get_usage|
76
+ |get_version|Returns the current Hoverfly version|Hoverfly.get_version|
77
+ |get_upstream_proxy|Returns the proxy port that Hoverfly is currently using|Hoverfly.get_upstream_proxy|
78
+ |get_cached_data|Returns data that Hoverfly has cached|Hoverfly.get_cached_data|
79
+ |clear_cached_data|Clears the Hoverfly cache|Hoverfly.clear_cached_data|
80
+ |get_logs|Returns the Hoverfly logs|Hoverfly.get_logs|
81
+ |stop|Kills the current instance of Hoverfly. This shuts down Hoverfly and deletes the tag used to start that instance. Once Hoverfly is stopped, the tag can be reused|Hoverfly.stop|
82
+
83
+ ## Contributing
84
+
85
+ Bug reports and pull requests are welcome. Note that if you are reporting a bug then make sure to include a failing spec that highlights an example of the bug. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
86
+
87
+ ## License
88
+
89
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/lib/client.rb ADDED
@@ -0,0 +1,54 @@
1
+ class Hoverfly
2
+ extend HoverflyAPI
3
+
4
+ class << self
5
+ attr_reader :target
6
+
7
+ def start(target, ports = {})
8
+ @target = target
9
+ admin_port = ports.fetch(:admin, 8888)
10
+ proxy_port = ports.fetch(:proxy, 8500)
11
+ puts "Starting target #{target} with admin #{admin_port} and proxy #{proxy_port}"
12
+ system "hoverctl targets create #{@target}"
13
+ system "hoverctl start --admin-port #{admin_port} --proxy-port #{proxy_port} -t #{@target}"
14
+ HoverflyAPI.default_options.update(verify: false)
15
+ HoverflyAPI.format :json
16
+ HoverflyAPI.base_uri "http://localhost:#{admin_port}"
17
+ end
18
+
19
+ def stop
20
+ puts "Stopping target #{Hoverfly.target} with base URL #{HoverflyAPI.base_uri}"
21
+ system "hoverctl stop -t #{@target}"
22
+ system "hoverctl targets delete #{@target} -f"
23
+ end
24
+
25
+ def middleware(middleware_location)
26
+ update_middleware({binary: '', script: '', remote: ''}.merge(middleware_location))
27
+ end
28
+
29
+ def import(file_list)
30
+ update_simulations(to_simulation(file_list))
31
+ end
32
+
33
+ private
34
+
35
+ def to_simulation(file_list, meta = {})
36
+ header_path = meta[:header] || File.expand_path('schema_metadata/header.json', __dir__)
37
+ footer_path = meta[:footer] || File.expand_path('schema_metadata/footer.json', __dir__)
38
+ header = File.open(header_path)
39
+ footer = File.open(footer_path)
40
+ mock = header.read
41
+ all_simulations = file_list.map do |filename|
42
+ file = File.open(filename)
43
+ simulation = file.read
44
+ file.close
45
+ simulation
46
+ end
47
+ mock << all_simulations.join(',')
48
+ mock << footer.read
49
+ header.close
50
+ footer.close
51
+ mock
52
+ end
53
+ end
54
+ end
data/lib/endpoints.rb ADDED
@@ -0,0 +1,67 @@
1
+ module HoverflyAPI
2
+ include HTTParty
3
+
4
+ def get_current_simulations
5
+ HoverflyAPI.get('/api/v2/simulation').response.body
6
+ end
7
+
8
+ def update_simulations(simulation)
9
+ HoverflyAPI.put('/api/v2/simulation', headers: { 'Content-Type' => 'application/json' }, body: simulation).response.body
10
+ end
11
+
12
+ def get_current_simulation_schema
13
+ HoverflyAPI.get('/api/v2/simulation/schema').response.body
14
+ end
15
+
16
+ def get_config_info
17
+ HoverflyAPI.get('/api/v2/hoverfly').response.body
18
+ end
19
+
20
+ def get_current_destination
21
+ HoverflyAPI.get(' /api/v2/hoverfly/destination').response.body
22
+ end
23
+
24
+ def update_destinitation(destination)
25
+ HoverflyAPI.put(' /api/v2/hoverfly/destination', headers: { 'Content-Type' => 'application/json' }, body: { destination: destination }.to_json).response.body
26
+ end
27
+
28
+ def get_current_middleware
29
+ HoverflyAPI.get('/api/v2/hoverfly/middleware').response.body
30
+ end
31
+
32
+ def update_middleware(middleware_request)
33
+ HoverflyAPI.put('/api/v2/hoverfly/middleware', headers: { 'Content-Type' => 'application/json' }, body: middleware_request.to_json).response.body
34
+ end
35
+
36
+ def get_current_mode
37
+ HoverflyAPI.get('/api/v2/hoverfly/mode').response.body
38
+ end
39
+
40
+ def update_mode(mode)
41
+ HoverflyAPI.put('/api/v2/hoverfly/mode', headers: { 'Content-Type' => 'application/json' }, body: { mode: mode }.to_json).response.body
42
+ end
43
+
44
+ def get_usage
45
+ HoverflyAPI.get('/api/v2/hoverfly/usage').response.body
46
+ end
47
+
48
+ def get_version
49
+ HoverflyAPI.get('/api/v2/hoverfly/version').response.body
50
+ end
51
+
52
+ def get_upstream_proxy
53
+ HoverflyAPI.get('/api/v2/hoverfly/upstream-proxy').response.body
54
+ end
55
+
56
+ def get_cached_data
57
+ HoverflyAPI.get('/api/v2/cache').response.body
58
+ end
59
+
60
+ def clear_cached_data
61
+ HoverflyAPI.delete('/api/v2/cache').response.body
62
+ end
63
+
64
+ def get_logs
65
+ HoverflyAPI.get('/api/v2/logs').response.body
66
+ end
67
+ end
data/lib/hoverfly.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ require_relative 'endpoints'
5
+ require_relative 'client'
@@ -0,0 +1,11 @@
1
+ ],
2
+ "globalActions": {
3
+ "delays": []
4
+ }
5
+ },
6
+ "meta": {
7
+ "schemaVersion": "v2",
8
+ "hoverflyVersion": "v0.10.2",
9
+ "timeExported": "2017-05-05T15:10:36-04:00"
10
+ }
11
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "data": {
3
+ "pairs": [
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hoverfly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Automation Wizards
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.13.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.13.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.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.11.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.11.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.4.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.4.0
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.4
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.4
83
+ description: Use this library to interact with Hoverfly in ruby
84
+ email:
85
+ - bjorn.ramroop@loblaw.ca
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE
91
+ - README.md
92
+ - lib/client.rb
93
+ - lib/endpoints.rb
94
+ - lib/hoverfly.rb
95
+ - lib/schema_metadata/footer.json
96
+ - lib/schema_metadata/header.json
97
+ homepage: https://github.com/automation-wizards/hoverfly
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.6.11
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Ruby wrapper for Hoverfly
121
+ test_files: []