benschwarz-openuri_recorder 0.1.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.
- data/LICENSE +20 -0
- data/README.mdown +25 -0
- data/VERSION.yml +4 -0
- data/lib/openuri_recorder.rb +57 -0
- data/spec/openuri_recorder_spec.rb +7 -0
- data/spec/spec_helper.rb +9 -0
- metadata +60 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Ben Schwarz
|
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.mdown
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# OpenURI Recorder
|
2
|
+
|
3
|
+
## What does it do?
|
4
|
+
captures your openuri "gets" and executes them with curl (cli),
|
5
|
+
the response (including headers) is then saved in plain text files
|
6
|
+
with a manifest for you to work out what goes where later.
|
7
|
+
|
8
|
+
This is so that you can quickly ascertain all of your openuri queries
|
9
|
+
for use with "fakeweb". Handy if you're trying to add fixtures / local
|
10
|
+
http for before a flight.
|
11
|
+
|
12
|
+
## Why?
|
13
|
+
|
14
|
+
I had 30 minutes spare and I needed to get all the remote web service calls together for [my app](http://ffolio.net) before a 20 hour flight.
|
15
|
+
|
16
|
+
## How to use it
|
17
|
+
|
18
|
+
require 'openuri_recorder'
|
19
|
+
|
20
|
+
Thats it! Don't use it with anything else that overrides openuri or else it probably just won't work properly.
|
21
|
+
Files will be dumped into a directory named `open-uri-recordings` with a `MANIFEST` for you to peice together.
|
22
|
+
|
23
|
+
Fakeweb allows you to register urls and return a whole response (like the one this library will record for you) using: `Fakeweb.register_uri("http://fake.tld/page", :response => '/path/to/your/response')`
|
24
|
+
|
25
|
+
### I suck, there are no specs.
|
data/VERSION.yml
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'digest/md5'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
RECORD_PATH = File.join(Dir.pwd, 'open-uri-recordings')
|
6
|
+
FileUtils.mkdir_p(RECORD_PATH)
|
7
|
+
|
8
|
+
module Kernel
|
9
|
+
alias_method :openuri_unmodified, :open
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def open(uri, *rest, &block)
|
14
|
+
OpenURI::Recorder.open(uri, *rest, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module OpenURI
|
19
|
+
module Recorder
|
20
|
+
class << self
|
21
|
+
def open(uri, *rest, &block)
|
22
|
+
response = StringIO.new(openuri_unmodified(uri, *rest, &block).read)
|
23
|
+
|
24
|
+
unless File.exists?(File.join(RECORD_PATH, Digest::MD5.hexdigest(uri)))
|
25
|
+
Manifest.add(uri)
|
26
|
+
record(uri)
|
27
|
+
end
|
28
|
+
|
29
|
+
if block_given?
|
30
|
+
begin
|
31
|
+
yield response
|
32
|
+
ensure
|
33
|
+
response.close
|
34
|
+
end
|
35
|
+
else
|
36
|
+
response
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def record(uri)
|
41
|
+
File.open(File.join(RECORD_PATH, Digest::MD5.hexdigest(uri)), 'w') {|f| f.write(`curl -i #{uri}`) }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module Manifest
|
46
|
+
class << self
|
47
|
+
def file
|
48
|
+
@file ||= File.new(File.join(RECORD_PATH, "MANIFEST"), "a")
|
49
|
+
end
|
50
|
+
|
51
|
+
def add(uri)
|
52
|
+
file.write "#{Digest::MD5.hexdigest(uri)} #{uri}\n"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: benschwarz-openuri_recorder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Schwarz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-30 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: ben.schwarz@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.mdown
|
24
|
+
- LICENSE
|
25
|
+
files:
|
26
|
+
- README.mdown
|
27
|
+
- VERSION.yml
|
28
|
+
- lib/openuri_recorder.rb
|
29
|
+
- spec/openuri_recorder_spec.rb
|
30
|
+
- spec/spec_helper.rb
|
31
|
+
- LICENSE
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://github.com/benschwarz/openuri_recorder
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options:
|
36
|
+
- --inline-source
|
37
|
+
- --charset=UTF-8
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.2.0
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: TODO
|
59
|
+
test_files: []
|
60
|
+
|