Code Monkey home page Code Monkey logo

soap-object's Introduction

SoapObject

Module to make it simpler to tests SOAP web services. The goal is to abstract all information about how your call and parse results from the web service within the soap objects.

Defining a soap-object

class AirportService
  include SoapObject

  wsdl 'http://www.webservicex.net/airport.asmx?WSDL'

  def airport_name
    xpath('//Table/CityOrAirportName').first.content
  end

end

Client Properties

By default, the following properties are set on the Savon::Client:

log: false
ssl_verify_mode: :none
ssl_version: :SSLv3

The following methods are available to set client properties:

proxy 'http://proxy.com:8080'
open_timeout 10
read_timeout 20
soap_header 'Token' => 'secret'
encoding 'UTF-16'
basic_auth 'steve', 'secret'
digest_auth 'digest', 'auth'
log_level :error
soap_version 2

ssl_options do |opts|
  opts.verify_mode = :peer
  opts.version = :SSLv2
end

Usage

require 'soap-object'

service = AirportService.new

service.operations
#=> [:get_airport_information_by_iso_country_code,
#    :get_airport_information_by_city_or_airport_name,
#    :get_airport_information_by_country,
#    :get_airport_information_by_airport_code]

service.get_airport_information_by_airport_code
#=> <Savon::Response>

By default soap-object attempts to handle any missing method call by passing it through to the underlying Savon client. This enable the soap-object to handle calls to all operations on a given WSDL.

Using with Cucumber

Include the factory methods by placing the following line in the cucumber env.rb file.

World(SoapObject::Factory)

By doing so, soap-object's methods are available in cucumbers step definitions.

When(/^I request the airport information for "([^"]*)"$/) do |airport_code|
  using(AirportService).get_airport_information_by_airport_code({airport_code: airport_code})
end

Then(/^the airport name should be "([^"]*)"$/) do |airport_name|
  expect(using(AirportService).airport_name).to be eq(airport_name)
end

Parsing the response

Several methods exists on the soap-object to help parse the response.

Return the xml response

  • to_xml

Return value at a specific path using xpath

  • xpath(path)

Return the response as a Hash

  • to_hash

Return the body of the message as a Hash

  • body

Return the response as a Nokogiri document

  • doc

Installation

Add this line to your application's Gemfile:

gem 'soap-object'

And then execute:

$ bundle

Or install it yourself as:

$ gem install soap-object

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

soap-object's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

soap-object's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.