jazor 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -30,3 +30,7 @@ Jazor is a simple command line JSON parsing tool.
30
30
  ==== Testing the value of a JSON "slice"
31
31
 
32
32
  jazor 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=jazor' -t 'responseData.results.is_a?(Array)'
33
+
34
+ === Help
35
+
36
+ jazor --help
data/bin/jazor CHANGED
@@ -41,6 +41,21 @@ module Jazor
41
41
  opts.on('-X', '--request REQUEST', 'REST request method (default: %s)' % options[:rest_request]) do |opt|
42
42
  options[:rest_request] = opt
43
43
  end
44
+
45
+ opts.on_tail('-h', '--help', 'Show this message') do
46
+ puts opts.help
47
+ exit
48
+ end
49
+
50
+ opts.on_tail('--version', 'Show version') do
51
+ puts "%s %s\n%s <%s>\n%s" % [opts.program_name, opts.version, AUTHOR, AUTHOR_EMAIL, URL]
52
+ exit
53
+ end
54
+
55
+ if ARGV.length == 0 && STDIN.fcntl(Fcntl::F_GETFL, 0) != 0
56
+ puts opts.help
57
+ exit(1)
58
+ end
44
59
  end.parse!
45
60
 
46
61
  begin
data/lib/jazor.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  require 'json'
2
2
  require 'logger'
3
+ require 'net/http'
3
4
  require 'pp'
4
-
5
- require 'rest_client'
5
+ require 'uri'
6
6
 
7
7
 
8
8
  module Jazor
9
9
 
10
10
  NAME = 'jazor'
11
- VERSION_INFO = ['0', '0', '2']
11
+ VERSION_INFO = ['0', '0', '3']
12
12
  VERSION = VERSION_INFO.join('.')
13
13
  AUTHOR = 'Michael T. Conigliaro'
14
14
  AUTHOR_EMAIL = 'mike [at] conigliaro [dot] org'
@@ -41,6 +41,25 @@ module Jazor
41
41
 
42
42
  end
43
43
 
44
+ class RestClient
45
+
46
+ def self.method_missing(method, uri, headers={}, data={})
47
+ uri_parsed = URI.parse(uri)
48
+ http = Net::HTTP.new(uri_parsed.host, port=uri_parsed.port)
49
+ request_uri = uri_parsed.query ? uri_parsed.path + '?' + uri_parsed.query: uri_parsed.path
50
+ request = Net::HTTP.const_get(method.to_s.capitalize).new(request_uri)
51
+ headers.each { |k,v| request.add_field(k, v) }
52
+ request.set_form_data(data)
53
+
54
+ LOG.debug('%s %s: uri=%s headers=%s data=%s' % [self, method.to_s.upcase, File.join(uri_parsed.host, request_uri), headers.to_json, data.to_json])
55
+ response = http.request(request)
56
+ LOG.debug('%s result: code=%d body=%s' % [self, response.code, response.body.gsub("\r", ' ').gsub("\n", ' ')])
57
+
58
+ response
59
+ end
60
+
61
+ end
62
+
44
63
  end
45
64
 
46
65
  class Hash
@@ -14,7 +14,7 @@ class TestExecute < Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  def test_without_paramaters
17
- assert eval(`#{@jazor_bin}`).nil?
17
+ assert `#{@jazor_bin}` =~ /Usage:/
18
18
  end
19
19
 
20
20
  def test_json_from_stdin
@@ -0,0 +1,21 @@
1
+ require 'test/unit'
2
+
3
+ $:.push File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ require 'jazor'
5
+
6
+
7
+ class TestExecute < Test::Unit::TestCase
8
+
9
+ def test_get
10
+ response = Jazor::RestClient.get('http://ajax.googleapis.com/ajax/services/search/web')
11
+ assert response.code == '200'
12
+ assert response.body =~ /"responseStatus": 400/
13
+ end
14
+
15
+ def test_get_with_query_string
16
+ response = Jazor::RestClient.get('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=jazor')
17
+ assert response.code == '200'
18
+ assert response.body =~ /"responseStatus": 200/
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jazor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael T. Conigliaro
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-24 00:00:00 -07:00
18
+ date: 2011-01-25 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -47,10 +47,10 @@ files:
47
47
  - README.rdoc
48
48
  - bin/jazor
49
49
  - lib/jazor.rb
50
- - lib/rest_client.rb
51
50
  - test/test.json
52
51
  - test/test_jazor.rb
53
52
  - test/test_jazor_bin.rb
53
+ - test/test_rest_client.rb
54
54
  has_rdoc: true
55
55
  homepage: http://github.com/mconigliaro/jazor
56
56
  licenses: []
data/lib/rest_client.rb DELETED
@@ -1,24 +0,0 @@
1
- require 'net/http'
2
- require 'uri'
3
-
4
- module Jazor
5
-
6
- class RestClient
7
-
8
- def self.method_missing(method, uri, headers={}, data={})
9
- uri = URI.parse(uri)
10
- http = Net::HTTP.new(uri.host, port=uri.port)
11
- request = Net::HTTP.const_get(method.to_s.capitalize).new(uri.path)
12
- headers.each { |k,v| request.add_field(k, v) }
13
- request.set_form_data(data)
14
-
15
- LOG.debug('%s %s: url=%s headers=%s data=%s' % [self, method.to_s.upcase, File.join(uri.host, uri.path), headers.to_json, data.to_json])
16
- response = http.request(request)
17
- LOG.debug('%s result: code=%d body="%s"' % [self, response.code, response.body.gsub("\r", ' ').gsub("\n", ' ')])
18
-
19
- response
20
- end
21
-
22
- end
23
-
24
- end