json_checker 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YzEzODZhNmFiZjA0ZGJhY2IyZTA5YzI3ZTkyMDMwMGZkNjI2Yjg2NA==
5
- data.tar.gz: !binary |-
6
- OTZjNDRjYTNkYmE2YTg1MTFkY2ZmM2FhNDM2NDM0ODRmYmYyM2ZjOQ==
2
+ SHA1:
3
+ metadata.gz: 7039a495025f0d11a764d92a4e30a358a2858797
4
+ data.tar.gz: 68ba2a3b3574fb0be32090aba3bf3e893e260f3d
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MGZmZTFlOTFlZjUyMDlmNzFiYjBkZGYwYzE1MDhjZWRhMWU1MzBkNTM3ZDVj
10
- NzNlZGM1MWZjYzZjMzQyZmIwOTE4MDgxYzVhYzA3NWQyODQ2YzY4NTliM2I5
11
- OWU1NzdhY2Q2Zjc1NTM3N2U4NmM2ZmFjODRhNGI5YTNkOWIxMGQ=
12
- data.tar.gz: !binary |-
13
- NDdjYjliNzJmYmZmZTY5NTQ1YTE3ODhmY2QyNGY3MDViZjRhZGRjMDRjN2Vl
14
- N2JhNzRmZWM0YzU3MmUxYWM1MDFiMjA4ZDlkMmJkYTRjNDJlYzVkNWQzM2Fl
15
- MTRiZjQyZTdiOWNlYTQzNjczN2I2ZmMzMWZlMmVmMTU2ZjFmMTY=
6
+ metadata.gz: 0debc9c97f6b9b9c21cb04de3792cc7c406187effee5e091f287e875ae9ff8b8ae19d8c08ad54792ae6019335545cfd947ec7b44668513ba34c4a026d5457ae5
7
+ data.tar.gz: dc905f8d9816c28f093a7623082f80715dbfc95402bff6eba0cc0c8e649b4d0d0f59d0d4ef7a2ad28b081904bd1bdec72a5f025802f44cd3a221aae5a63aa3a9
data/.gitignore CHANGED
@@ -11,7 +11,6 @@
11
11
  /tmp/
12
12
  /Gemfile.lock
13
13
  /pkg/
14
- output.html
15
14
 
16
15
  # rspec failure tracking
17
16
  .rspec_status
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # JsonChecker
2
2
 
3
+ Compare and validate JSON files
4
+
3
5
  [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/hyperium/hyper/master/LICENSE)
4
6
  [![Build Status](https://travis-ci.org/ciceroduarte/json_checker.svg?branch=master)](https://travis-ci.org/ciceroduarte/json_checker)
5
7
  [![Coverage Status](https://coveralls.io/repos/github/ciceroduarte/json_checker/badge.svg?branch=master)](https://coveralls.io/github/ciceroduarte/json_checker?branch=master)
8
+ ![](http://ruby-gem-downloads-badge.herokuapp.com/json_checker?color=green&style=flat&type=total)
6
9
 
7
10
  ## Installation
8
11
 
@@ -20,10 +23,54 @@ Or install it yourself as:
20
23
 
21
24
  $ gem install json_checker
22
25
 
26
+ ## Configuration file
27
+
28
+ ```json
29
+ # json-config.json
30
+ {
31
+ "files": [
32
+ {
33
+ "name": "JSON example",
34
+ "remote-path": "http://private-8d36d-jsonchecker.apiary-mock.com/choices",
35
+ "keys" : {
36
+ "choice1": "Swift",
37
+ "choice2": "C",
38
+ "choice2": "Swift22",
39
+ "choice3": "Objective-C",
40
+ "choice6": "Java"
41
+ },
42
+ "compare-to": [
43
+ {
44
+ "remote-path": "http://private-8d36d-jsonchecker.apiary-mock.com/choices2",
45
+ "name": "Choices"
46
+ }
47
+ ]
48
+ }
49
+ ]
50
+ }
51
+ ```
52
+
53
+ ### Fields
54
+
55
+ * `files`: List of files to validation.
56
+ * `name`: Name of file to report.
57
+ * `path`: Local path to file.
58
+ * `remote-path`: Remote path to file.
59
+ * `keys`: Key/value to check.
60
+ * `compare-to`: List of files to compare
61
+
23
62
  ## Usage
24
63
 
25
- TODO: Write usage instructions here
64
+ Add `json-config.json` to your path and run `json_checker`
65
+ ```sh
66
+ $ json_checker
67
+ ```
68
+
69
+ ## HTML Output
70
+
71
+ Output example [output.html](http://htmlpreview.github.io/?https://github.com/ciceroduarte/json_checker/blob/master/output.html)
26
72
 
73
+ ![Screenshot0](https://raw.githubusercontent.com/ciceroduarte/json_checker/master/images/output.png)
27
74
  ## Development
28
75
 
29
76
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -37,4 +84,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/cicero
37
84
 
38
85
  ## License
39
86
 
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
87
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/images/output.png ADDED
Binary file
data/json-config.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
- "files": [
3
- {
4
- "name": "JSON Questions 2",
5
- "remote-path": "http://private-1e56c2-rubytest.apiary-mock.com/questions2",
6
- "keys" : {
7
- "choice": "Swift3",
8
- "choice1": "Swift22",
9
- "choice2": "Swift22",
10
- "choice3": "Swift3",
11
- "choiceTroll": "hue"
12
- },
13
- "compare-to": [
2
+ "files": [
3
+ {
4
+ "name": "JSON example",
5
+ "remote-path": "http://private-8d36d-jsonchecker.apiary-mock.com/choices",
6
+ "keys" : {
7
+ "choice1": "Swift",
8
+ "choice2": "C",
9
+ "choice2": "Swift22",
10
+ "choice3": "Objective-C",
11
+ "choice6": "Java"
12
+ },
13
+ "compare-to": [
14
14
  {
15
- "remote-path": "http://private-1e56c2-rubytest.apiary-mock.com/questions",
16
- "name": "Questions"
15
+ "remote-path": "http://private-8d36d-jsonchecker.apiary-mock.com/choices2",
16
+ "name": "Choices"
17
17
  }
18
- ]
19
- }
20
- ]
18
+ ]
19
+ }
20
+ ]
21
21
  }
@@ -29,7 +29,7 @@ module JsonChecker
29
29
  HTMLOutput.add_item(item)
30
30
  end
31
31
 
32
- def self.generate_output()
32
+ def self.generate_output(output_path)
33
33
  htmlOutput = HTMLOutput.new()
34
34
  output = "<html>" + htmlOutput.add_style() + "<body>"
35
35
  @reportItems.each do |item|
@@ -37,7 +37,7 @@ module JsonChecker
37
37
  end
38
38
  output << "</body></html>"
39
39
 
40
- htmlOutput.save_to_file(output)
40
+ htmlOutput.save_to_file(output, output_path)
41
41
  end
42
42
 
43
43
  def self.add_item(item)
@@ -48,7 +48,9 @@ module JsonChecker
48
48
  end
49
49
 
50
50
  def add_style()
51
- return "<style>
51
+ return "
52
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
53
+ <style>
52
54
  .addition { background: #eaffea; }
53
55
  .remotion { background: #ffecec; }
54
56
  .diff { outline: 1px solid #eff0d6; margin: 5px; padding-top: 5px; padding-bottom: 5px; }
@@ -63,11 +65,18 @@ module JsonChecker
63
65
  </style>"
64
66
  end
65
67
 
66
- def save_to_file(report)
68
+ def save_to_file(report, output_path)
69
+
70
+ path = "output.html"
71
+
72
+ unless output_path.nil?
73
+ path = output_path
74
+ end
75
+
67
76
  if report.nil?
68
77
  puts "[ERROR] Invalid report"
69
78
  else
70
- File.write("output.html", report)
79
+ File.write(path, report)
71
80
  end
72
81
  end
73
82
 
@@ -27,7 +27,7 @@ module JsonChecker
27
27
  temp_jsonToCompare = tempfile_from_json(jsonToCompare)
28
28
 
29
29
  unless temp_json.nil? && temp_jsonToCompare.nil?
30
- diff = Diffy::Diff.new(temp_json.path, temp_jsonToCompare.path, :source => 'files', :context => 3)
30
+ diff = Diffy::Diff.new(temp_jsonToCompare.path, temp_json.path, :source => 'files', :context => 3)
31
31
  html_report_from_diff(title, diff)
32
32
 
33
33
  temp_jsonToCompare.delete
@@ -30,7 +30,7 @@ module JsonChecker
30
30
  JSONComparator.compare(fileToCheck, fileToCheck.compareTo)
31
31
  end
32
32
  end
33
- HTMLOutput.generate_output()
33
+ HTMLOutput.generate_output(config['output-path'])
34
34
  end
35
35
 
36
36
  def validate_JSON_with_keys(title, jsonKeys, json)
@@ -1,3 +1,3 @@
1
1
  module JsonChecker
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/output.html ADDED
@@ -0,0 +1,96 @@
1
+ <html>
2
+ <style>
3
+ .addition {
4
+ background: #eaffea;
5
+ }
6
+ .remotion {
7
+ background: #ffecec;
8
+ }
9
+ .diff {
10
+ outline: 1px solid #eff0d6;
11
+ margin: 5px;
12
+ padding-top: 5px;
13
+ padding-bottom: 5px;
14
+ }
15
+ .validation {
16
+ margin: 5px;
17
+ }
18
+ body {
19
+ font-family: monospace;
20
+ }
21
+ table {
22
+ border-collapse: collapse;
23
+ width: 100%;
24
+ }
25
+ td {
26
+ border: 1px solid #eff0d6;
27
+ }
28
+ th {
29
+ background-color: #4CAF50;
30
+ color: white;
31
+ border: 1px solid #4CAF50;
32
+ }
33
+ th, td {
34
+ padding: 5px;
35
+ text-align: left;
36
+ }
37
+ tr:hover {
38
+ background-color: #f5f5f5
39
+ }
40
+ p {
41
+ margin-top: 0em;
42
+ margin-bottom: 0em;
43
+ white-space: pre;
44
+ padding : 3;
45
+ color: #3e3333
46
+ }
47
+ </style>
48
+ <body>
49
+ <h2>Validating JSON example values</h2>
50
+ <div class="validation" style="overflow-x:auto;">
51
+ <table>
52
+ <tr>
53
+ <th>Status</th>
54
+ <th>Key</th>
55
+ <th>Expected</th>
56
+ <th>Value</th>
57
+ </tr>
58
+ <tr>
59
+ <td>Success</td>
60
+ <td>choice1</td>
61
+ <td>Swift</td>
62
+ <td>Swift</td>
63
+ </tr>
64
+ <tr>
65
+ <td>Error</td>
66
+ <td>choice2</td>
67
+ <td>Swift22</td>
68
+ <td>Python</td>
69
+ </tr>
70
+ <tr>
71
+ <td>Success</td>
72
+ <td>choice3</td>
73
+ <td>Objective-C</td>
74
+ <td>Objective-C</td>
75
+ </tr>
76
+ <tr>
77
+ <td>Not found</td>
78
+ <td>choice6</td>
79
+ <td>Java</td>
80
+ <td></td>
81
+ </tr>
82
+ </table>
83
+ </div>
84
+ <h2>Comparing JSON example with Choices</h2>
85
+ <div class="diff">
86
+ <p class="null"> {</p>
87
+ <p class="null"> "choice1": "Swift",</p>
88
+ <p class="remotion">- "choice2": "Python",</p>
89
+ <p class="addition">+ "choice2": "C",</p>
90
+ <p class="null"> "choice3": "Objective-C",</p>
91
+ <p class="remotion">- "choice4": "Ruby"</p>
92
+ <p class="addition">+ "choice4": "Java"</p>
93
+ <p class="null"> }</p>
94
+ </div>
95
+ </body>
96
+ </html>
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cícero Duarte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-15 00:00:00.000000000 Z
11
+ date: 2017-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.14'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.14'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: coveralls
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
@@ -88,10 +88,10 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - .coveralls.yml
92
- - .gitignore
93
- - .rspec
94
- - .travis.yml
91
+ - ".coveralls.yml"
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
95
  - CODE_OF_CONDUCT.md
96
96
  - Gemfile
97
97
  - LICENSE.md
@@ -101,6 +101,7 @@ files:
101
101
  - bin/console
102
102
  - bin/json_checker
103
103
  - bin/setup
104
+ - images/output.png
104
105
  - json-config.json
105
106
  - json_checker.gemspec
106
107
  - lib/json_checker.rb
@@ -111,6 +112,7 @@ files:
111
112
  - lib/json_checker/json_to_check.rb
112
113
  - lib/json_checker/json_validator.rb
113
114
  - lib/json_checker/version.rb
115
+ - output.html
114
116
  homepage: https://github.com/ciceroduarte/json_checker
115
117
  licenses:
116
118
  - MIT
@@ -121,17 +123,17 @@ require_paths:
121
123
  - lib
122
124
  required_ruby_version: !ruby/object:Gem::Requirement
123
125
  requirements:
124
- - - ! '>='
126
+ - - ">="
125
127
  - !ruby/object:Gem::Version
126
128
  version: '0'
127
129
  required_rubygems_version: !ruby/object:Gem::Requirement
128
130
  requirements:
129
- - - ! '>='
131
+ - - ">="
130
132
  - !ruby/object:Gem::Version
131
133
  version: '0'
132
134
  requirements: []
133
135
  rubyforge_project:
134
- rubygems_version: 2.6.10
136
+ rubygems_version: 2.0.14.1
135
137
  signing_key:
136
138
  specification_version: 4
137
139
  summary: Validate fields and compare with others json files