soap-response_cutter 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +32 -5
- data/.rubocop.yml +5 -0
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/README.md +8 -5
- data/Rakefile +23 -1
- data/circle.yml +9 -0
- data/lib/soap/response_cutter/version.rb +1 -1
- data/lib/soap/response_cutter.rb +12 -33
- data/spec/lib/soap/response_cutter_spec.rb +48 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/coverage.rb +22 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9b98c0c734e048dc25a4fc0942ec1217d08e1cf
|
4
|
+
data.tar.gz: 11d60da98bda8a15ff67f099b7101e15cfd82cb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64b4a770f68e2f31d0085602c2b781703a2b7c26d40b9cbef2f68023456ed41e2f10acc2376a0aaa3f8150d097f1bda76cc1fc6e263bd422db047f2499ccc636
|
7
|
+
data.tar.gz: 7d620c213e59e9e5daa2422b49e8b320bfeb275ff5589cf2546f89596efd83eda60e132456faf3c72a308ef29567c108e032b67da21835e51e9b90f42ff45aed
|
data/.gitignore
CHANGED
@@ -1,15 +1,42 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
/_yardoc/
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
5
4
|
/coverage/
|
6
|
-
/
|
5
|
+
/InstalledFiles
|
7
6
|
/pkg/
|
8
7
|
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
9
10
|
/tmp/
|
11
|
+
/_yardoc/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
10
17
|
*.bundle
|
11
18
|
*.so
|
12
19
|
*.o
|
13
20
|
*.a
|
14
21
|
mkmf.log
|
15
22
|
.idea/
|
23
|
+
|
24
|
+
## Documentation cache and generated files:
|
25
|
+
/.yardoc/
|
26
|
+
/_yardoc/
|
27
|
+
/doc/
|
28
|
+
/rdoc/
|
29
|
+
|
30
|
+
## Environment normalisation:
|
31
|
+
/.bundle/
|
32
|
+
/lib/bundler/man/
|
33
|
+
|
34
|
+
# for a library or gem, you might want to ignore these files since the code is
|
35
|
+
# intended to run in multiple environments; otherwise, check them in:
|
36
|
+
# Gemfile.lock
|
37
|
+
# .ruby-version
|
38
|
+
# .ruby-gemset
|
39
|
+
|
40
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
41
|
+
.rvmrc
|
42
|
+
Gemfile.lock
|
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Mikael Henriksson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
|
1
|
+
[](https://codeclimate.com/github/mhenrixon/soap-response_cutter) [](https://codeclimate.com/github/mhenrixon/soap-response_cutter)
|
2
|
+
# Soap::ResponseCutter
|
2
3
|
|
3
|
-
|
4
|
+
Gets rid of the `<XmlResponse><XmlResult>` and returns just the stuff you really need
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
7
8
|
Add this line to your application's Gemfile:
|
8
9
|
|
9
10
|
```ruby
|
10
|
-
gem '
|
11
|
+
gem 'soap-response_cutter'
|
11
12
|
```
|
12
13
|
|
13
14
|
And then execute:
|
@@ -16,11 +17,13 @@ And then execute:
|
|
16
17
|
|
17
18
|
Or install it yourself as:
|
18
19
|
|
19
|
-
$ gem install
|
20
|
+
$ gem install soap-response_cutter
|
20
21
|
|
21
22
|
## Usage
|
22
23
|
|
23
|
-
|
24
|
+
```ruby
|
25
|
+
Soap::ResponseCutter.new(action, response).parse
|
26
|
+
```
|
24
27
|
|
25
28
|
## Contributing
|
26
29
|
|
data/Rakefile
CHANGED
@@ -1,2 +1,24 @@
|
|
1
|
-
require '
|
1
|
+
require 'rspec/core'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
2
4
|
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
|
7
|
+
if defined?(RSpec)
|
8
|
+
namespace :style do
|
9
|
+
desc 'Run Ruby style checks'
|
10
|
+
RuboCop::RakeTask.new(:ruby) do |task|
|
11
|
+
task.patterns = %w(lib/**/*.rb spec/**/*.rb)
|
12
|
+
task.formatters = ['files']
|
13
|
+
task.fail_on_error = true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Run all style checks'
|
18
|
+
task style: %w(style:ruby)
|
19
|
+
|
20
|
+
desc 'Run all specs in spec directory (excluding plugin specs)'
|
21
|
+
RSpec::Core::RakeTask.new(:spec)
|
22
|
+
task test: :spec
|
23
|
+
task default: %w(style spec)
|
24
|
+
end
|
data/circle.yml
ADDED
data/lib/soap/response_cutter.rb
CHANGED
@@ -7,6 +7,7 @@ module Soap
|
|
7
7
|
# Examples:
|
8
8
|
# ResponseCutter.new(:soap_action, { somes: 'value'})
|
9
9
|
class ResponseCutter
|
10
|
+
USELESS_KEYS = %w(response result return)
|
10
11
|
attr_reader :action, :response
|
11
12
|
|
12
13
|
def initialize(action, response)
|
@@ -17,16 +18,8 @@ module Soap
|
|
17
18
|
|
18
19
|
# rubocop:disable MethodLength
|
19
20
|
def parse
|
20
|
-
|
21
|
-
|
22
|
-
return response if response == true
|
23
|
-
return response unless response.is_a?(Hash)
|
24
|
-
|
25
|
-
@response = return_part
|
26
|
-
if response.is_a?(Hash)
|
27
|
-
if (res = return_part)
|
28
|
-
return res
|
29
|
-
end
|
21
|
+
catch :done do
|
22
|
+
flatten_response while useless_nesting?
|
30
23
|
end
|
31
24
|
response
|
32
25
|
end
|
@@ -34,32 +27,18 @@ module Soap
|
|
34
27
|
|
35
28
|
private
|
36
29
|
|
37
|
-
def
|
38
|
-
|
39
|
-
response.fetch(
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
key('response')
|
45
|
-
end
|
46
|
-
|
47
|
-
def reverse_response_key
|
48
|
-
reverse_key('response')
|
49
|
-
end
|
50
|
-
|
51
|
-
def return_part
|
52
|
-
response.fetch(return_key) do
|
53
|
-
response.fetch(reverse_return_key, true)
|
30
|
+
def flatten_response
|
31
|
+
USELESS_KEYS.each do |suffix|
|
32
|
+
@response = response.fetch(key(suffix)) do
|
33
|
+
response.fetch(reverse_key(suffix)) { response }
|
34
|
+
end
|
35
|
+
throw :done unless response.is_a?(Hash)
|
36
|
+
throw :done unless useless_nesting?
|
54
37
|
end
|
55
38
|
end
|
56
39
|
|
57
|
-
def
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
def reverse_return_key
|
62
|
-
reverse_key('return')
|
40
|
+
def useless_nesting?
|
41
|
+
response.any? { |k| k.to_s =~ /response|result|return/ }
|
63
42
|
end
|
64
43
|
|
65
44
|
def key(suffix)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'soap/response_cutter'
|
2
3
|
|
3
4
|
describe Soap::ResponseCutter do
|
4
5
|
describe '#parse' do
|
@@ -25,5 +26,52 @@ describe Soap::ResponseCutter do
|
|
25
26
|
end
|
26
27
|
its(:parse) { should eq(expected) }
|
27
28
|
end
|
29
|
+
|
30
|
+
context 'nested inverted result' do
|
31
|
+
let(:response) do
|
32
|
+
{
|
33
|
+
abc_response_v2: {
|
34
|
+
abc_return_v2: {
|
35
|
+
abc_return_v2: expected
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
its(:parse) { should eq(expected) }
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'real world example' do
|
44
|
+
let(:expected) do
|
45
|
+
{
|
46
|
+
offer_id: '737',
|
47
|
+
game_id: '262',
|
48
|
+
user_id: '1',
|
49
|
+
lines: '1',
|
50
|
+
coins: '20',
|
51
|
+
rounds: '5',
|
52
|
+
denomination: '0.1000',
|
53
|
+
expire_time: 'Sun, 13 Dec 2015 00:00:00 +0000',
|
54
|
+
freegame_external_id: '1',
|
55
|
+
used: nil,
|
56
|
+
turnover: '0',
|
57
|
+
finished: nil,
|
58
|
+
rounds_used: '0',
|
59
|
+
freegame_trigger_id: nil,
|
60
|
+
created: 'Sat, 13 Dec 2014 14:20:11 +0000',
|
61
|
+
currency: nil,
|
62
|
+
'@xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance'
|
63
|
+
}
|
64
|
+
end
|
65
|
+
let(:response) do
|
66
|
+
{
|
67
|
+
add_freegame_offers_response: {
|
68
|
+
add_freegame_offers_result: expected
|
69
|
+
},
|
70
|
+
:@xmlns => 'http://playngo.com/v1'
|
71
|
+
}
|
72
|
+
end
|
73
|
+
subject { Soap::ResponseCutter.new(:add_freegame_offers, response) }
|
74
|
+
its(:parse) { should eq(expected) }
|
75
|
+
end
|
28
76
|
end
|
29
77
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'codeclimate-test-reporter'
|
3
|
+
formatters = [SimpleCov::Formatter::HTMLFormatter]
|
4
|
+
|
5
|
+
if ENV['CODECLIMATE_REPO_TOKEN']
|
6
|
+
formatters << CodeClimate::TestReporter::Formatter
|
7
|
+
CodeClimate::TestReporter.start
|
8
|
+
end
|
9
|
+
|
10
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[*formatters]
|
11
|
+
SimpleCov.profiles.define 'gem' do
|
12
|
+
add_filter '/spec'
|
13
|
+
add_group 'lib', '/lib'
|
14
|
+
add_group 'soap', '/lib/soap'
|
15
|
+
end
|
16
|
+
|
17
|
+
SimpleCov.start 'gem'
|
18
|
+
|
19
|
+
if ENV['CIRCLE_ARTIFACTS']
|
20
|
+
dir = File.join(ENV['CIRCLE_ARTIFACTS'], 'coverage')
|
21
|
+
SimpleCov.coverage_dir(dir)
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soap-response_cutter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikael Henriksson
|
@@ -103,15 +103,19 @@ extra_rdoc_files: []
|
|
103
103
|
files:
|
104
104
|
- ".gitignore"
|
105
105
|
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
106
107
|
- Gemfile
|
108
|
+
- LICENSE
|
107
109
|
- LICENSE.txt
|
108
110
|
- README.md
|
109
111
|
- Rakefile
|
112
|
+
- circle.yml
|
110
113
|
- lib/soap/response_cutter.rb
|
111
114
|
- lib/soap/response_cutter/version.rb
|
112
115
|
- soap-response_cutter.gemspec
|
113
116
|
- spec/lib/soap/response_cutter_spec.rb
|
114
117
|
- spec/spec_helper.rb
|
118
|
+
- spec/support/coverage.rb
|
115
119
|
homepage: ''
|
116
120
|
licenses:
|
117
121
|
- MIT
|
@@ -139,4 +143,5 @@ summary: Gets rid of <SomethingResponse><SomethingResult> from soap responses
|
|
139
143
|
test_files:
|
140
144
|
- spec/lib/soap/response_cutter_spec.rb
|
141
145
|
- spec/spec_helper.rb
|
146
|
+
- spec/support/coverage.rb
|
142
147
|
has_rdoc:
|