martinbtt-net-http-spy 0.1.1 → 0.1.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.
- data/Rakefile +40 -0
- data/VERSION +1 -0
- data/examples/fogbugz.rb +14 -0
- data/examples/google.rb +8 -0
- data/examples/twitter-calltrace.rb +7 -0
- data/examples/twitter-customlog.rb +8 -0
- data/examples/twitter-simple.rb +6 -0
- data/examples/twitter-verbose.rb +7 -0
- data/examples/twitter-withbody.rb +7 -0
- data/lib/net-http-spy.rb +50 -0
- data/net-http-spy.gemspec +63 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/spy_spec.rb +93 -0
- metadata +32 -30
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rake/gempackagetask"
|
3
|
+
require "rake/rdoctask"
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gemspec|
|
8
|
+
gemspec.name = "net-http-spy"
|
9
|
+
gemspec.summary = "Ever wondered what HTTP requests the Ruby gem you are using to connect to a third party API is making? Use HTTP Spy to see what is going on behind the scenes."
|
10
|
+
gemspec.email = "martin@beyondthetype.com"
|
11
|
+
gemspec.homepage = "http://github.com/martinbtt/net-http-spy"
|
12
|
+
gemspec.description = "Ever wondered what HTTP requests the Ruby gem you are using to connect to a third party API is making? Use HTTP Spy to see what is going on behind the scenes."
|
13
|
+
gemspec.authors = ["Martin Sadler"]
|
14
|
+
gemspec.files.include Dir["examples/*.rb"] + ["readme.markdown"]
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
18
|
+
end
|
19
|
+
|
20
|
+
task :default => :spec
|
21
|
+
|
22
|
+
require "spec"
|
23
|
+
require "spec/rake/spectask"
|
24
|
+
Spec::Rake::SpecTask.new do |t|
|
25
|
+
t.spec_opts = %w(--format specdoc --colour)
|
26
|
+
t.libs = ["spec"]
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
# Generate documentation
|
31
|
+
Rake::RDocTask.new do |rd|
|
32
|
+
rd.main = "readme.markdown"
|
33
|
+
rd.rdoc_files.include("readme.markdown", "lib/**/*.rb")
|
34
|
+
rd.rdoc_dir = "rdoc"
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'Clear out RDoc and generated packages'
|
38
|
+
task :clean => [:clobber_rdoc, :clobber_package] do
|
39
|
+
rm "#{spec.name}.gemspec"
|
40
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
data/examples/fogbugz.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Just showing an example of something other than Twitter.
|
2
|
+
require 'rubygems'
|
3
|
+
require 'fogbugz-api' # sudo gem install austinmoody-fogbugz-api
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','lib','spy'))
|
5
|
+
|
6
|
+
config = {:username => "yourusername",
|
7
|
+
:password => "yourpass",
|
8
|
+
:domain => "yourdomain.fogbugz.com"
|
9
|
+
}
|
10
|
+
|
11
|
+
Net::HTTP.http_logger_options = {:body => true, :trace => false}
|
12
|
+
|
13
|
+
@fogbugz = FogBugz.new(config[:domain],true) # create instance
|
14
|
+
@fogbugz.logon(config[:username],config[:password]) # logs into FogBugz and sets *token*
|
data/examples/google.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Just showing an example of something other than Twitter.
|
2
|
+
# Garb lets you access the Google Analytics API
|
3
|
+
require 'rubygems'
|
4
|
+
require 'garb'
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','lib','spy'))
|
6
|
+
|
7
|
+
Net::HTTP.http_logger_options = {:body => false, :trace => false, :verbose => false}
|
8
|
+
Garb::Session.login('yourgoogleusername', 'yourpassword')
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# See where the external API calls take place within the gem you are using with the :trace option
|
2
|
+
require 'rubygems'
|
3
|
+
require 'twitter'
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','lib','spy'))
|
5
|
+
|
6
|
+
Net::HTTP.http_logger_options = {:trace => true}
|
7
|
+
Twitter::Search.new('httparty').each { |r| r }
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# By default the logger outputs to STDOUT, it's easy to change this to a file if you like
|
2
|
+
# Great to capture and then use for testing with tools like FakeWeb when combined with :body => true
|
3
|
+
require 'rubygems'
|
4
|
+
require 'twitter'
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','lib','spy'))
|
6
|
+
|
7
|
+
Net::HTTP.http_logger = Logger.new('twitter.log')
|
8
|
+
Twitter::Search.new('httparty').each { |r| r }
|
@@ -0,0 +1,6 @@
|
|
1
|
+
# Simplist example. All you need to do is include the spy lib for it to start doing the right thing
|
2
|
+
require 'rubygems'
|
3
|
+
require 'twitter'
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','lib','spy'))
|
5
|
+
|
6
|
+
Twitter::Search.new('httparty').each { |r| r }
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Net::HTTP has it's own logging/debug functionality. Turn on :verbose to show the full raw HTTP communication
|
2
|
+
require 'rubygems'
|
3
|
+
require 'twitter'
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','lib','spy'))
|
5
|
+
|
6
|
+
Net::HTTP.http_logger_options = {:verbose => true}
|
7
|
+
Twitter::Search.new('httparty').each { |r| r }
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Display the full response/request body. Usually just the response code is shown.
|
2
|
+
require 'rubygems'
|
3
|
+
require 'twitter'
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','lib','spy'))
|
5
|
+
|
6
|
+
Net::HTTP.http_logger_options = {:body => true}
|
7
|
+
Twitter::Search.new('httparty').each { |r| r }
|
data/lib/net-http-spy.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'logger'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
# HTTP SPY
|
6
|
+
module Net
|
7
|
+
class HTTP
|
8
|
+
alias :old_initialize :initialize
|
9
|
+
alias :old_request :request
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :http_logger
|
13
|
+
attr_accessor :http_logger_options
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(*args, &block)
|
17
|
+
self.class.http_logger_options ||= {}
|
18
|
+
defaults = {:body => false, :trace => false, :verbose => false}
|
19
|
+
self.class.http_logger_options = (self.class.http_logger_options == :default) ? defaults : self.class.http_logger_options
|
20
|
+
@logger_options = defaults.merge(self.class.http_logger_options)
|
21
|
+
|
22
|
+
self.class.http_logger.info "CONNECT: #{args.inspect}" if !@logger_options[:verbose]
|
23
|
+
|
24
|
+
old_initialize(*args, &block)
|
25
|
+
@debug_output = self.class.http_logger if @logger_options[:verbose]
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def request(*args, &block)
|
30
|
+
unless started? || @logger_options[:verbose]
|
31
|
+
req = args[0].class::METHOD
|
32
|
+
self.class.http_logger.info "#{req} #{args[0].path}"
|
33
|
+
end
|
34
|
+
|
35
|
+
result = old_request(*args, &block)
|
36
|
+
unless started? || @logger_options[:verbose]
|
37
|
+
|
38
|
+
self.class.http_logger.info "PARAMS #{CGI.parse(args[0].body).inspect} " if args[0].body && req != 'CONNECT'
|
39
|
+
self.class.http_logger.info "TRACE: #{caller.reverse}" if @logger_options[:trace]
|
40
|
+
self.class.http_logger.info "BODY: #{ @logger_options[:body] ? result.body : result.class.name}"
|
41
|
+
end
|
42
|
+
result
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
Net::HTTP.http_logger = Logger.new(STDOUT)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{net-http-spy}
|
5
|
+
s.version = "0.1.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Martin Sadler"]
|
9
|
+
s.date = %q{2009-06-05}
|
10
|
+
s.description = %q{Ever wondered what HTTP requests the Ruby gem you are using to connect to a third party API is making? Use HTTP Spy to see what is going on behind the scenes.}
|
11
|
+
s.email = %q{martin@beyondthetype.com}
|
12
|
+
s.files = [
|
13
|
+
"Rakefile",
|
14
|
+
"VERSION",
|
15
|
+
"examples/fogbugz.rb",
|
16
|
+
"examples/fogbugz.rb",
|
17
|
+
"examples/google.rb",
|
18
|
+
"examples/google.rb",
|
19
|
+
"examples/twitter-calltrace.rb",
|
20
|
+
"examples/twitter-calltrace.rb",
|
21
|
+
"examples/twitter-customlog.rb",
|
22
|
+
"examples/twitter-customlog.rb",
|
23
|
+
"examples/twitter-simple.rb",
|
24
|
+
"examples/twitter-simple.rb",
|
25
|
+
"examples/twitter-verbose.rb",
|
26
|
+
"examples/twitter-verbose.rb",
|
27
|
+
"examples/twitter-withbody.rb",
|
28
|
+
"examples/twitter-withbody.rb",
|
29
|
+
"lib/net-http-spy.rb",
|
30
|
+
"net-http-spy.gemspec",
|
31
|
+
"readme.markdown",
|
32
|
+
"readme.markdown",
|
33
|
+
"spec/spec.opts",
|
34
|
+
"spec/spec_helper.rb",
|
35
|
+
"spec/spy_spec.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/martinbtt/net-http-spy}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.3}
|
41
|
+
s.summary = %q{Ever wondered what HTTP requests the Ruby gem you are using to connect to a third party API is making? Use HTTP Spy to see what is going on behind the scenes.}
|
42
|
+
s.test_files = [
|
43
|
+
"spec/spec_helper.rb",
|
44
|
+
"spec/spy_spec.rb",
|
45
|
+
"examples/fogbugz.rb",
|
46
|
+
"examples/google.rb",
|
47
|
+
"examples/twitter-calltrace.rb",
|
48
|
+
"examples/twitter-customlog.rb",
|
49
|
+
"examples/twitter-simple.rb",
|
50
|
+
"examples/twitter-verbose.rb",
|
51
|
+
"examples/twitter-withbody.rb"
|
52
|
+
]
|
53
|
+
|
54
|
+
if s.respond_to? :specification_version then
|
55
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
56
|
+
s.specification_version = 3
|
57
|
+
|
58
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
59
|
+
else
|
60
|
+
end
|
61
|
+
else
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'rspec'
|
3
|
+
require 'spec'
|
4
|
+
require 'net/http'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'twitter'
|
7
|
+
require 'mechanize'
|
8
|
+
|
9
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'spy')
|
10
|
+
|
11
|
+
|
12
|
+
class DummyLogger
|
13
|
+
|
14
|
+
attr_accessor :lines
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
reset!
|
18
|
+
end
|
19
|
+
|
20
|
+
def <<(msg)
|
21
|
+
@lines << msg
|
22
|
+
end
|
23
|
+
|
24
|
+
def info(msg)
|
25
|
+
@lines << msg
|
26
|
+
end
|
27
|
+
|
28
|
+
def reset!
|
29
|
+
@lines = []
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/spec/spy_spec.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
# Bare bones spec to make sure the core functionality is working
|
4
|
+
describe "Net:HTTP Spying on" do
|
5
|
+
before(:all) do
|
6
|
+
Net::HTTP.http_logger = DummyLogger.new()
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "a get request with default options" do
|
10
|
+
|
11
|
+
before(:all) do
|
12
|
+
Net::HTTP.http_logger.reset!
|
13
|
+
Twitter::Search.new('httparty').each { |r| r }
|
14
|
+
Net::HTTP.http_logger_options = :default
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should give the connection" do
|
19
|
+
Net::HTTP.http_logger.lines.should include("CONNECT: [\"search.twitter.com\", 80]")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should give GET uri and query string" do
|
23
|
+
Net::HTTP.http_logger.lines.should include("GET /search.json?q=httparty")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should give the BODY response code" do
|
27
|
+
Net::HTTP.http_logger.lines.should include("BODY: Net::HTTPOK")
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
describe "a get request with body option set to true" do
|
36
|
+
|
37
|
+
before(:each) do
|
38
|
+
Net::HTTP.http_logger.reset!
|
39
|
+
Net::HTTP.http_logger_options = {:body => true}
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
it "should give the body output" do
|
44
|
+
Twitter::Search.new('httparty').each { |r| r }
|
45
|
+
Net::HTTP.http_logger.lines.grep(/BODY: \{\"results\":/).should_not be_empty
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
describe "a get request with trace option set to true" do
|
52
|
+
|
53
|
+
before(:each) do
|
54
|
+
Net::HTTP.http_logger.reset!
|
55
|
+
Net::HTTP.http_logger_options = {:trace => true}
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
it "should give the trace output" do
|
60
|
+
Twitter::Search.new('httparty').each { |r| r }
|
61
|
+
Net::HTTP.http_logger.lines.grep(/TRACE: /).should_not be_empty
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "a post request with default options" do
|
67
|
+
|
68
|
+
before(:all) do
|
69
|
+
Net::HTTP.http_logger.reset!
|
70
|
+
@connection = Net::HTTP.new('http://search.twitter.com')
|
71
|
+
@connection.post('/','?q=hello')
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
it "should give the post uri" do
|
76
|
+
Net::HTTP.http_logger.lines.should include("POST /")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should give the post params" do
|
80
|
+
Net::HTTP.http_logger.lines.should include("PARAMS {\"?q\"=>[\"hello\"]} ")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should give the BODY response code" do
|
84
|
+
Net::HTTP.http_logger.lines.should include("BODY: Net::HTTPFound")
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: martinbtt-net-http-spy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Sadler
|
@@ -9,45 +9,39 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05
|
12
|
+
date: 2009-06-05 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
type: :development
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "0"
|
24
|
-
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: twitter
|
27
|
-
type: :development
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: "0"
|
34
|
-
version:
|
35
|
-
description:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ever wondered what HTTP requests the Ruby gem you are using to connect to a third party API is making? Use HTTP Spy to see what is going on behind the scenes.
|
36
17
|
email: martin@beyondthetype.com
|
37
18
|
executables: []
|
38
19
|
|
39
20
|
extensions: []
|
40
21
|
|
41
|
-
extra_rdoc_files:
|
42
|
-
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
43
24
|
files:
|
25
|
+
- Rakefile
|
26
|
+
- VERSION
|
27
|
+
- examples/fogbugz.rb
|
28
|
+
- examples/google.rb
|
29
|
+
- examples/twitter-calltrace.rb
|
30
|
+
- examples/twitter-customlog.rb
|
31
|
+
- examples/twitter-simple.rb
|
32
|
+
- examples/twitter-verbose.rb
|
33
|
+
- examples/twitter-withbody.rb
|
34
|
+
- lib/net-http-spy.rb
|
35
|
+
- net-http-spy.gemspec
|
44
36
|
- readme.markdown
|
37
|
+
- spec/spec.opts
|
38
|
+
- spec/spec_helper.rb
|
39
|
+
- spec/spy_spec.rb
|
45
40
|
has_rdoc: false
|
46
41
|
homepage: http://github.com/martinbtt/net-http-spy
|
47
42
|
post_install_message:
|
48
43
|
rdoc_options:
|
49
|
-
- --
|
50
|
-
- readme.markdown
|
44
|
+
- --charset=UTF-8
|
51
45
|
require_paths:
|
52
46
|
- lib
|
53
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -69,5 +63,13 @@ rubygems_version: 1.2.0
|
|
69
63
|
signing_key:
|
70
64
|
specification_version: 3
|
71
65
|
summary: Ever wondered what HTTP requests the Ruby gem you are using to connect to a third party API is making? Use HTTP Spy to see what is going on behind the scenes.
|
72
|
-
test_files:
|
73
|
-
|
66
|
+
test_files:
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
- spec/spy_spec.rb
|
69
|
+
- examples/fogbugz.rb
|
70
|
+
- examples/google.rb
|
71
|
+
- examples/twitter-calltrace.rb
|
72
|
+
- examples/twitter-customlog.rb
|
73
|
+
- examples/twitter-simple.rb
|
74
|
+
- examples/twitter-verbose.rb
|
75
|
+
- examples/twitter-withbody.rb
|