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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0f969aafc0a1f671abe44b5a3a4aac4fb175980
4
- data.tar.gz: e08dfad5c3d6c06a6e568ec0ec842fdca98e9a98
3
+ metadata.gz: a9b98c0c734e048dc25a4fc0942ec1217d08e1cf
4
+ data.tar.gz: 11d60da98bda8a15ff67f099b7101e15cfd82cb0
5
5
  SHA512:
6
- metadata.gz: ea88c32d7ef4bd06e55815af8882cbe67bb255827e2e16dd9975b5c611da5574854458e095b079eacab517e05e6cf31d2727e7e94a58f99edac74e1a0be31258
7
- data.tar.gz: f1df64deab2b3e8df4660da58c3aa44afaad4f92f6b60157f301905685bbba187d848f99542edf2486000e0e08dfd5a891ddc52199ca416fe35b4256578a03ac
6
+ metadata.gz: 64b4a770f68e2f31d0085602c2b781703a2b7c26d40b9cbef2f68023456ed41e2f10acc2376a0aaa3f8150d097f1bda76cc1fc6e263bd422db047f2499ccc636
7
+ data.tar.gz: 7d620c213e59e9e5daa2422b49e8b320bfeb275ff5589cf2546f89596efd83eda60e132456faf3c72a308ef29567c108e032b67da21835e51e9b90f42ff45aed
data/.gitignore CHANGED
@@ -1,15 +1,42 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
1
+ *.gem
2
+ *.rbc
3
+ /.config
5
4
  /coverage/
6
- /doc/
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
@@ -0,0 +1,5 @@
1
+ AllCops:
2
+ Include:
3
+ - 'Rakefile'
4
+ Exclude:
5
+ - spec/**/*
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in shorter-savon-response.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'simplecov', require: nil
8
+ gem 'codeclimate-test-reporter', require: nil
9
+ end
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
- # Shorter::Savon::Response
1
+ [![Code Climate](https://codeclimate.com/github/mhenrixon/soap-response_cutter/badges/gpa.svg)](https://codeclimate.com/github/mhenrixon/soap-response_cutter) [![Test Coverage](https://codeclimate.com/github/mhenrixon/soap-response_cutter/badges/coverage.svg)](https://codeclimate.com/github/mhenrixon/soap-response_cutter)
2
+ # Soap::ResponseCutter
2
3
 
3
- TODO: Write a gem description
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 'shorter-savon-response'
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 shorter-savon-response
20
+ $ gem install soap-response_cutter
20
21
 
21
22
  ## Usage
22
23
 
23
- TODO: Write usage instructions here
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 'bundler/gem_tasks'
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
@@ -0,0 +1,9 @@
1
+ machine:
2
+ timezone:
3
+ Europe/Stockholm
4
+ ruby:
5
+ version: 2.1.5
6
+
7
+ test:
8
+ override:
9
+ - bundle exec rake
@@ -1,6 +1,6 @@
1
1
  module Soap
2
2
  # nodoc
3
3
  class ResponseCutter
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
6
6
  end
@@ -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
- @response = response_part
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 response_part
38
- response.fetch(response_key) do
39
- response.fetch(reverse_response_key, true)
40
- end
41
- end
42
-
43
- def response_key
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 return_key
58
- key('return')
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
@@ -1,5 +1,5 @@
1
1
  require 'rspec/its'
2
- require 'soap/response_cutter'
2
+ require_relative 'support/coverage.rb'
3
3
 
4
4
  RSpec.configure do |config|
5
5
  config.expect_with :rspec do |expectations|
@@ -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.2
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: