malcolm 0.0.2 → 0.1.0
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 +7 -0
- data/lib/malcolm.rb +6 -6
- data/lib/malcolm/exceptions.rb +3 -0
- data/lib/malcolm/request/soap_builder.rb +7 -8
- data/lib/malcolm/response/soap_parser.rb +10 -11
- data/lib/malcolm/version.rb +3 -0
- data/spec/malcolm/request/soap_builder_spec.rb +12 -3
- data/spec/malcolm/response/soap_parser_spec.rb +7 -2
- metadata +68 -40
- data/README.md +0 -22
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: ce48a7b3712eb2d682e308b30b5e3ac8153ce6c6
         | 
| 4 | 
            +
              data.tar.gz: 040a16adb500ea31bb00486a95011b343f1b54c8
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: a86a1a211487167fb7d3a8c8b5e6894e1ea8ebd0a41474c4eaf58130b902406adf133748a6e86c75bb7e9c7fd5141740a6eddea67c9970f8414c4de1018630b1
         | 
| 7 | 
            +
              data.tar.gz: d8deaf6c14307d53cc89fd877cfb87d43722adfdcef4255c33d1ea73211e929f4fb4b9be5d4e9b7e15f9c786277c7b4e1ba16f118568fc6079ed207ee553bf68
         | 
    
        data/lib/malcolm.rb
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            require 'faraday'
         | 
| 2 | 
            +
            require 'nori'
         | 
| 3 | 
            +
            require 'gyoku'
         | 
| 4 | 
            +
            require 'malcolm/exceptions'
         | 
| 2 5 |  | 
| 3 6 | 
             
            module Malcolm
         | 
| 4 7 | 
             
              autoload :SOAPBuilder, 'malcolm/request/soap_builder'
         | 
| 5 8 | 
             
              autoload :SOAPParser,  'malcolm/response/soap_parser'
         | 
| 6 9 |  | 
| 7 | 
            -
              Faraday.register_middleware : | 
| 8 | 
            -
                :soap => SOAPBuilder
         | 
| 9 | 
            -
                
         | 
| 10 | 
            -
              Faraday.register_middleware :response,
         | 
| 11 | 
            -
                :soap => SOAPParser
         | 
| 10 | 
            +
              Faraday::Request.register_middleware soap: SOAPBuilder
         | 
| 12 11 |  | 
| 13 | 
            -
             | 
| 12 | 
            +
              Faraday::Response.register_middleware soap: SOAPParser
         | 
| 13 | 
            +
            end
         | 
| @@ -2,23 +2,22 @@ module Malcolm | |
| 2 2 | 
             
              # Request middleware that converts params to XML and wraps them in a SOAP envelope.
         | 
| 3 3 | 
             
              #See http://www.w3.org/TR/2007/REC-soap12-part0-20070427/
         | 
| 4 4 | 
             
              class SOAPBuilder < Faraday::Middleware
         | 
| 5 | 
            -
                 | 
| 6 | 
            -
                
         | 
| 7 | 
            -
                # Assumes request body is a hash of key-value pairs    
         | 
| 5 | 
            +
                # Assumes request body is a hash of key-value pairs
         | 
| 8 6 | 
             
                def call(env)
         | 
| 9 7 | 
             
                  env[:body] = wrap(env[:body])
         | 
| 10 8 | 
             
                  @app.call env
         | 
| 11 9 | 
             
                end
         | 
| 12 | 
            -
             | 
| 10 | 
            +
             | 
| 13 11 | 
             
              private
         | 
| 14 | 
            -
             | 
| 12 | 
            +
             | 
| 15 13 | 
             
                # Builds an XML document around request data
         | 
| 16 14 | 
             
                def wrap(data)
         | 
| 17 | 
            -
                  raise "Request body already serialized.  Please make sure it is a hash before applying SOAP Builder." unless data.is_a?(Hash)
         | 
| 18 15 | 
             
                  "<?xml version=\"1.0\" encoding=\"UTF-8\"?><env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"><env:Body>".tap do |soap_envelope|
         | 
| 19 | 
            -
                     | 
| 16 | 
            +
                    unless data.blank?
         | 
| 17 | 
            +
                      soap_envelope << (data.is_a?(Hash) ? Gyoku.xml(data) : data)
         | 
| 18 | 
            +
                    end
         | 
| 20 19 | 
             
                    soap_envelope << "</env:Body></env:Envelope>"
         | 
| 21 20 | 
             
                  end
         | 
| 22 21 | 
             
                end
         | 
| 23 22 | 
             
              end
         | 
| 24 | 
            -
            end
         | 
| 23 | 
            +
            end
         | 
| @@ -1,25 +1,24 @@ | |
| 1 1 | 
             
            module Malcolm
         | 
| 2 2 | 
             
              # Response middleware that unwraps a SOAP envelope for you
         | 
| 3 3 | 
             
              class SOAPParser < Faraday::Response::Middleware
         | 
| 4 | 
            -
                dependency 'nori'
         | 
| 5 | 
            -
                
         | 
| 6 | 
            -
                Nori.configure do |config|
         | 
| 7 | 
            -
                  config.strip_namespaces = true
         | 
| 8 | 
            -
                  config.convert_tags_to { |tag| tag.snakecase.to_sym }
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
                
         | 
| 11 4 | 
             
                def initialize(env, *args)
         | 
| 12 5 | 
             
                  key = args[0]
         | 
| 13 6 | 
             
                  super(env)
         | 
| 14 7 | 
             
                end
         | 
| 15 | 
            -
             | 
| 8 | 
            +
             | 
| 16 9 | 
             
                # Expects response XML to already be parsed
         | 
| 17 10 | 
             
                def on_complete(env)
         | 
| 18 | 
            -
                  env[:body] = Nori. | 
| 11 | 
            +
                  env[:body] = Nori.new(
         | 
| 12 | 
            +
                    strip_namespaces: true,
         | 
| 13 | 
            +
                    convert_tags_to: ->(tag) { tag.snakecase.to_sym }
         | 
| 14 | 
            +
                  ).parse(env[:body])
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  raise SOAPError, "Invalid SOAP response" if env[:body].empty?
         | 
| 17 | 
            +
             | 
| 19 18 | 
             
                  env[:body] = env[:body][:envelope][:body]
         | 
| 20 19 | 
             
                  env[:body] = find_key_in_hash(env[:body], @key)
         | 
| 21 20 | 
             
                end
         | 
| 22 | 
            -
             | 
| 21 | 
            +
             | 
| 23 22 | 
             
              private
         | 
| 24 23 |  | 
| 25 24 | 
             
                # Finds +index+ in +hash+ by searching recursively
         | 
| @@ -42,6 +41,6 @@ module Malcolm | |
| 42 41 | 
             
                    end
         | 
| 43 42 | 
             
                  end
         | 
| 44 43 | 
             
                end
         | 
| 45 | 
            -
             | 
| 44 | 
            +
             | 
| 46 45 | 
             
              end
         | 
| 47 46 | 
             
            end
         | 
| @@ -18,11 +18,20 @@ describe Malcolm::SOAPBuilder do | |
| 18 18 | 
             
                xml.should include %{<test>data}
         | 
| 19 19 | 
             
              end
         | 
| 20 20 |  | 
| 21 | 
            -
              it " | 
| 21 | 
            +
              it "directly inserts string data into hash" do
         | 
| 22 22 | 
             
                middleware = described_class.new(lambda{|env| env})
         | 
| 23 | 
            -
                env = {:body => "test | 
| 24 | 
            -
                 | 
| 23 | 
            +
                env = {:body => "<test>data</test>", :request_headers => Faraday::Utils::Headers.new}
         | 
| 24 | 
            +
                result = middleware.call(env)
         | 
| 25 | 
            +
                xml = result[:body]
         | 
| 26 | 
            +
                xml.should include %{<test>data</test>}
         | 
| 25 27 | 
             
              end
         | 
| 26 28 |  | 
| 29 | 
            +
              it "ignores empty data" do
         | 
| 30 | 
            +
                middleware = described_class.new(lambda{|env| env})
         | 
| 31 | 
            +
                env = {:body => {}, :request_headers => Faraday::Utils::Headers.new}
         | 
| 32 | 
            +
                result = middleware.call(env)
         | 
| 33 | 
            +
                xml = result[:body]
         | 
| 34 | 
            +
                xml.should include %{<env:Body></env:Body>}    
         | 
| 35 | 
            +
              end
         | 
| 27 36 |  | 
| 28 37 | 
             
            end
         | 
| @@ -8,14 +8,14 @@ describe Malcolm::SOAPParser do | |
| 8 8 | 
             
                res = middleware.on_complete(env)
         | 
| 9 9 | 
             
                res.should be_a Hash
         | 
| 10 10 | 
             
              end
         | 
| 11 | 
            -
             | 
| 11 | 
            +
             | 
| 12 12 | 
             
              it "drills down to body" do
         | 
| 13 13 | 
             
                env = { :body => load_fixture("soap.xml") }
         | 
| 14 14 | 
             
                middleware = described_class.new(lambda{|env| env})
         | 
| 15 15 | 
             
                res = middleware.on_complete(env)
         | 
| 16 16 | 
             
                res.keys.should_not include(:envelope)
         | 
| 17 17 | 
             
              end
         | 
| 18 | 
            -
             | 
| 18 | 
            +
             | 
| 19 19 | 
             
              it "fetches given key" do
         | 
| 20 20 | 
             
                env = { :body => load_fixture("soap.xml") }
         | 
| 21 21 | 
             
                middleware = described_class.new(lambda{|env| env}, :item)
         | 
| @@ -23,4 +23,9 @@ describe Malcolm::SOAPParser do | |
| 23 23 | 
             
                res.keys.should_not include(:envelope)
         | 
| 24 24 | 
             
              end
         | 
| 25 25 |  | 
| 26 | 
            +
              it "raises on invalid response" do
         | 
| 27 | 
            +
                env = { :body => "" }
         | 
| 28 | 
            +
                middleware = described_class.new(lambda{|env| env}, :item)
         | 
| 29 | 
            +
                expect { middleware.on_complete(env) }.to raise_error(Malcolm::SOAPError)
         | 
| 30 | 
            +
              end
         | 
| 26 31 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,113 +1,141 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: malcolm
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0 | 
| 5 | 
            -
              prerelease: 
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 6 5 | 
             
            platform: ruby
         | 
| 7 6 | 
             
            authors:
         | 
| 8 7 | 
             
            - Floyd Wright
         | 
| 9 8 | 
             
            autorequire: 
         | 
| 10 9 | 
             
            bindir: bin
         | 
| 11 10 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date:  | 
| 11 | 
            +
            date: 2014-06-03 00:00:00.000000000 Z
         | 
| 13 12 | 
             
            dependencies:
         | 
| 14 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 14 | 
             
              name: faraday
         | 
| 16 | 
            -
              requirement:  | 
| 17 | 
            -
                none: false
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 18 16 | 
             
                requirements:
         | 
| 19 | 
            -
                - - ~>
         | 
| 17 | 
            +
                - - "~>"
         | 
| 20 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            -
                    version: 0. | 
| 19 | 
            +
                    version: 0.9.0
         | 
| 22 20 | 
             
              type: :runtime
         | 
| 23 21 | 
             
              prerelease: false
         | 
| 24 | 
            -
              version_requirements:  | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: 0.9.0
         | 
| 25 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 26 | 
            -
              name:  | 
| 27 | 
            -
              requirement:  | 
| 28 | 
            -
                none: false
         | 
| 28 | 
            +
              name: gyoku
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 29 30 | 
             
                requirements:
         | 
| 30 | 
            -
                - -  | 
| 31 | 
            +
                - - ">="
         | 
| 31 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            -
                    version:  | 
| 33 | 
            +
                    version: 0.4.4
         | 
| 33 34 | 
             
              type: :runtime
         | 
| 34 35 | 
             
              prerelease: false
         | 
| 35 | 
            -
              version_requirements:  | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ">="
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: 0.4.4
         | 
| 36 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 37 42 | 
             
              name: nori
         | 
| 38 | 
            -
              requirement:  | 
| 39 | 
            -
                none: false
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 40 44 | 
             
                requirements:
         | 
| 41 | 
            -
                - -  | 
| 45 | 
            +
                - - ">="
         | 
| 42 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 43 47 | 
             
                    version: 1.1.0
         | 
| 44 48 | 
             
              type: :runtime
         | 
| 45 49 | 
             
              prerelease: false
         | 
| 46 | 
            -
              version_requirements:  | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: 1.1.0
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: nokogiri
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ">="
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: 1.6.2.1
         | 
| 62 | 
            +
              type: :runtime
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - ">="
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: 1.6.2.1
         | 
| 47 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 48 70 | 
             
              name: rake
         | 
| 49 | 
            -
              requirement:  | 
| 50 | 
            -
                none: false
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 51 72 | 
             
                requirements:
         | 
| 52 | 
            -
                - - ~>
         | 
| 73 | 
            +
                - - "~>"
         | 
| 53 74 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 75 | 
             
                    version: 0.9.2.2
         | 
| 55 76 | 
             
              type: :development
         | 
| 56 77 | 
             
              prerelease: false
         | 
| 57 | 
            -
              version_requirements:  | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - "~>"
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: 0.9.2.2
         | 
| 58 83 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 59 84 | 
             
              name: rspec
         | 
| 60 | 
            -
              requirement:  | 
| 61 | 
            -
                none: false
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 62 86 | 
             
                requirements:
         | 
| 63 | 
            -
                - - ~>
         | 
| 87 | 
            +
                - - "~>"
         | 
| 64 88 | 
             
                  - !ruby/object:Gem::Version
         | 
| 65 | 
            -
                    version: 2. | 
| 89 | 
            +
                    version: 2.10.0
         | 
| 66 90 | 
             
              type: :development
         | 
| 67 91 | 
             
              prerelease: false
         | 
| 68 | 
            -
              version_requirements:  | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - "~>"
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: 2.10.0
         | 
| 97 | 
            +
            description: |2
         | 
| 98 | 
            +
                  A collection of Faraday middleware
         | 
| 72 99 | 
             
            email: fwright@site5.com
         | 
| 73 100 | 
             
            executables: []
         | 
| 74 101 | 
             
            extensions: []
         | 
| 75 102 | 
             
            extra_rdoc_files:
         | 
| 76 103 | 
             
            - README.markdown
         | 
| 77 104 | 
             
            files:
         | 
| 105 | 
            +
            - README.markdown
         | 
| 78 106 | 
             
            - Rakefile
         | 
| 79 | 
            -
            -  | 
| 107 | 
            +
            - lib/malcolm.rb
         | 
| 108 | 
            +
            - lib/malcolm/exceptions.rb
         | 
| 80 109 | 
             
            - lib/malcolm/request/soap_builder.rb
         | 
| 81 110 | 
             
            - lib/malcolm/response/soap_parser.rb
         | 
| 82 | 
            -
            - lib/malcolm.rb
         | 
| 111 | 
            +
            - lib/malcolm/version.rb
         | 
| 83 112 | 
             
            - spec/fixtures/soap.xml
         | 
| 84 113 | 
             
            - spec/malcolm/request/soap_builder_spec.rb
         | 
| 85 114 | 
             
            - spec/malcolm/response/soap_parser_spec.rb
         | 
| 86 115 | 
             
            - spec/spec_helper.rb
         | 
| 87 | 
            -
            - README.markdown
         | 
| 88 116 | 
             
            homepage: https://github.com/site5/malcolm
         | 
| 89 117 | 
             
            licenses: []
         | 
| 118 | 
            +
            metadata: {}
         | 
| 90 119 | 
             
            post_install_message: 
         | 
| 91 120 | 
             
            rdoc_options:
         | 
| 92 | 
            -
            - --charset=UTF-8
         | 
| 121 | 
            +
            - "--charset=UTF-8"
         | 
| 93 122 | 
             
            require_paths:
         | 
| 94 123 | 
             
            - lib
         | 
| 95 124 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 96 | 
            -
              none: false
         | 
| 97 125 | 
             
              requirements:
         | 
| 98 | 
            -
              - -  | 
| 126 | 
            +
              - - ">="
         | 
| 99 127 | 
             
                - !ruby/object:Gem::Version
         | 
| 100 128 | 
             
                  version: '0'
         | 
| 101 129 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 102 | 
            -
              none: false
         | 
| 103 130 | 
             
              requirements:
         | 
| 104 | 
            -
              - -  | 
| 131 | 
            +
              - - ">="
         | 
| 105 132 | 
             
                - !ruby/object:Gem::Version
         | 
| 106 133 | 
             
                  version: '0'
         | 
| 107 134 | 
             
            requirements: []
         | 
| 108 135 | 
             
            rubyforge_project: 
         | 
| 109 | 
            -
            rubygems_version:  | 
| 136 | 
            +
            rubygems_version: 2.2.2
         | 
| 110 137 | 
             
            signing_key: 
         | 
| 111 | 
            -
            specification_version:  | 
| 138 | 
            +
            specification_version: 4
         | 
| 112 139 | 
             
            summary: A collection of Faraday middleware
         | 
| 113 140 | 
             
            test_files: []
         | 
| 141 | 
            +
            has_rdoc: 
         | 
    
        data/README.md
    DELETED
    
    | @@ -1,22 +0,0 @@ | |
| 1 | 
            -
            # Malcolm [![Malcolm Build Status][Build Icon]][Build Status]
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            Malcolm is a collection of middleware for [Faraday](https://github.com/technoweenie/faraday),
         | 
| 4 | 
            -
            the excellent HTTP client interface based on [Rack](http://rack.github.com/).
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            [Build Icon]: https://secure.travis-ci.org/site5/malcolm.png?branch=master
         | 
| 7 | 
            -
            [Build Status]: https://travis-ci.org/site5/malcolm
         | 
| 8 | 
            -
             | 
| 9 | 
            -
            ## Note on Patches/Pull Requests
         | 
| 10 | 
            -
             | 
| 11 | 
            -
            * Fork the project.
         | 
| 12 | 
            -
            * Make your feature addition or bug fix.
         | 
| 13 | 
            -
            * Add tests for it. This is important so I don't break it in a
         | 
| 14 | 
            -
              future version unintentionally.
         | 
| 15 | 
            -
            * Commit, do not mess with rakefile, version, or history.
         | 
| 16 | 
            -
              (if you want to have your own version, that is fine but bump version in a
         | 
| 17 | 
            -
              commit by itself I can ignore when I pull)
         | 
| 18 | 
            -
            * Send me a pull request. Bonus points for topic branches.
         | 
| 19 | 
            -
             | 
| 20 | 
            -
            ## Copyright
         | 
| 21 | 
            -
             | 
| 22 | 
            -
            Copyright (c) 2012 Site5.com. See LICENSE for details.
         |