soaspec 0.2.17 → 0.2.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2f7c6eb1593879711796c37e0d54efbc7f9ea13
4
- data.tar.gz: 3f96430569dfd2ced08ed09534b6432062f3167c
3
+ metadata.gz: e82cd7590344ebe9d4a034ca2d81600f2cb88d86
4
+ data.tar.gz: 1bf2cedb30604a07b916afea81895ce8ff52a1b4
5
5
  SHA512:
6
- metadata.gz: fd585f6ea3eeacec2a99dbd1cb18e43d96f4365acaa7cc5e53afd5cd6ee5d98662fb283c7b3d0b50a1cc5f8e623275ccc452afe2fadf9e957ecfe35bf5969c24
7
- data.tar.gz: 28865b3bca9a6df7c5bf7dbb7f810b0c86ba4ddcbfa822011bf41f1b745700c6aa9f0f3998ddb8ceb00f5a03d9df24dd691a204018fd8c65b12e9686a33d1452
6
+ metadata.gz: 3f174f525a227249b2ca53d3567170f865230e7bdca4db70a0f1e94f7f9b03adde27200046ed08d1ebe63eb6d45850f4c74fbf345c61054f58d6e32f2b861791
7
+ data.tar.gz: 3f5580e744a260781dedb2907d8b99b97b0a152cb6abacefe2a0f2d6d98ec4e4f3297b80b5aa89f62b367e0f4d70b369bc121f4c26cc7f60bebbbb049b198e2f
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ Version 0.2.18
2
+ * Enhancement
3
+ * Hash of body returned via 'to_hash' can be accessed through Symbol or String
4
+
1
5
  Version 0.2.17
2
6
  * Bug Fix
3
7
  * Correct Output where does not show the conversion happening by JSONPath and PascalCase conversion
data/README.md CHANGED
@@ -207,6 +207,10 @@ Soaspec::SpecLogger.output_to_terminal = true
207
207
  Soaspec::SpecLogger.terminal_color = :magenta
208
208
  ```
209
209
 
210
+ ## Learning more
211
+
212
+ Looking at the website [here](https://samuel-garratt.gitlab.io/soaspec/)
213
+
210
214
  ## Development
211
215
 
212
216
  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.
data/demo/index.html CHANGED
@@ -6,7 +6,8 @@
6
6
  <body>
7
7
  <h1>Soaspec</h1>
8
8
  <h2>Samples demonstrating how Soaspec works</h2>
9
- <a href="extract.html">Extract response from exchange</a>
9
+ <a href="json_extract.html">Extract out of JSON response from exchange</a>
10
+ <a href="xml_extract.html">Extract out of XML response from exchange</a>
10
11
  <h2>Code coverage</h2>
11
12
  <a href="coverage/index.html">RSpec test code coverage</a>
12
13
  </body>
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title>Exchange extractors</title>
4
+ <title>JSON Exchange extractors</title>
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
6
  <script src="js/angular.min.js"></script>
7
7
  <style>
@@ -12,7 +12,7 @@
12
12
  </head>
13
13
  <body>
14
14
 
15
- <h1>Extract value from JSON response</h1>
15
+ <h1>Extract value(s) from JSON response body</h1>
16
16
 
17
17
  <div ng-app="codeDemo" ng-controller="extract">
18
18
  <h2>Sample JSON response body</h2>
@@ -35,7 +35,7 @@
35
35
  <script>
36
36
  var app = angular.module('codeDemo', []);
37
37
  app.controller('extract', function($scope, $http) {
38
- $http.get("extract.json").then(function(response) {
38
+ $http.get("json_extract.json").then(function(response) {
39
39
  $scope.myData = response.data.methods;
40
40
  $scope.sampleData = response.data.sampleData;
41
41
  });
@@ -5,7 +5,7 @@
5
5
  {
6
6
  "desc": "Get response object",
7
7
  "method": "@exchange.response",
8
- "result": "# RestClient::Response or Savon::Response object"
8
+ "result": "# RestClient::Response"
9
9
  },
10
10
  {
11
11
  "desc": "Value from unique element",
@@ -27,14 +27,14 @@
27
27
  },
28
28
  {
29
29
  "desc": "List of values matching JSONPath",
30
- "method": "@exchange.values_at_path('$..child2')",
30
+ "method": "@exchange.values_from_path('$..child2')",
31
31
  "result": "['parent1 word', 'word2'] # Array",
32
32
  "highlight": "\"child2\""
33
33
  },
34
34
  {
35
35
  "desc": "Convert response into hash",
36
36
  "method": "@exchange.to_hash",
37
- "result": "{:root=>{:parent1=>{:child1=>5, :child2=>\"parent1 word\"}, :parent2=>{:uniq=>\"val\", :child2=>\"word2\"}}} # Hash"
37
+ "result": "{\"root\"=>{\"parent1\"=>{\"child1\"=>\"5\", \"child2\"=>\"parent1 word\"}, \"parent2\"=>{\"uniq\"=>\"val\", \"child2\"=>\"word2\"}}} # Hash accessable through symbol or string"
38
38
  }
39
39
  ]
40
40
  }
@@ -0,0 +1,53 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>XML Exchange extractors</title>
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <script src="js/angular.min.js"></script>
7
+ <style>
8
+ .highlighted {
9
+ background: yellow;
10
+ }
11
+ </style>
12
+ </head>
13
+ <body>
14
+
15
+ <h1>Extract value(s) from XML response body</h1>
16
+
17
+ <div ng-app="codeDemo" ng-controller="extract">
18
+ <h2>Sample JSON response body</h2>
19
+ <code ng-repeat="item in sampleData | filter:myData[index].highlight"
20
+ ng-bind-html="item | highlight:myData[index].highlight">
21
+ </code>
22
+ <p>Method:
23
+ <select ng-model="index">
24
+ <option ng-repeat="option in myData" value="{{$index}}">{{option.desc}}
25
+ </option>
26
+ </select>
27
+ </p>
28
+ <p>Code:
29
+ <code>{{ myData[index].method }}</code>
30
+ </p>
31
+ <p>Result:
32
+ <code>{{ myData[index].result }}</code>
33
+ </p>
34
+ </div>
35
+ <script>
36
+ var app = angular.module('codeDemo', []);
37
+ app.controller('extract', function($scope, $http) {
38
+ $http.get("xml_extract.json").then(function(response) {
39
+ $scope.myData = response.data.methods;
40
+ $scope.sampleData = response.data.sampleData;
41
+ });
42
+ })
43
+ .filter('highlight', function($sce) {
44
+ return function(text, phrase) {
45
+ if (phrase) text = text.replace(new RegExp('('+phrase+')', 'gi'),
46
+ '<span class="highlighted">$1</span>')
47
+
48
+ return $sce.trustAsHtml(text)
49
+ }
50
+ });
51
+ </script>
52
+ </body>
53
+ </html>
@@ -0,0 +1,46 @@
1
+ {
2
+ "sampleData":
3
+ ["&lt;root&gt;\n &lt;parent1&gt;\n &lt;child1&gt;5&lt;/child1&gt;\n&lt;child2&gt;parent1 word&lt;/child2&gt;\n &lt;/parent1&gt;\n &lt;parent2&gt;\n &lt;uniq attr=\"test_atr\"&gt;val&lt;/uniq&gt;\n &lt;child2&gt;word2&lt;/child2&gt;\n &lt;/parent2&gt;\n &lt;/root&gt;" ],
4
+ "methods": [
5
+ {
6
+ "desc": "Get response object",
7
+ "method": "@exchange.response",
8
+ "result": "# RestClient::Response or Savon::Response object"
9
+ },
10
+ {
11
+ "desc": "Value from unique element",
12
+ "method": "@exchange['uniq']",
13
+ "result": "'val' # String",
14
+ "highlight": "&lt;uniq "
15
+ },
16
+ {
17
+ "desc": "Value via XPath",
18
+ "method": "@exchange['//parent1/child2']",
19
+ "result": "'parent1 word' # String",
20
+ "highlight": "\n&lt;child2&gt;"
21
+ },
22
+ {
23
+ "desc": "Value via first matching XPath",
24
+ "method": "@exchange['//parent1/uniq|//parent2/uniq']",
25
+ "result": "'val' # String. (First XPath didn't find anything so second was used)",
26
+ "highlight": "&lt;uniq "
27
+ },
28
+ {
29
+ "desc": "List of values matching XPath",
30
+ "method": "@exchange.values_from_path('//child2')",
31
+ "result": "['parent1 word', 'word2'] # Array",
32
+ "highlight": "&lt;child2&gt;"
33
+ },
34
+ {
35
+ "desc": "Convert response into hash",
36
+ "method": "@exchange.to_hash",
37
+ "result": "{:root=&gt;{:parent1=&gt;{:child1=&gt;5, :child2=&gt;\"parent1 word\"}, :parent2=&gt;{:uniq=&gt;\"val\", :child2=&gt;\"word2\"}}} # Hash"
38
+ },
39
+ {
40
+ "desc": "Extract attribute from hash",
41
+ "method": "@exchange.to_hash.dig(:root, :parent2, :uniq).attributes['attr']",
42
+ "result": "test_atr # String",
43
+ "highlight": "attr"
44
+ }
45
+ ]
46
+ }
@@ -24,9 +24,9 @@ module Soaspec
24
24
  # @return [Hash] Hash representing response body
25
25
  def to_hash(response)
26
26
  case Interpreter.response_type_for(response)
27
- when :xml then parse_xml(response.body.to_s)
27
+ when :xml then IndifferentHash.new(parse_xml(response.body.to_s))
28
28
  when :json
29
- JSON.parse(response.body.to_s)
29
+ IndifferentHash.new(JSON.parse(response.body.to_s))
30
30
  else
31
31
  raise "Unable to interpret type of #{response.body}"
32
32
  end
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.2.17'.freeze
2
+ VERSION = '0.2.18'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soaspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.17
4
+ version: 0.2.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-24 00:00:00.000000000 Z
11
+ date: 2019-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -396,10 +396,12 @@ files:
396
396
  - README.md
397
397
  - Rakefile
398
398
  - Todo.md
399
- - demo/extract.html
400
- - demo/extract.json
401
399
  - demo/index.html
402
400
  - demo/js/angular.min.js
401
+ - demo/json_extract.html
402
+ - demo/json_extract.json
403
+ - demo/xml_extract.html
404
+ - demo/xml_extract.json
403
405
  - exe/soaspec
404
406
  - exe/xml_to_yaml_file
405
407
  - images/basic_demo.gif