Skip to content

Commit

Permalink
updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
shyal committed Dec 6, 2016
1 parent 0cb8803 commit b1cb3bc
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 1 deletion.
85 changes: 85 additions & 0 deletions docs/source/soap.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
.. soap
====
soap
====

In this example we'll take a look a using hoverpy when working with SOAP. To run this example, simply execute:

``env PYTHONPATH=.:${PYTHONPATH} examples/soap/soap.py --capture``

which runs the program in capture mode, then:

``env PYTHONPATH=.:${PYTHONPATH} examples/soap/soap.py``

Which simply runs our program in simulate mode.

This program gets our IP address from ``http://jsontest.com``, then uses it to do some geolocation using a WDSL SOAP web service. In my case, I'm getting this:

.. code-block:: json
{
'ResolveIPResult':{
'City':u'London',
'HasDaylightSavings':False,
'CountryCode':u'GB',
'AreaCode':u'0',
'Country':u'United Kingdom',
'StateProvince':u'H9',
'Longitude':-0.09550476,
'TimeZone':None,
'Latitude':51.5092,
'Organization':None,
'Certainty':90,
'RegionName':None
}
}
Which is what the ``ip2geo`` service thinks is the location of the SpectoLabs office!

.. literalinclude:: ../../examples/soap/soap.py
:language: python
:lines: 3-5

Above, we bring in our usual suspect libraries. Namely the ``HoverPy`` class, ``pysimplesoap`` which is a straight forward SOAP client, and the ``requests`` library.

.. literalinclude:: ../../examples/soap/soap.py
:language: python
:lines: 7-11

We use argparse so we can run our app in ``--capture`` mode first.


.. literalinclude:: ../../examples/soap/soap.py
:language: python
:lines: 14

We then construct HoverPy either in capture, or simulate mode, depending on the flag provided.


.. literalinclude:: ../../examples/soap/soap.py
:language: python
:lines: 15

We then make a get HTTP request to ``http://ip.jsontest.com`` for our IP address. This is very similar to our basic example.

.. literalinclude:: ../../examples/soap/soap.py
:language: python
:lines: 16

We now tell ``pysimplesoap`` to use ``urllib2``, this is because urllib2 happens to play well with proxies.

.. literalinclude:: ../../examples/soap/soap.py
:language: python
:lines: 18-20

We then build our SOAP client, pointing to the ip2go WSDL schema description URL.

.. literalinclude:: ../../examples/soap/soap.py
:language: python
:lines: 22

We finally invoke the ``ResolveIP`` method on our SOAP client. So to resume, in this example we built a program that gets our IP address from one external service, and then builds a SOAP client using a WSDL schema description, and finally queries the SOAP service for our location using said IP address.

If you really want to prove to yourself that hoverfly is indeed playing back the requests, then you can run the script in simulate mode without an internet connection. Timing our script also shows us we're now running approximately 10x faster.

1 change: 1 addition & 0 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ I don't know about you, but for me the best way of getting into things is by try
modify
urllib2eg
urllib3eg
soap



2 changes: 2 additions & 0 deletions examples/soap/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests
pysimplesoap
22 changes: 22 additions & 0 deletions examples/soap/soap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/python

from hoverpy import HoverPy
import pysimplesoap
import requests

from argparse import ArgumentParser

parser = ArgumentParser(description="Perform proxy testing/URL list creation")
parser.add_argument("--capture", help="capture the data", action="store_true")
args = parser.parse_args()


with HoverPy(capture=args.capture):
ipAddress = requests.get("http://ip.jsontest.com/myip").json()["ip"]
pysimplesoap.transport.set_http_wrapper("urllib2")

client = pysimplesoap.client.SoapClient(
wsdl='http://ws.cdyne.com/ip2geo/ip2geo.asmx?WSDL'
)

print(client.ResolveIP(ipAddress=ipAddress, licenseKey="0"))
3 changes: 2 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ docs: .PHONY
mv examples/unittesting/unittesting.rst docs/source/
mv examples/urllib2eg/urllib2eg.rst docs/source/
mv examples/urllib3eg/urllib3eg.rst docs/source/

sphinx-apidoc -o docs/source/ hoverpy

cd docs; make html;
# cd docs/source/mermaid/intro; mermaid *;

### -------------------------------------------------------------------------------
## You'll need to save this into your ~/.pypirc if you'd like to push this to pypi
Expand Down

0 comments on commit b1cb3bc

Please sign in to comment.