har 0.0.1.dev → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Jari Bakken
1
+ Copyright (c) 2011 Jari Bakken
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -19,6 +19,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- harviewer by Jan Odvarko is covered by the New BSD License
22
+ harviewer is Copyright (c) Jan Odvarko and is covered by the New BSD License
23
23
  http://www.opensource.org/licenses/bsd-license.php
24
24
  http://code.google.com/p/harviewer/
25
+
@@ -2,7 +2,7 @@ HAR
2
2
  ===
3
3
 
4
4
  Ruby library to work with and view HTTP archives.
5
- This includes [harviewer](http://code.google.com/p/harviewer/), which can be launched through the "har" command.
5
+ This includes [harviewer][viewer], which can be launched through the "har" command.
6
6
 
7
7
  Usage
8
8
  =============
@@ -10,15 +10,10 @@ Usage
10
10
  HAR::Archive.from_string(json) #=> #<Har::Archive:0x5e7cac>
11
11
  HAR::Archive.from_file(path) #=> #<Har::Archive:0x5e7cac>
12
12
 
13
- Or from command the command line:
13
+ Or launch a local [harviewer][viewer] the command line:
14
14
 
15
15
  har /path/to/some.har
16
16
 
17
- Links
18
- =====
19
-
20
- * [harviewer](http://code.google.com/p/harviewer/)
21
-
22
17
  Note on Patches/Pull Requests
23
18
  =============================
24
19
 
@@ -33,4 +28,6 @@ Note on Patches/Pull Requests
33
28
  Copyright
34
29
  =========
35
30
 
36
- Copyright (c) 2010 Jari Bakken. See LICENSE for details.
31
+ Copyright (c) 2011 Jari Bakken. See LICENSE for details.
32
+
33
+ [viewer]: http://code.google.com/p/harviewer/
@@ -1,3 +1,3 @@
1
1
  module HAR
2
- VERSION = "0.0.1.dev"
2
+ VERSION = "0.0.1"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require "webrick"
2
2
  require "launchy"
3
+ require "optparse"
3
4
 
4
5
  module HAR
5
6
  class Viewer
@@ -9,8 +10,7 @@ module HAR
9
10
  @running = false
10
11
  @options = parse(args)
11
12
 
12
- hars = create_archives args
13
- @har = merge hars
13
+ @har = merge archives_from(args)
14
14
  end
15
15
 
16
16
  def show
@@ -21,40 +21,65 @@ module HAR
21
21
 
22
22
  private
23
23
 
24
- def create_archives(hars)
24
+ def archives_from(hars)
25
25
  hars = hars.map { |path| Archive.from_file(path) }
26
- hars.each { |h| h.validate! }
26
+
27
+ if @options[:validate]
28
+ progress("Validating archives...") do
29
+ hars.each { |h| h.validate! }
30
+ end
31
+ end
32
+
33
+ hars
27
34
  end
28
35
 
29
36
  def create_root
30
- viewer = File.expand_path("../viewer", __FILE__)
31
- tmp_dir = Dir.mktmpdir("harviewer")
37
+ progress("Creating viewer...") {
38
+ viewer = File.expand_path("../viewer", __FILE__)
39
+ tmp_dir = Dir.mktmpdir("harviewer")
32
40
 
33
- at_exit { FileUtils.rm_rf tmp_dir }
34
- FileUtils.cp_r viewer, tmp_dir
41
+ at_exit { FileUtils.rm_rf tmp_dir }
42
+ FileUtils.cp_r viewer, tmp_dir
35
43
 
36
- har.save_to File.join(tmp_dir, 'viewer', url_friendly(@har.uri))
44
+ har.save_to File.join(tmp_dir, 'viewer', url_friendly(@har.uri))
37
45
 
38
- tmp_dir
46
+ tmp_dir
47
+ }
39
48
  end
40
49
 
41
50
  def merge(hars)
42
- har = hars.shift or raise Error, "no HARs given"
51
+ progress("Merging hars...") {
52
+ har = hars.shift or raise Error, "no HARs given"
43
53
 
44
- unless hars.empty?
45
- hars.each { |h| har.merge! h }
46
- end
54
+ unless hars.empty?
55
+ hars.each { |h| har.merge! h }
56
+ end
47
57
 
48
- har
58
+ har
59
+ }
49
60
  end
50
61
 
51
62
  DEFAULT_OPTIONS = {
52
- :port => 9292
63
+ :port => 9292,
64
+ :validate => false
53
65
  }
54
66
 
55
67
  def parse(args)
56
- # TODO: parse command line
57
- DEFAULT_OPTIONS.dup
68
+ options = DEFAULT_OPTIONS.dup
69
+
70
+ OptionParser.new do |opts|
71
+ opts.banner = "Usage: har [options] [files]"
72
+
73
+ opts.on "-p", "--port PORT", Integer do |int|
74
+ options[:port] = int
75
+ end
76
+
77
+ opts.on "-v", "--validate" do
78
+ options[:validate] = true
79
+ end
80
+ end.parse!(args)
81
+
82
+ options
58
83
  end
59
84
 
60
85
  def url
@@ -75,7 +100,7 @@ module HAR
75
100
 
76
101
  def server(root)
77
102
  Thread.new do
78
- puts "Starting HAR Viewer Server..."
103
+ puts "Starting server..."
79
104
  puts "Type ^C to exit\n\n"
80
105
 
81
106
  server = WEBrick::HTTPServer.new(:Port => port,
@@ -95,5 +120,13 @@ module HAR
95
120
  Launchy.open url
96
121
  end
97
122
 
123
+ def progress(msg, &blk)
124
+ print msg
125
+ res = yield
126
+ puts "done."
127
+
128
+ res
129
+ end
130
+
98
131
  end # Viewer
99
132
  end # HAR
@@ -4,13 +4,18 @@ module HAR
4
4
  describe Viewer do
5
5
 
6
6
  context "creating" do
7
- it "validates the given HARs" do
8
- lambda { Viewer.new(all_hars) }.should raise_error(ValidationError)
7
+ it "validates the given HARs if asked to" do
8
+ lambda { Viewer.new(["--validate", *all_hars]) }.should raise_error(ValidationError)
9
9
  end
10
10
 
11
11
  it "has a merged archive" do
12
12
  Viewer.new(good_hars).har.should be_kind_of(Archive)
13
13
  end
14
+
15
+ it "parses options" do
16
+ v = Viewer.new(["-p", "1234", *good_hars])
17
+ v.options[:port].should == 1234
18
+ end
14
19
  end
15
20
 
16
21
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: har
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ prerelease: false
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
8
  - 1
9
- - dev
10
- version: 0.0.1.dev
9
+ version: 0.0.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jari Bakken
@@ -255,13 +254,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
255
254
  required_rubygems_version: !ruby/object:Gem::Requirement
256
255
  none: false
257
256
  requirements:
258
- - - ">"
257
+ - - ">="
259
258
  - !ruby/object:Gem::Version
260
259
  segments:
261
- - 1
262
- - 3
263
- - 1
264
- version: 1.3.1
260
+ - 0
261
+ version: "0"
265
262
  requirements: []
266
263
 
267
264
  rubyforge_project: har