jazor 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,11 @@
1
1
  = Change Log
2
2
 
3
+ == 0.1.3 (2011-12-13)
4
+
5
+ * Handle HTTPS URLs
6
+ * Use .rvmrc and Bundler in project
7
+ * Convert tests from Test::Unit to RSpec
8
+
3
9
  == 0.1.2 (2011-08-24)
4
10
 
5
11
  * Apply sort after evaluating expression
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2011 Michael T. Conigliaro
1
+ Copyright (C) 2011 Michael Paul Thomas Conigliaro
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of
4
4
  this software and associated documentation files (the "Software"), to deal in
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Jazor
2
2
 
3
- Jazor (JSON + razor) is a simple command line JSON parsing tool.
3
+ Jazor (JSON razor) is a simple command line JSON parsing tool.
4
4
 
5
5
  == Installation
6
6
 
@@ -54,18 +54,21 @@ scripts.
54
54
  $ jazor '{ "foo": "abc", "bar": [1, 2, 3] }' 'bar.inject { |memo,obj| memo + obj }'
55
55
  6
56
56
 
57
- $ jazor '[1, 2, 3, 4, 5]' 'select { |obj| obj.even? }'
57
+ $ jazor '[1, 2, 3, 4, 5]' 'select(&:even?)'
58
58
  [2, 4]
59
59
 
60
- $ jazor '[1, 2, 3, 4, 5]' 'select { |obj| obj.odd? }'
60
+ $ jazor '[1, 2, 3, 4, 5]' 'select(&:odd?)'
61
61
  [1, 3, 5]
62
62
 
63
- $ jazor '["a", "b", "c"]' self.count
64
- 3
63
+ $ jazor '["a", "b", "c", "d", "e"]' 'self[1..3]'
64
+ ["b", "c", "d"]
65
+
66
+ $ jazor '[1, 2, 3, 4, 5]' "'odds=%s; evens=%s' % [select(&:odd?).join(','), select(&:even?).join(',')]"
67
+ odds=1,3,5; evens=2,4
65
68
 
66
69
  == Authors
67
70
 
68
- * Michael T. Conigliaro <mike [at] conigliaro [dot] org>
71
+ * Michael Paul Thomas Conigliaro <mike [at] conigliaro [dot] org>
69
72
 
70
73
  == Contributers
71
74
 
data/Rakefile CHANGED
@@ -1,15 +1,15 @@
1
- task :default => [:test]
1
+ require 'rspec/core/rake_task'
2
2
 
3
- task :test do
4
- Dir[File.expand_path(File.join(File.dirname(__FILE__), 'test', 'test_*'))].each do |test|
5
- system "ruby -I #{File.expand_path(File.join(File.dirname(__FILE__), 'lib'))} #{test}"
6
- end
7
- end
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :default => :spec
8
6
 
7
+ desc 'Build the gem'
9
8
  task :build do
10
9
  system "gem build *.gemspec"
11
10
  end
12
11
 
12
+ desc 'Push the gem'
13
13
  task :push do
14
14
  system "gem push *.gem"
15
15
  end
data/bin/jazor CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'optparse'
4
3
  require 'fcntl'
4
+ require 'optparse'
5
5
 
6
6
  $:.push File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
7
7
  require 'jazor'
data/lib/jazor.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'logger'
2
2
  require 'net/http'
3
+ require 'net/https'
3
4
  require 'pp'
4
5
  require 'uri'
5
6
 
@@ -10,10 +11,10 @@ require 'json'
10
11
  module Jazor
11
12
 
12
13
  NAME = 'jazor'
13
- VERSION = '0.1.2'
14
- AUTHOR = 'Michael T. Conigliaro'
14
+ VERSION = '0.1.3'
15
+ AUTHOR = 'Michael Paul Thomas Conigliaro'
15
16
  AUTHOR_EMAIL = 'mike [at] conigliaro [dot] org'
16
- DESCRIPTION = 'Jazor (JSON + razor) is a simple command line JSON parsing tool.'
17
+ DESCRIPTION = 'Jazor (JSON razor) is a simple command line JSON parsing tool.'
17
18
  URL = 'http://github.com/mconigliaro/jazor'
18
19
 
19
20
  LOG = Logger.new(STDOUT)
@@ -38,6 +39,10 @@ module Jazor
38
39
  def self.method_missing(method, uri, headers={}, data={})
39
40
  uri_parsed = URI.parse(uri)
40
41
  http = Net::HTTP.new(uri_parsed.host, port=uri_parsed.port)
42
+ if uri_parsed.scheme == 'https'
43
+ http.use_ssl = true
44
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
45
+ end
41
46
  request_uri = uri_parsed.query ? "#{uri_parsed.path}?#{uri_parsed.query}" : uri_parsed.path
42
47
  request = Net::HTTP.const_get(method.to_s.capitalize).new(request_uri)
43
48
  headers.each { |k,v| request.add_field(k, v) }
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jazor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Michael T. Conigliaro
8
+ - Michael Paul Thomas Conigliaro
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-24 00:00:00.000000000Z
12
+ date: 2011-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &2152331680 !ruby/object:Gem::Requirement
16
+ requirement: &2151885000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,8 +21,8 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152331680
25
- description: Jazor (JSON + razor) is a simple command line JSON parsing tool.
24
+ version_requirements: *2151885000
25
+ description: Jazor (JSON razor) is a simple command line JSON parsing tool.
26
26
  email: mike [at] conigliaro [dot] org
27
27
  executables:
28
28
  - jazor
@@ -35,10 +35,6 @@ files:
35
35
  - README.rdoc
36
36
  - bin/jazor
37
37
  - lib/jazor.rb
38
- - test/test.json
39
- - test/test_jazor.rb
40
- - test/test_jazor_bin.rb
41
- - test/test_rest_client.rb
42
38
  homepage: http://github.com/mconigliaro/jazor
43
39
  licenses: []
44
40
  post_install_message:
@@ -59,8 +55,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
55
  version: '0'
60
56
  requirements: []
61
57
  rubyforge_project: jazor
62
- rubygems_version: 1.8.6
58
+ rubygems_version: 1.8.10
63
59
  signing_key:
64
60
  specification_version: 3
65
- summary: Jazor (JSON + razor) is a simple command line JSON parsing tool.
61
+ summary: Jazor (JSON razor) is a simple command line JSON parsing tool.
66
62
  test_files: []
data/test/test.json DELETED
@@ -1,32 +0,0 @@
1
- {
2
- "value0": "test",
3
- "value1": 123,
4
- "value2": 0.123,
5
- "array_of_values" : [1, 2, 3],
6
- "array_of_arrays" : [
7
- [1, 2, 3],
8
- [1, 2, 3],
9
- [1, 2, 3]
10
- ],
11
- "array_of_objects": [
12
- {"object0":1},
13
- {"object1":2},
14
- {"object2":3}
15
- ],
16
- "nested_object": {
17
- "value0": "test",
18
- "value1": 123,
19
- "value2": 0.123,
20
- "array_of_values" : [1, 2, 3],
21
- "array_of_arrays" : [
22
- [1, 2, 3],
23
- [1, 2, 3],
24
- [1, 2, 3]
25
- ],
26
- "array_of_objects": [
27
- {"object0":0},
28
- {"object1":1},
29
- {"object2":2}
30
- ]
31
- }
32
- }
data/test/test_jazor.rb DELETED
@@ -1,57 +0,0 @@
1
- require 'test/unit'
2
-
3
- class TestExecute < Test::Unit::TestCase
4
-
5
- def setup
6
- require 'jazor'
7
-
8
- @init_json = IO.read(File.expand_path(File.join(File.dirname(__FILE__), 'test.json')))
9
- @init_hash = JSON.parse(@init_json)
10
- end
11
-
12
- def test_root_object
13
- assert Jazor::parse(@init_json).is_a?(Hash)
14
- assert Jazor::parse(@init_json) == @init_hash
15
- end
16
-
17
- def test_values
18
- assert Jazor::parse(@init_json).value0.is_a?(String)
19
- assert Jazor::parse(@init_json).value1.is_a?(Integer)
20
- assert Jazor::parse(@init_json).value2.is_a?(Float)
21
- (0..2).each do |i|
22
- assert Jazor::parse(@init_json).send("value#{i}") == @init_hash["value#{i}"]
23
- end
24
- end
25
-
26
- def test_array_of_values
27
- assert Jazor::parse(@init_json).array_of_values.is_a?(Array)
28
- assert Jazor::parse(@init_json).array_of_values == @init_hash['array_of_values']
29
- (0...Jazor::parse(@init_json).array_of_values.length).each do |i|
30
- assert Jazor::parse(@init_json).array_of_values[i].is_a?(Integer)
31
- assert Jazor::parse(@init_json).array_of_values[i] == @init_hash["array_of_values"][i]
32
- end
33
- end
34
-
35
- def test_array_of_arrays
36
- assert Jazor::parse(@init_json).array_of_arrays.is_a?(Array)
37
- (0...Jazor::parse(@init_json).array_of_arrays.length).each do |i|
38
- assert Jazor::parse(@init_json).array_of_arrays[i].is_a?(Array)
39
- assert Jazor::parse(@init_json).array_of_arrays[i] == @init_hash['array_of_arrays'][i]
40
- (0...Jazor::parse(@init_json).array_of_arrays[i].length).each do |j|
41
- assert Jazor::parse(@init_json).array_of_arrays[i][j].is_a?(Integer)
42
- assert Jazor::parse(@init_json).array_of_arrays[i][j] == @init_hash['array_of_arrays'][i][j]
43
- end
44
- end
45
- end
46
-
47
- def test_array_of_objects
48
- assert Jazor::parse(@init_json).array_of_objects.is_a?(Array)
49
- (0...Jazor::parse(@init_json).array_of_objects.length).each do |i|
50
- assert Jazor::parse(@init_json).array_of_objects[i].is_a?(Hash)
51
- assert Jazor::parse(@init_json).array_of_objects[i] == @init_hash['array_of_objects'][i]
52
- assert Jazor::parse(@init_json).array_of_objects[i].send("object#{i}").is_a?(Integer)
53
- assert Jazor::parse(@init_json).array_of_objects[i].send("object#{i}") == @init_hash['array_of_objects'][i]["object#{i}"]
54
- end
55
- end
56
-
57
- end
@@ -1,59 +0,0 @@
1
- require 'test/unit'
2
-
3
- class TestExecute < Test::Unit::TestCase
4
-
5
- def setup
6
- require 'jazor'
7
-
8
- @init_url = 'http://github.com/api/v2/json/commits/list/mconigliaro/jazor/master'
9
- @init_file = File.expand_path(File.join(File.dirname(__FILE__), 'test.json'))
10
- @init_string = IO.read(@init_file)
11
- @jazor_bin = File.expand_path(File.join(File.dirname(__FILE__), '..', 'bin', 'jazor'))
12
- end
13
-
14
- def test_without_paramaters
15
- assert `#{@jazor_bin}` =~ /Usage:/
16
- end
17
-
18
- def test_json_from_stdin
19
- assert JSON.parse(`cat #{@init_file} | #{@jazor_bin}`).is_a?(Hash)
20
- end
21
-
22
- def test_json_from_url
23
- assert JSON.parse(`#{@jazor_bin} '#{@init_url}'`).is_a?(Hash)
24
- end
25
-
26
- def test_json_from_file
27
- assert JSON.parse(`#{@jazor_bin} #{@init_file}`).is_a?(Hash)
28
- end
29
-
30
- def test_json_from_argv
31
- assert JSON.parse(`#{@jazor_bin} '#{@init_string}'`).is_a?(Hash)
32
- end
33
-
34
- def test_json_from_file_with_expression
35
- assert eval(`#{@jazor_bin} #{@init_file} value1`).is_a?(Integer)
36
- assert JSON.parse(`#{@jazor_bin} #{@init_file} nested_object`).is_a?(Hash)
37
- assert JSON.parse(`#{@jazor_bin} #{@init_file} nested_object.array_of_values`).is_a?(Array)
38
- assert eval(`#{@jazor_bin} #{@init_file} dontexist`).nil?
39
- end
40
-
41
- def test_json_from_file_with_tests
42
- assert `#{@jazor_bin} -t #{@init_file} 'value1==123'` =~ /passed/
43
- assert `#{@jazor_bin} -t #{@init_file} 'value1==1234'` =~ /failed/
44
- end
45
-
46
- def test_sorting
47
- if Jazor::HAS_ORDERED_HASH
48
- {
49
- '[3, 2, 1]' => [1, 2, 3],
50
- '["foo", "bar", 1]' => [1, 'bar', 'foo'],
51
- '{"foo":1, "bar":2}' => {'bar' => 2, 'foo' => 1},
52
- '{"1":1, "bar":2}' => {'1' => 1, 'bar' => 2}
53
- }.each do |k,v|
54
- assert JSON.parse(`#{@jazor_bin} -s '#{k}'`) == v
55
- end
56
- end
57
- end
58
-
59
- end
@@ -1,19 +0,0 @@
1
- require 'test/unit'
2
-
3
- class TestExecute < Test::Unit::TestCase
4
-
5
- def test_get
6
- require 'jazor'
7
-
8
- response = Jazor::RestClient.get('http://ajax.googleapis.com/ajax/services/search/web')
9
- assert response.code == '200'
10
- assert response.body =~ /"responseStatus": 400/
11
- end
12
-
13
- def test_get_with_query_string
14
- response = Jazor::RestClient.get('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=jazor')
15
- assert response.code == '200'
16
- assert response.body =~ /"responseStatus": 200/
17
- end
18
-
19
- end