netrecorder 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/Manifest +2 -1
- data/README.rdoc +0 -2
- data/Rakefile +1 -1
- data/lib/config.rb +13 -0
- data/lib/http.rb +19 -2
- data/lib/http_header.rb +4 -1
- data/lib/netrecorder.rb +24 -5
- data/netrecorder.gemspec +4 -4
- metadata +4 -3
- metadata.gz.sig +0 -0
- data/gem-public_cert.pem +0 -20
data.tar.gz.sig
CHANGED
Binary file
|
data/Manifest
CHANGED
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('netrecorder', '0.1.
|
5
|
+
Echoe.new('netrecorder', '0.1.1') do |p|
|
6
6
|
p.description = "Record network responses for easy stubbing of external calls"
|
7
7
|
p.url = "http://github.com/tombombadil/netrecorder"
|
8
8
|
p.author = "Chris Young"
|
data/lib/config.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Config class is used to capture configuration options
|
2
|
+
module NetRecorder
|
3
|
+
class Config
|
4
|
+
# set to true to record net requests and responses to the cache file
|
5
|
+
attr_accessor :record_net_calls
|
6
|
+
# set to true to use fakeweb and the cache
|
7
|
+
attr_accessor :fakeweb
|
8
|
+
# path to the cache file
|
9
|
+
attr_accessor :cache_file
|
10
|
+
# clear the cache
|
11
|
+
attr_accessor :clear_cache
|
12
|
+
end
|
13
|
+
end
|
data/lib/http.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
# Extend Net:HTTP to record requests and responses
|
1
2
|
module NetRecorder
|
2
3
|
module NetHTTP
|
3
|
-
def self.extended(base)
|
4
|
+
def self.extended(base) #:nodoc:
|
4
5
|
base.class_eval do
|
5
6
|
alias :alias_for_request :request
|
6
|
-
@@fakes = {'GET' => {}, 'POST' => {}, 'DELETE' => {}, 'PUT' => {}}
|
7
|
+
@@fakes = fakes_cache || {'GET' => {}, 'POST' => {}, 'DELETE' => {}, 'PUT' => {}}
|
8
|
+
|
9
|
+
# request is overridden and the request and response are stored as a hash that can be written to a cache file
|
7
10
|
def request(req, body = nil, &block)
|
8
11
|
response = alias_for_request(req, body)
|
9
12
|
path = "http://#{req.bauth if req.bauth}#{req['host']}#{req.path}"
|
@@ -15,6 +18,7 @@ module NetRecorder
|
|
15
18
|
return response
|
16
19
|
end
|
17
20
|
|
21
|
+
# returns the fakes hash
|
18
22
|
def self.fakes
|
19
23
|
@@fakes
|
20
24
|
end
|
@@ -22,3 +26,16 @@ module NetRecorder
|
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
29
|
+
|
30
|
+
# Loads the yaml from the cache file and returns a hash
|
31
|
+
def fakes_cache
|
32
|
+
fakes =
|
33
|
+
if File.exist?(NetRecorder.cache_file)
|
34
|
+
File.open(NetRecorder.cache_file, "r") do |f|
|
35
|
+
YAML.load(f.read)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
return fakes if fakes.class == Hash
|
40
|
+
nil
|
41
|
+
end
|
data/lib/http_header.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
# Override Net:HTTP_Header to capture basic auth
|
1
2
|
module NetRecorder
|
2
3
|
module NetHTTPHeader
|
3
|
-
def self.extended(base)
|
4
|
+
def self.extended(base) #:nodoc:
|
4
5
|
base.class_eval do
|
5
6
|
alias :alias_for_basic_auth :basic_auth
|
6
7
|
attr_accessor :bauth
|
8
|
+
|
9
|
+
# override basic auth to make grabbing the basic auth easy
|
7
10
|
def basic_auth(account, password)
|
8
11
|
@bauth = "#{account}:#{password}@"
|
9
12
|
alias_for_basic_auth(account, password)
|
data/lib/netrecorder.rb
CHANGED
@@ -1,28 +1,46 @@
|
|
1
|
+
# NetRecorder allows you to record requests and responses from the web
|
2
|
+
|
1
3
|
require 'fakeweb'
|
2
4
|
require "#{File.dirname(__FILE__)}/http"
|
3
5
|
require "#{File.dirname(__FILE__)}/http_header"
|
6
|
+
require "#{File.dirname(__FILE__)}/config"
|
4
7
|
|
8
|
+
# NetRecorder - the global namespace
|
5
9
|
module NetRecorder
|
6
|
-
|
7
|
-
|
10
|
+
|
11
|
+
# the path to the cache file
|
12
|
+
def self.cache_file
|
13
|
+
@@config.cache_file
|
8
14
|
end
|
9
15
|
|
16
|
+
# configure netrecorder
|
10
17
|
def self.config
|
11
18
|
@@config = Config.new
|
12
19
|
yield @@config
|
20
|
+
clear_cache! if @@config.clear_cache
|
13
21
|
fakeweb if @@config.fakeweb
|
14
22
|
record_net_calls if @@config.record_net_calls
|
15
23
|
end
|
16
24
|
|
25
|
+
# returns true if record_net_calls is set to true in the config
|
17
26
|
def self.recording?
|
18
27
|
@@config.record_net_calls
|
19
28
|
end
|
20
29
|
|
21
|
-
|
30
|
+
# save the fakes hash to the cash file
|
31
|
+
def self.cache!
|
22
32
|
File.open(@@config.cache_file, 'w') {|f| f.write Net::HTTP.fakes.to_yaml}
|
23
33
|
end
|
24
34
|
|
25
|
-
|
35
|
+
# delete the cache file
|
36
|
+
def self.clear_cache!
|
37
|
+
if File.exist?(@@config.cache_file)
|
38
|
+
File.delete(@@config.cache_file)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
# load the cache and register all of the urls with fakeweb
|
26
44
|
def self.fakeweb
|
27
45
|
fakes = File.open(@@config.cache_file, "r") do |f|
|
28
46
|
YAML.load(f.read)
|
@@ -35,7 +53,8 @@ private
|
|
35
53
|
end
|
36
54
|
end
|
37
55
|
end
|
38
|
-
|
56
|
+
|
57
|
+
# extend NET library to record requests and responses
|
39
58
|
def self.record_net_calls
|
40
59
|
Net::HTTP.extend(NetHTTP)
|
41
60
|
Net::HTTPHeader.extend(NetHTTPHeader)
|
data/netrecorder.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{netrecorder}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Chris Young"]
|
9
9
|
s.cert_chain = ["/Users/chrisyoung/Documents/certificates/gem-public_cert.pem"]
|
10
|
-
s.date = %q{2010-01-
|
10
|
+
s.date = %q{2010-01-04}
|
11
11
|
s.description = %q{Record network responses for easy stubbing of external calls}
|
12
12
|
s.email = %q{beesucker@gmail.com}
|
13
|
-
s.extra_rdoc_files = ["README.rdoc", "lib/http.rb", "lib/http_header.rb", "lib/netrecorder.rb"]
|
14
|
-
s.files = ["Manifest", "README.rdoc", "Rakefile", "
|
13
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/config.rb", "lib/http.rb", "lib/http_header.rb", "lib/netrecorder.rb"]
|
14
|
+
s.files = ["Manifest", "README.rdoc", "Rakefile", "lib/config.rb", "lib/http.rb", "lib/http_header.rb", "lib/netrecorder.rb", "netrecorder.gemspec"]
|
15
15
|
s.homepage = %q{http://github.com/tombombadil/netrecorder}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Netrecorder", "--main", "README.rdoc"]
|
17
17
|
s.require_paths = ["lib"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netrecorder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Young
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
bIN1xy1IiuNcvw==
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2010-01-
|
33
|
+
date: 2010-01-04 00:00:00 -07:00
|
34
34
|
default_executable:
|
35
35
|
dependencies: []
|
36
36
|
|
@@ -42,6 +42,7 @@ extensions: []
|
|
42
42
|
|
43
43
|
extra_rdoc_files:
|
44
44
|
- README.rdoc
|
45
|
+
- lib/config.rb
|
45
46
|
- lib/http.rb
|
46
47
|
- lib/http_header.rb
|
47
48
|
- lib/netrecorder.rb
|
@@ -49,7 +50,7 @@ files:
|
|
49
50
|
- Manifest
|
50
51
|
- README.rdoc
|
51
52
|
- Rakefile
|
52
|
-
-
|
53
|
+
- lib/config.rb
|
53
54
|
- lib/http.rb
|
54
55
|
- lib/http_header.rb
|
55
56
|
- lib/netrecorder.rb
|
metadata.gz.sig
CHANGED
Binary file
|
data/gem-public_cert.pem
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
-----BEGIN CERTIFICATE-----
|
2
|
-
MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMRMwEQYDVQQDDApjaHJp
|
3
|
-
c3lvdW5nMRUwEwYKCZImiZPyLGQBGRYFYnV6YXoxEzARBgoJkiaJk/IsZAEZFgNj
|
4
|
-
b20wHhcNMTAwMTAxMDE0MTA2WhcNMTEwMTAxMDE0MTA2WjBBMRMwEQYDVQQDDApj
|
5
|
-
aHJpc3lvdW5nMRUwEwYKCZImiZPyLGQBGRYFYnV6YXoxEzARBgoJkiaJk/IsZAEZ
|
6
|
-
FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDu37vOHls+p6xf
|
7
|
-
vzazqbwWkjZhh+p6t8cMhDKzMD2O+ITMSIouKg8z2DkIDtvSnkZb3pfWEC/YkZu1
|
8
|
-
79RahOE79mSC4IB1gLeyEMmTg1TPJkNxIuoG632Sp09j2Eg8EUW1EToSFsh+gIwz
|
9
|
-
FcCBFWQ1yq0IgfQZ9+RM8a8Ei6uKfQXmm4wK6vZT5Lxp8Dv0nELoO1dkYV1WXkGh
|
10
|
-
AAFhUMX2Y9tp0x2XZztO2Z+AUL4GYD1PyU2Afh7qp/qQJZMVS0YJjulB2bnW2yn/
|
11
|
-
7vlBadeBo3Ohp1J+OJuMUtmnuOAcKo+4cbj3HT4xTyuUa+V3izENJKX3qWCTk1D+
|
12
|
-
mU8TzNlzAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
|
13
|
-
BBSTLbhEokEPfV+oVZKmXVmGucmgljANBgkqhkiG9w0BAQUFAAOCAQEAQqRkDRig
|
14
|
-
aHqxsoqnJjG9FgZCIidnYhLNj7c3hXy8OQKJMZYau5VSDZb8dS4hC+jxQuyXiRJr
|
15
|
-
z5E16Gbqkb2fRC/YU63FnfIg2ce7PlGTp8yw0Xypn3QBYywDAWWJS4TdguikEDOM
|
16
|
-
e8IOmSKyOVJ7Zn6DIC0qyVtdcacXuKXWqqYQaWNwFwlaSlud5mQlyB77lcj5E5Lc
|
17
|
-
2mBFwT18jFQay2vOU/lgBDXBQ/VmrgL22gnhLL2nSf++CHM8miqa39Jk2MPaTbMs
|
18
|
-
tMtvELogNijvQYORkxU83coIjJ0bIsxgbjeBoFEcWCKkq/e8uSLULcJR4nULhvR3
|
19
|
-
bIN1xy1IiuNcvw==
|
20
|
-
-----END CERTIFICATE-----
|