har 0.0.8 → 0.0.9

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) 2011 Jari Bakken
1
+ Copyright (c) 2011-2012 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
@@ -4,8 +4,13 @@ HAR
4
4
  Ruby library to work with and view HTTP archives.
5
5
  This includes [harviewer][viewer], which can be launched through the "har" command.
6
6
 
7
+ Install
8
+ =======
9
+
10
+ gem install har
11
+
7
12
  Usage
8
- =============
13
+ =====
9
14
 
10
15
  HAR::Archive.from_string(json) #=> #<Har::Archive:0x5e7cac>
11
16
  HAR::Archive.from_file(path) #=> #<Har::Archive:0x5e7cac>
@@ -28,6 +33,6 @@ Note on Patches/Pull Requests
28
33
  Copyright
29
34
  =========
30
35
 
31
- Copyright (c) 2011 Jari Bakken. See LICENSE for details.
36
+ Copyright (c) 2011-2012 Jari Bakken. See LICENSE for details.
32
37
 
33
38
  [viewer]: http://code.google.com/p/harviewer/
@@ -15,12 +15,13 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = "har"
16
16
 
17
17
  s.add_dependency "json"
18
- s.add_dependency "json-schema", "= 0.1.12"
18
+ s.add_dependency "jschematic", ">= 0.1.0"
19
19
  s.add_dependency "launchy", ">= 0.3.7"
20
20
 
21
21
  s.add_development_dependency "rspec", "~> 2.0"
22
22
  s.add_development_dependency "simplecov"
23
23
  s.add_development_dependency "rake", "~> 0.9.2"
24
+ s.add_development_dependency "pry"
24
25
 
25
26
  s.files = `git ls-files`.split("\n")
26
27
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/lib/har.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'json'
2
- require 'json-schema'
2
+ require 'jschematic'
3
3
  require 'time'
4
4
 
5
5
  require 'har/error'
@@ -9,6 +9,8 @@ require 'har/schema_type'
9
9
  require 'har/page'
10
10
  require 'har/archive'
11
11
  require 'har/viewer'
12
+ require 'har/extensions/jschematic/attributes/format'
13
+
12
14
 
13
15
  module Enumerable
14
16
  def group_by
@@ -34,6 +34,23 @@ module HAR
34
34
  result
35
35
  end
36
36
 
37
+ # @api private
38
+ def self.schemas
39
+ @schemas ||= {}
40
+ end
41
+
42
+ # @api private
43
+ def self.add_schema(path)
44
+ data = JSON.parse(File.read(path))
45
+ id = data.fetch('id')
46
+
47
+ schemas[id] = data
48
+ end
49
+
50
+ Dir[File.expand_path("../schemas/*.json", __FILE__)].each do |path|
51
+ add_schema path
52
+ end
53
+
37
54
  attr_reader :uri
38
55
 
39
56
  def initialize(input, uri = nil)
@@ -81,26 +98,23 @@ module HAR
81
98
  end
82
99
 
83
100
  def valid?
84
- JSON::Validator.validate schema_file, @data
101
+ Jschematic.validate @data, log_type_schema, :debug => true, :context => self.class.schemas.values
85
102
  end
86
103
 
87
104
  def validate!
88
- JSON::Validator.validate2 schema_file, @data
89
- rescue JSON::ValidationError => ex
90
- # add archive uri to the message
91
- if @uri
92
- raise ValidationError, "#{@uri}: #{ex.message}"
93
- else
94
- raise ValidationError, ex.message
95
- end
96
- end
105
+ Jschematic.validate! @data, log_type_schema, :debug => true, :context => self.class.schemas.values
106
+ nil
107
+ rescue Jschematic::ValidationError => ex
108
+ msg = ex.message
109
+ msg = "#{@uri}: #{msg}" if @uri
97
110
 
98
- protected
111
+ raise ValidationError, msg
112
+ end
99
113
 
100
114
  private
101
115
 
102
- def schema_file
103
- @schema_file ||= File.expand_path("../schemas/logType", __FILE__)
116
+ def log_type_schema
117
+ @schema ||= self.class.schemas.fetch('logType')
104
118
  end
105
119
 
106
120
  def merge_data(left, right, uri)
@@ -160,4 +174,3 @@ module HAR
160
174
 
161
175
  end # Archive
162
176
  end # HAR
163
-
@@ -0,0 +1,21 @@
1
+ module Jschematic
2
+ module Attributes
3
+ module Format
4
+
5
+ # Looks like HAR files have slightly non-compliant dates,
6
+ # so we override DateTime#accepts? to also check for that
7
+ class DateTime
8
+ alias_method :accepts_orig?, :accepts?
9
+
10
+ def accepts?(date_time)
11
+ accepts_orig?(date_time) || accepts_har_date?(date_time)
12
+ end
13
+
14
+ def accepts_har_date?(date_time)
15
+ # taken from harSchema.js
16
+ date_time =~ /^(\d{4})(-)?(\d\d)(-)?(\d\d)(T)?(\d\d)(:)?(\d\d)(:)?(\d\d)(\.\d+)?(Z|([+-])(\d\d)(:)?(\d\d))/
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -2,7 +2,6 @@
2
2
  "id": "browserType",
3
3
  "description": "Name and version info of used browser.",
4
4
  "type": "object",
5
- "optional": true,
6
5
  "properties": {
7
6
  "name": {
8
7
  "type": "string",
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "id": "cacheEntryType",
3
- "optional": true,
4
3
  "description": "Info about cache entry.",
5
4
  "properties": {
6
5
  "expires": {
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "id": "entryType",
3
3
  "description": "Request and Response related info",
4
- "optional": true,
5
4
  "properties": {
6
5
  "pageref": {
7
6
  "type": "string"
@@ -14,7 +13,7 @@
14
13
  },
15
14
  "time": {
16
15
  "type": "integer",
17
- "min": 0,
16
+ "minimum": 0,
18
17
  "required": true
19
18
  },
20
19
  "request": {
@@ -4,11 +4,11 @@
4
4
  "properties": {
5
5
  "onContentLoad": {
6
6
  "type": "number",
7
- "min": -1
7
+ "minimum": -1
8
8
  },
9
9
  "onLoad": {
10
10
  "type": "number",
11
- "min": -1
11
+ "minimum": -1
12
12
  },
13
13
  "comment": {
14
14
  "type": "string"
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "id": "pageType",
3
3
  "description": "Exported web page",
4
- "optional": true,
5
4
  "properties": {
6
5
  "startedDateTime": {
7
6
  "type": "string",
@@ -11,7 +10,6 @@
11
10
  },
12
11
  "id": {
13
12
  "type": "string",
14
- "unique": true,
15
13
  "required": true
16
14
  },
17
15
  "title": {
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "id": "postDataType",
3
3
  "description": "Posted data info.",
4
- "optional": true,
5
4
  "properties": {
6
5
  "mimeType": {
7
6
  "type": "string",
@@ -4,37 +4,37 @@
4
4
  "properties": {
5
5
  "dns": {
6
6
  "type": "integer",
7
- "min": -1,
7
+ "minimum": -1,
8
8
  "required": true
9
9
  },
10
10
  "connect": {
11
11
  "type": "integer",
12
- "min": -1,
12
+ "minimum": -1,
13
13
  "required": true
14
14
  },
15
15
  "blocked": {
16
16
  "type": "integer",
17
- "min": -1,
17
+ "minimum": -1,
18
18
  "required": true
19
19
  },
20
20
  "send": {
21
21
  "type": "integer",
22
- "min": -1,
22
+ "minimum": -1,
23
23
  "required": true
24
24
  },
25
25
  "wait": {
26
26
  "type": "integer",
27
- "min": -1,
27
+ "minimum": -1,
28
28
  "required": true
29
29
  },
30
30
  "receive": {
31
31
  "type": "integer",
32
- "min": -1,
32
+ "minimum": -1,
33
33
  "required": true
34
34
  },
35
35
  "ssl": {
36
36
  "type": "integer",
37
- "min": -1
37
+ "minimum": -1
38
38
  },
39
39
  "comment": {
40
40
  "type": "string"
@@ -1,3 +1,3 @@
1
1
  module HAR
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -7,7 +7,8 @@ if ENV['COVERAGE']
7
7
  end
8
8
 
9
9
  $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
10
- require "har"
10
+ require 'har'
11
+ require 'pry'
11
12
 
12
13
  module HAR
13
14
  module SpecHelper
metadata CHANGED
@@ -1,123 +1,136 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: har
3
- version: !ruby/object:Gem::Version
4
- hash: 15
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 8
10
- version: 0.0.8
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Jari Bakken
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-10-10 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-08-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: json
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: json-schema
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: jschematic
32
+ requirement: !ruby/object:Gem::Requirement
38
33
  none: false
39
- requirements:
40
- - - "="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- - 1
46
- - 12
47
- version: 0.1.12
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.1.0
48
38
  type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: launchy
52
39
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
54
41
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 29
59
- segments:
60
- - 0
61
- - 3
62
- - 7
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: launchy
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
63
53
  version: 0.3.7
64
54
  type: :runtime
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
- name: rspec
68
55
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
70
57
  none: false
71
- requirements:
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.3.7
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
72
67
  - - ~>
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 2
77
- - 0
78
- version: "2.0"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.0'
79
70
  type: :development
80
- version_requirements: *id004
81
- - !ruby/object:Gem::Dependency
82
- name: simplecov
83
71
  prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
85
81
  none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- hash: 3
90
- segments:
91
- - 0
92
- version: "0"
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
93
86
  type: :development
94
- version_requirements: *id005
95
- - !ruby/object:Gem::Dependency
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
96
95
  name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.9.2
102
+ type: :development
97
103
  prerelease: false
98
- requirement: &id006 !ruby/object:Gem::Requirement
104
+ version_requirements: !ruby/object:Gem::Requirement
99
105
  none: false
100
- requirements:
106
+ requirements:
101
107
  - - ~>
102
- - !ruby/object:Gem::Version
103
- hash: 63
104
- segments:
105
- - 0
106
- - 9
107
- - 2
108
+ - !ruby/object:Gem::Version
108
109
  version: 0.9.2
110
+ - !ruby/object:Gem::Dependency
111
+ name: pry
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
109
118
  type: :development
110
- version_requirements: *id006
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
111
126
  description: Ruby library to work with HTTP archives
112
- email:
127
+ email:
113
128
  - jari.bakken@gmail.com
114
- executables:
129
+ executables:
115
130
  - har
116
131
  extensions: []
117
-
118
132
  extra_rdoc_files: []
119
-
120
- files:
133
+ files:
121
134
  - .gitignore
122
135
  - .rspec
123
136
  - .travis.yml
@@ -130,23 +143,24 @@ files:
130
143
  - lib/har.rb
131
144
  - lib/har/archive.rb
132
145
  - lib/har/error.rb
146
+ - lib/har/extensions/jschematic/attributes/format.rb
133
147
  - lib/har/page.rb
134
148
  - lib/har/schema_type.rb
135
- - lib/har/schemas/browserType
136
- - lib/har/schemas/cacheEntryType
137
- - lib/har/schemas/cacheType
138
- - lib/har/schemas/contentType
139
- - lib/har/schemas/cookieType
140
- - lib/har/schemas/creatorType
141
- - lib/har/schemas/entryType
142
- - lib/har/schemas/logType
143
- - lib/har/schemas/pageTimingsType
144
- - lib/har/schemas/pageType
145
- - lib/har/schemas/postDataType
146
- - lib/har/schemas/recordType
147
- - lib/har/schemas/requestType
148
- - lib/har/schemas/responseType
149
- - lib/har/schemas/timingsType
149
+ - lib/har/schemas/browserType.json
150
+ - lib/har/schemas/cacheEntryType.json
151
+ - lib/har/schemas/cacheType.json
152
+ - lib/har/schemas/contentType.json
153
+ - lib/har/schemas/cookieType.json
154
+ - lib/har/schemas/creatorType.json
155
+ - lib/har/schemas/entryType.json
156
+ - lib/har/schemas/logType.json
157
+ - lib/har/schemas/pageTimingsType.json
158
+ - lib/har/schemas/pageType.json
159
+ - lib/har/schemas/postDataType.json
160
+ - lib/har/schemas/recordType.json
161
+ - lib/har/schemas/requestType.json
162
+ - lib/har/schemas/responseType.json
163
+ - lib/har/schemas/timingsType.json
150
164
  - lib/har/serializable.rb
151
165
  - lib/har/version.rb
152
166
  - lib/har/viewer.rb
@@ -274,40 +288,31 @@ files:
274
288
  - spec/har/page_spec.rb
275
289
  - spec/har/viewer_spec.rb
276
290
  - spec/spec_helper.rb
277
- homepage: ""
291
+ homepage: ''
278
292
  licenses: []
279
-
280
293
  post_install_message:
281
294
  rdoc_options: []
282
-
283
- require_paths:
295
+ require_paths:
284
296
  - lib
285
- required_ruby_version: !ruby/object:Gem::Requirement
297
+ required_ruby_version: !ruby/object:Gem::Requirement
286
298
  none: false
287
- requirements:
288
- - - ">="
289
- - !ruby/object:Gem::Version
290
- hash: 3
291
- segments:
292
- - 0
293
- version: "0"
294
- required_rubygems_version: !ruby/object:Gem::Requirement
299
+ requirements:
300
+ - - ! '>='
301
+ - !ruby/object:Gem::Version
302
+ version: '0'
303
+ required_rubygems_version: !ruby/object:Gem::Requirement
295
304
  none: false
296
- requirements:
297
- - - ">="
298
- - !ruby/object:Gem::Version
299
- hash: 3
300
- segments:
301
- - 0
302
- version: "0"
305
+ requirements:
306
+ - - ! '>='
307
+ - !ruby/object:Gem::Version
308
+ version: '0'
303
309
  requirements: []
304
-
305
310
  rubyforge_project: har
306
- rubygems_version: 1.8.10
311
+ rubygems_version: 1.8.24
307
312
  signing_key:
308
313
  specification_version: 3
309
314
  summary: Ruby library to work with HTTP archives
310
- test_files:
315
+ test_files:
311
316
  - spec/fixtures/entry1.json
312
317
  - spec/fixtures/hars/bad.har
313
318
  - spec/fixtures/hars/browser-blocking-time.har
@@ -319,3 +324,4 @@ test_files:
319
324
  - spec/har/page_spec.rb
320
325
  - spec/har/viewer_spec.rb
321
326
  - spec/spec_helper.rb
327
+ has_rdoc: