kronk 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,14 @@
1
+ === 1.2.2 / 2011-02-19
2
+
3
+ * Enhancements:
4
+
5
+ * Added support for default host to avoid having to write out
6
+ the most commonly used host name (e.g. http://localhost:3000)
7
+
8
+ * Added support for bash completion of URIs.
9
+
10
+ * Explicitely passing the http protocol is now optional.
11
+
1
12
  === 1.2.1 / 2011-01-21
2
13
 
3
14
  * Enhancements:
@@ -11,6 +11,7 @@ lib/kronk/plist_parser.rb
11
11
  lib/kronk/request.rb
12
12
  lib/kronk/response.rb
13
13
  lib/kronk/xml_parser.rb
14
+ script/kronk_completion
14
15
  test/mocks/200_response.json
15
16
  test/mocks/200_response.plist
16
17
  test/mocks/200_response.txt
@@ -27,6 +27,8 @@ Kronk was made possible by the sponsoring of AT&T Interactive.
27
27
 
28
28
  * Easy-to-read output (color or ascii, line numbers, etc).
29
29
 
30
+ * Yes, it works on Windows.
31
+
30
32
  == FUTURE:
31
33
 
32
34
  * Auto-queryer with optional param randomizing.
@@ -37,35 +39,37 @@ Kronk was made possible by the sponsoring of AT&T Interactive.
37
39
 
38
40
  Check if your json response returns the same data as your xml variety:
39
41
 
40
- $ kronk http://host.com/path.json http://host.com/path.xml
42
+ $ kronk host.com/path.json host.com/path.xml
41
43
 
42
44
  Compare body structure only (uses datatypes instead of values):
43
45
 
44
- $ kronk http://host.com/path.json http://host.com/path.xml --struct
46
+ $ kronk host.com/path.json host.com/path.xml --struct
45
47
 
46
48
  Call comparison with similar uri suffixes:
47
49
 
48
- $ kronk http://host.com/path.json http://host.com/path.xml --suff '?page=1'
50
+ $ kronk host.com/path.json host.com/path.xml --suff '?page=1'
49
51
 
50
- Compare response with the previous call:
52
+ Compare response over ssl with the previous call:
51
53
 
52
- $ kronk http://host.com/path --prev
54
+ $ kronk https://host.com/path --prev
53
55
 
54
56
  Compare response with a local file:
55
57
 
56
- $ kronk http://host.com/path.json ./saved_response.json
58
+ $ kronk host.com/path.json ./saved_response.json
57
59
 
58
60
  Do a simple text diff on the http response, including headers:
59
61
 
60
- $ kronk http://host.com/A/path.json http://host.com/B/path.json --raw -i
62
+ $ kronk host.com/A/path.json host.com/B/path.json --raw -i
61
63
 
62
64
  Run it to display formatted data:
63
65
 
64
- $ kronk http://host.com/path.json
66
+ $ kronk host.com/path.json
65
67
 
66
- Run it to display raw data with headers:
68
+ Run it to display raw data with headers from the default host (localhost:3000).
69
+ Default host is assumed when the path starts with "/" and no local files match
70
+ the given path:
67
71
 
68
- $ kronk http://host.com/path.json --raw -i
72
+ $ kronk /path.json --raw -i
69
73
 
70
74
  Parse the data and run an IRB console with the response:
71
75
 
@@ -135,6 +139,17 @@ Show line numbers in the output:
135
139
 
136
140
  :show_lines: true
137
141
 
142
+ Assign a default host to use when none is specified:
143
+
144
+ :default_host: http://localhost:3000
145
+
146
+ === Bash Completion:
147
+
148
+ Bash completion is available by sourcing the file returned by:
149
+
150
+ $ kronk --completion
151
+ [gem path]/script/kronk_completion
152
+
138
153
  == DATA TRAVERSING:
139
154
 
140
155
  One of Kronk's most powerful features is its ability to segregate data.
@@ -225,6 +240,10 @@ single quotes around some of your paths.
225
240
 
226
241
  * json gem
227
242
 
243
+ * rack gem
244
+
245
+ * cookiejar gem
246
+
228
247
  == INSTALL:
229
248
 
230
249
  $ sudo gem install kronk
@@ -242,7 +261,7 @@ and generate the RDoc.
242
261
 
243
262
  (The MIT License)
244
263
 
245
- Copyright (c) 2010 Jeremie Castagna
264
+ Copyright (c) 2010, 2011 Jeremie Castagna
246
265
 
247
266
  Permission is hereby granted, free of charge, to any person obtaining
248
267
  a copy of this software and associated documentation files (the
@@ -11,7 +11,7 @@ require 'yaml'
11
11
  class Kronk
12
12
 
13
13
  # This gem's version.
14
- VERSION = '1.2.1'
14
+ VERSION = '1.2.2'
15
15
 
16
16
 
17
17
  ##
@@ -42,6 +42,10 @@ class Kronk
42
42
  DEFAULT_COOKIES_FILE = File.expand_path "~/.kronk_cookies"
43
43
 
44
44
 
45
+ # Default file with history of unique URIs. (Used for autocomplete)
46
+ DEFAULT_HISTORY_FILE = File.expand_path "~/.kronk_history"
47
+
48
+
45
49
  # Default Content-Type header to parser mapping.
46
50
  DEFAULT_CONTENT_TYPES = {
47
51
  'js' => 'JSON',
@@ -81,10 +85,12 @@ class Kronk
81
85
  # Default config to use.
82
86
  DEFAULT_CONFIG = {
83
87
  :content_types => DEFAULT_CONTENT_TYPES.dup,
88
+ :default_host => "http://localhost:3000",
84
89
  :diff_format => :ascii_diff,
85
90
  :show_lines => false,
86
91
  :cache_file => DEFAULT_CACHE_FILE,
87
92
  :cookies_file => DEFAULT_COOKIES_FILE,
93
+ :history_file => DEFAULT_HISTORY_FILE,
88
94
  :use_cookies => true,
89
95
  :requires => [],
90
96
  :uri_options => {},
@@ -290,6 +296,20 @@ class Kronk
290
296
  end
291
297
 
292
298
 
299
+ ##
300
+ # Writes the given URIs to the history file.
301
+
302
+ def self.save_history *uris
303
+ path = self.config[:history_file]
304
+
305
+ uris.concat File.readlines(path).map{|line| line.strip} if File.file?(path)
306
+
307
+ File.open path, "w" do |file|
308
+ file.write uris.uniq.join($/)
309
+ end
310
+ end
311
+
312
+
293
313
  ##
294
314
  # Make requests, parse the responses and compare the data.
295
315
  # Query arguments may be set to the special value :cache to use the
@@ -410,12 +430,15 @@ class Kronk
410
430
  $stdout << "Found #{diff.count} diff(s).\n"
411
431
  end
412
432
 
433
+ save_history uri1, uri2
413
434
  exit 1 if diff.count > 0
414
435
 
415
436
  else
416
437
  out = retrieve_data_string uri1, options
417
438
  out = Diff.insert_line_nums out if config[:show_lines]
418
439
  puts out
440
+
441
+ save_history uri1
419
442
  end
420
443
 
421
444
  rescue Request::NotFoundError, Response::MissingParser => e
@@ -452,7 +475,10 @@ class Kronk
452
475
  opt.release = nil
453
476
 
454
477
  opt.banner = <<-STR
455
- Kronk runs diffs against data from live and cached http responses.
478
+
479
+ #{opt.program_name} #{opt.version}
480
+
481
+ Parse and run diffs against data from live and cached http responses.
456
482
 
457
483
  Usage:
458
484
  #{opt.program_name} --help
@@ -483,6 +509,13 @@ Kronk runs diffs against data from live and cached http responses.
483
509
  end
484
510
 
485
511
 
512
+ opt.on('--completion', 'Print bash completion file path and exit') do
513
+ file = File.join(File.dirname(__FILE__), "../script/kronk_completion")
514
+ puts File.expand_path(file)
515
+ exit 2
516
+ end
517
+
518
+
486
519
  opt.on('--config STR', String,
487
520
  'Load the given Kronk config file') do |value|
488
521
  load_config value
@@ -101,11 +101,6 @@ class Kronk
101
101
  when Hash
102
102
  output = "{\n"
103
103
 
104
- key_width = 0
105
- data.keys.each do |k|
106
- key_width = k.inspect.length if k.inspect.length > key_width
107
- end
108
-
109
104
  data_values =
110
105
  data.map do |key, value|
111
106
  pad = " " * indent
@@ -51,7 +51,7 @@ class Kronk
51
51
  resp =
52
52
  if IO === query || StringIO === query
53
53
  retrieve_io query, options
54
- elsif local?(query)
54
+ elsif query == :cache || File.file?(query)
55
55
  retrieve_file query, options
56
56
  else
57
57
  retrieve_uri query, options
@@ -71,14 +71,6 @@ class Kronk
71
71
  end
72
72
 
73
73
 
74
- ##
75
- # Check if a URI should be treated as a local file.
76
-
77
- def self.local? uri
78
- !(uri =~ %r{^\w+://})
79
- end
80
-
81
-
82
74
  ##
83
75
  # Read http response from a file and return a HTTPResponse instance.
84
76
 
@@ -178,15 +170,7 @@ class Kronk
178
170
  # :proxy:: Hash/String - http proxy to use; defaults to nil
179
171
 
180
172
  def self.call http_method, uri, options={}
181
- suffix = options.delete :uri_suffix
182
-
183
- uri = "#{uri}#{suffix}" if suffix
184
- uri = URI.parse uri unless URI === uri
185
-
186
- if options[:query]
187
- query = build_query options[:query]
188
- uri.query = [uri.query, query].compact.join "&"
189
- end
173
+ uri = build_uri uri, options
190
174
 
191
175
  data = options[:data]
192
176
  data &&= build_query data
@@ -240,6 +224,27 @@ class Kronk
240
224
  end
241
225
 
242
226
 
227
+ ##
228
+ # Build the URI to use for the request from the given uri or
229
+ # path and options.
230
+
231
+ def self.build_uri uri, options={}
232
+ suffix = options.delete :uri_suffix
233
+
234
+ uri = "http://#{uri}" unless uri =~ %r{^(\w+://|/)}
235
+ uri = "#{uri}#{suffix}" if suffix
236
+ uri = URI.parse uri unless URI === uri
237
+ uri = URI.parse(Kronk.config[:default_host]) + uri unless uri.host
238
+
239
+ if options[:query]
240
+ query = build_query options[:query]
241
+ uri.query = [uri.query, query].compact.join "&"
242
+ end
243
+
244
+ uri
245
+ end
246
+
247
+
243
248
  ##
244
249
  # Checks if cookies should be used and set.
245
250
 
@@ -0,0 +1,22 @@
1
+ #!/bin/bash
2
+
3
+ _kronk()
4
+ {
5
+ local cur prev opts kronk_keys
6
+ COMPREPLY=()
7
+ cur="${COMP_WORDS[COMP_CWORD]}"
8
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
9
+
10
+ kronk_keys="$HOME/.kronk_history"
11
+
12
+
13
+ if [ -f "$kronk_keys" ]; then
14
+ opts=$(cat $kronk_keys)
15
+ COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
16
+ return 0
17
+ fi
18
+
19
+ return 1
20
+ }
21
+
22
+ complete -d -X '.[^./]*' -F _kronk kronk
@@ -12,6 +12,8 @@ class TestKronk < Test::Unit::TestCase
12
12
  },
13
13
  :cache_file => Kronk::DEFAULT_CACHE_FILE,
14
14
  :cookies_file => Kronk::DEFAULT_COOKIES_FILE,
15
+ :history_file => Kronk::DEFAULT_HISTORY_FILE,
16
+ :default_host => "http://localhost:3000",
15
17
  :diff_format => :ascii_diff,
16
18
  :show_lines => false,
17
19
  :use_cookies => true,
@@ -33,6 +35,7 @@ class TestKronk < Test::Unit::TestCase
33
35
  :ignore_headers => ["Content-Type"],
34
36
  :cache_file => Kronk::DEFAULT_CACHE_FILE,
35
37
  :cookies_file => Kronk::DEFAULT_COOKIES_FILE,
38
+ :history_file => Kronk::DEFAULT_HISTORY_FILE,
36
39
  :show_lines => false,
37
40
  :use_cookies => true,
38
41
  :requires => [],
@@ -54,9 +57,11 @@ class TestKronk < Test::Unit::TestCase
54
57
  'plist' => "PlistParser",
55
58
  'xml' => "XMLParser"
56
59
  },
60
+ :default_host => "http://localhost:3000",
57
61
  :diff_format => :ascii_diff,
58
62
  :cache_file => Kronk::DEFAULT_CACHE_FILE,
59
63
  :cookies_file => Kronk::DEFAULT_COOKIES_FILE,
64
+ :history_file => Kronk::DEFAULT_HISTORY_FILE,
60
65
  :requires => [],
61
66
  :show_lines => false,
62
67
  :use_cookies => true,
@@ -68,6 +68,7 @@ class TestRequest < Test::Unit::TestCase
68
68
  def test_retrieve_cached
69
69
  query = "path/to/file.txt"
70
70
  options = {:foo => "bar"}
71
+ File.expects(:file?).with(query).returns true
71
72
  Kronk::Request.expects(:retrieve_file).with query, options
72
73
 
73
74
  Kronk::Request.retrieve query, options
@@ -1,4 +1,5 @@
1
1
  require 'test/test_helper'
2
+ require "nokogiri"
2
3
 
3
4
  class TestXmlParser < Test::Unit::TestCase
4
5
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kronk
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 27
5
+ prerelease:
5
6
  segments:
6
7
  - 1
7
8
  - 2
8
- - 1
9
- version: 1.2.1
9
+ - 2
10
+ version: 1.2.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Jeremie Castagna
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-01-21 00:00:00 -08:00
18
+ date: 2011-02-21 00:00:00 -08:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ~>
27
28
  - !ruby/object:Gem::Version
29
+ hash: 3
28
30
  segments:
29
31
  - 3
30
32
  - 1
@@ -40,6 +42,7 @@ dependencies:
40
42
  requirements:
41
43
  - - ~>
42
44
  - !ruby/object:Gem::Version
45
+ hash: 11
43
46
  segments:
44
47
  - 1
45
48
  - 2
@@ -54,6 +57,7 @@ dependencies:
54
57
  requirements:
55
58
  - - ~>
56
59
  - !ruby/object:Gem::Version
60
+ hash: 9
57
61
  segments:
58
62
  - 1
59
63
  - 3
@@ -68,6 +72,7 @@ dependencies:
68
72
  requirements:
69
73
  - - ~>
70
74
  - !ruby/object:Gem::Version
75
+ hash: 1
71
76
  segments:
72
77
  - 0
73
78
  - 5
@@ -82,6 +87,7 @@ dependencies:
82
87
  requirements:
83
88
  - - ">="
84
89
  - !ruby/object:Gem::Version
90
+ hash: 15
85
91
  segments:
86
92
  - 2
87
93
  - 0
@@ -97,6 +103,7 @@ dependencies:
97
103
  requirements:
98
104
  - - ~>
99
105
  - !ruby/object:Gem::Version
106
+ hash: 19
100
107
  segments:
101
108
  - 0
102
109
  - 3
@@ -112,57 +119,45 @@ dependencies:
112
119
  requirements:
113
120
  - - ~>
114
121
  - !ruby/object:Gem::Version
122
+ hash: 15
115
123
  segments:
116
124
  - 1
117
125
  - 0
118
126
  version: "1.0"
119
127
  type: :runtime
120
128
  version_requirements: *id007
121
- - !ruby/object:Gem::Dependency
122
- name: rubyforge
123
- prerelease: false
124
- requirement: &id008 !ruby/object:Gem::Requirement
125
- none: false
126
- requirements:
127
- - - ">="
128
- - !ruby/object:Gem::Version
129
- segments:
130
- - 2
131
- - 0
132
- - 4
133
- version: 2.0.4
134
- type: :development
135
- version_requirements: *id008
136
129
  - !ruby/object:Gem::Dependency
137
130
  name: mocha
138
131
  prerelease: false
139
- requirement: &id009 !ruby/object:Gem::Requirement
132
+ requirement: &id008 !ruby/object:Gem::Requirement
140
133
  none: false
141
134
  requirements:
142
135
  - - ~>
143
136
  - !ruby/object:Gem::Version
137
+ hash: 47
144
138
  segments:
145
139
  - 0
146
140
  - 9
147
141
  - 10
148
142
  version: 0.9.10
149
143
  type: :development
150
- version_requirements: *id009
144
+ version_requirements: *id008
151
145
  - !ruby/object:Gem::Dependency
152
146
  name: hoe
153
147
  prerelease: false
154
- requirement: &id010 !ruby/object:Gem::Requirement
148
+ requirement: &id009 !ruby/object:Gem::Requirement
155
149
  none: false
156
150
  requirements:
157
151
  - - ">="
158
152
  - !ruby/object:Gem::Version
153
+ hash: 47
159
154
  segments:
160
155
  - 2
161
- - 6
162
- - 2
163
- version: 2.6.2
156
+ - 8
157
+ - 0
158
+ version: 2.8.0
164
159
  type: :development
165
- version_requirements: *id010
160
+ version_requirements: *id009
166
161
  description: |-
167
162
  Kronk runs diffs against data from live and cached http responses.
168
163
  Kronk was made possible by the sponsoring of AT&T Interactive.
@@ -190,6 +185,7 @@ files:
190
185
  - lib/kronk/request.rb
191
186
  - lib/kronk/response.rb
192
187
  - lib/kronk/xml_parser.rb
188
+ - script/kronk_completion
193
189
  - test/mocks/200_response.json
194
190
  - test/mocks/200_response.plist
195
191
  - test/mocks/200_response.txt
@@ -218,7 +214,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
214
  requirements:
219
215
  - - ">="
220
216
  - !ruby/object:Gem::Version
221
- hash: -195272185281626433
217
+ hash: 3
222
218
  segments:
223
219
  - 0
224
220
  version: "0"
@@ -227,13 +223,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
223
  requirements:
228
224
  - - ">="
229
225
  - !ruby/object:Gem::Version
226
+ hash: 3
230
227
  segments:
231
228
  - 0
232
229
  version: "0"
233
230
  requirements: []
234
231
 
235
232
  rubyforge_project: kronk
236
- rubygems_version: 1.3.7
233
+ rubygems_version: 1.5.2
237
234
  signing_key:
238
235
  specification_version: 3
239
236
  summary: Kronk runs diffs against data from live and cached http responses