Skip to content

Commit 6dbd5e7

Browse files
author
Greg Taylor
committed
Lots of documentation and fine-tuning.
1 parent fe08bf3 commit 6dbd5e7

File tree

7 files changed

+196
-32
lines changed

7 files changed

+196
-32
lines changed

docs/build_docs.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
epydoc-2.6 -v --config epydoc.config --check

docs/epydoc.config

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[epydoc] # Epydoc section marker (required by ConfigParser)
2+
3+
# Information about the project.
4+
name: python-fedex
5+
url: http://code.google.com/p/python-fedex/
6+
7+
# The list of modules to document. Modules can be named using
8+
# dotted names, module filenames, or package directory names.
9+
# This option may be repeated.
10+
modules: ../fedex
11+
12+
# Write html output to the directory "apidocs"
13+
output: html
14+
target: apidocs/
15+
16+
# Include all automatically generated graphs. These graphs are
17+
# generated using Graphviz dot.
18+
graph: all
19+
dotpath: /opt/local/bin/dot

fedex/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
python-fedex API Documentation
3+
==============================
4+
The python-fedex module is a light wrapper around Fedex's Web Services SOAP API.
5+
Using the excellent U{suds<https://fedorahosted.org/suds/>} SOAP client,
6+
the Fedex requests and responses are trivial to work with.
7+
8+
What python-fedex is
9+
--------------------
10+
- A light wrapper around Fedex Web Services SOAP API.
11+
- Simple and easy to use.
12+
- Minimal by design.
13+
14+
What python-fedex is not
15+
------------------------
16+
- An abstraction layer. python-fedex only assembles the needed SOAP calls
17+
and returns a SOAP response through suds. This is easy enough to work with
18+
that no abstraction is needed. Doing so would limit your use of the data.
19+
- Anything more than a light wrapper.
20+
21+
A note on completeness
22+
----------------------
23+
python-fedex was created for use with some of my internal projects. For the
24+
initial release, only the things that I needed at the time were implemented.
25+
If there is missing functionality, please report an U{issue<http://code.google.com/p/python-fedex/issues/list>}
26+
so that I may make this module more useful to others. Likewise, feel free to
27+
submit patches as well if you would like to help.
28+
29+
Getting Support
30+
---------------
31+
If you have any questions, problems, ideas, or patch submissions, please visit
32+
our U{Google Code project<http://code.google.com/p/python-fedex/>} and enter
33+
an issue in the U{Issue Tracker<http://code.google.com/p/python-fedex/issues/list>}.
34+
"""

fedex/base_service.py

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,64 @@
1+
"""
2+
The L{base_service} module contains classes that form the low level foundations
3+
of the Web Service API. Things that many different kinds of requests have in
4+
common may be found here.
5+
6+
In particular, the L{FedexBaseService} class handles most of the basic,
7+
repetetive setup work that most requests do.
8+
"""
19
import os
210
import logging
311
from suds.client import Client
412

513
class FedexBaseService(object):
14+
"""
15+
This class is the master class for all Fedex request objects. It gets all
16+
of the common SOAP objects created via suds and populates them with
17+
values from a L{FedexConfig} object, along with keyword arguments
18+
via L{__init__}.
19+
20+
@note: This object should never be used directly, use one of the included
21+
sub-classes.
22+
"""
623
def __init__(self, config_obj, wsdl_name, *args, **kwargs):
24+
"""
25+
This constructor should only be called by children of the class. As is
26+
such, only the optional keyword arguments caught by C{**kwargs} will
27+
be documented.
28+
29+
@type customer_transaction_id: L{str}
30+
@keyword customer_transaction_id: A user-specified identifier to
31+
differentiate this transaction from others. This value will be
32+
returned with the response from Fedex.
33+
@type carrier_code: L{str}
34+
@keyword carrier_code: The carrier code to use for this query. In most
35+
cases, this will be FDXE (Fedex Express). Must be one of the
36+
following four-letter codes:
37+
- FDXC (Fedex Cargo)
38+
- FDXE (Fedex Express)
39+
- FDXG (Fedex Ground)
40+
- FXCC (Fedex Custom Critical)
41+
- FXFR (Fedex Freight)
42+
- FXSP (Fedex Smartpost)
43+
"""
744
self.config_obj = config_obj
845
self.wsdl_path = os.path.join(config_obj.wsdl_path, wsdl_name)
946
self.client = Client('file://%s' % self.wsdl_path)
1047
self.logger = logging.getLogger('fedex')
48+
self.response = None
49+
"""@ivar: The response from Fedex. You will want to pick what you
50+
want out here here. This object does have a __str__() method,
51+
you'll want to print or log it to see what possible values
52+
you can pull."""
1153

1254
self.logger.debug(self.client)
13-
self.set_web_authentication_detail()
14-
self.set_client_detail()
15-
self.set_version_id()
16-
self.set_carrier_code_type(*args, **kwargs)
17-
self.set_transaction_detail(*args, **kwargs)
55+
self.__set_web_authentication_detail()
56+
self.__set_client_detail()
57+
self.__set_version_id()
58+
self.__set_carrier_code_type(*args, **kwargs)
59+
self.__set_transaction_detail(*args, **kwargs)
1860

19-
def set_web_authentication_detail(self):
61+
def __set_web_authentication_detail(self):
2062
"""
2163
Sets up the WebAuthenticationDetail node. This is required for all
2264
requests.
@@ -32,7 +74,7 @@ def set_web_authentication_detail(self):
3274
self.logger.debug(WebAuthenticationDetail)
3375
self.WebAuthenticationDetail = WebAuthenticationDetail
3476

35-
def set_client_detail(self):
77+
def __set_client_detail(self):
3678
"""
3779
Sets up the ClientDetail node, which is required for all shipping
3880
related requests.
@@ -44,7 +86,7 @@ def set_client_detail(self):
4486
self.logger.debug(ClientDetail)
4587
self.ClientDetail = ClientDetail
4688

47-
def set_transaction_detail(self, *args, **kwargs):
89+
def __set_transaction_detail(self, *args, **kwargs):
4890
"""
4991
Checks kwargs for 'customer_transaction_id' and sets it if present.
5092
"""
@@ -57,7 +99,7 @@ def set_transaction_detail(self, *args, **kwargs):
5799
else:
58100
self.TransactionDetail = None
59101

60-
def set_carrier_code_type(self, *args, **kwargs):
102+
def __set_carrier_code_type(self, *args, **kwargs):
61103
"""
62104
Checks kwargs for 'carrier_code' and sets it if present.
63105
"""
@@ -70,22 +112,22 @@ def set_carrier_code_type(self, *args, **kwargs):
70112
else:
71113
self.CarrierCodeType = None
72114

73-
def set_version_id(self):
115+
def __set_version_id(self):
74116
"""
75117
Pulles the versioning info for the request from the child request.
76118
"""
77119
VersionId = self.client.factory.create('VersionId')
78-
VersionId.ServiceId = self.version_info['service_id']
79-
VersionId.Major = self.version_info['major']
80-
VersionId.Intermediate = self.version_info['intermediate']
81-
VersionId.Minor = self.version_info['minor']
120+
VersionId.ServiceId = self._version_info['service_id']
121+
VersionId.Major = self._version_info['major']
122+
VersionId.Intermediate = self._version_info['intermediate']
123+
VersionId.Minor = self._version_info['minor']
82124
self.logger.debug(VersionId)
83125
self.VersionId = VersionId
84126

85127
def send_request(self):
86128
"""
87129
Sends the assembled request on the child object.
88130
"""
89-
self.response = self.assemble_and_send_request()
131+
self.response = self._assemble_and_send_request()
90132
self.logger.info("== FEDEX QUERY RESULT ==")
91133
self.logger.info(self.response)

fedex/config.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,55 @@
1+
"""
2+
The L{config} module contains the L{FedexConfig} class, which is passed to
3+
the Fedex API calls. It stores useful information such as your Web Services
4+
account numbers and keys.
5+
6+
It is strongly suggested that you create a single L{FedexConfig} object in
7+
your project and pass that to the various API calls, rather than create new
8+
L{FedexConfig} objects haphazardly. This is merely a design suggestion,
9+
treat it as such.
10+
"""
111
import os
212
import sys
313

414
class FedexConfig(object):
515
"""
616
Base configuration class that is used for the different Fedex SOAP calls.
17+
These are generally passed to the Fedex request classes as arguments.
18+
You may instantiate a L{FedexConfig} object with the minimal C{key} and
19+
C{password} arguments and set the instance variables documented below
20+
at a later time if you must.
721
"""
822
def __init__(self, key, password, account_number=None, meter_number=None,
923
integrator_id=None, wsdl_path=None):
24+
"""
25+
@type key: L{str}
26+
@param key: Developer test key.
27+
@type password: L{str}
28+
@param password: The Fedex-generated password for your Web Systems
29+
account. This is generally emailed to you after registration.
30+
@type account_number: L{str}
31+
@keyword account_number: The account number sent to you by Fedex after
32+
registering for Web Services.
33+
@type meter_number: L{str}
34+
@keyword meter_number: The meter number sent to you by Fedex after
35+
registering for Web Services.
36+
@type integrator_id: L{str}
37+
@keyword integrator_id: The integrator string sent to you by Fedex after
38+
registering for Web Services.
39+
@type wsdl_path: L{str}
40+
@keyword wsdl_path: In the event that you want to override the path to
41+
your WSDL directory, do so with this argument.
42+
"""
1043
self.key = key
44+
"""@ivar: Developer test key."""
1145
self.password = password
46+
"""@ivar: Fedex Web Services password."""
1247
self.account_number = account_number
48+
"""@ivar: Web Services account number."""
1349
self.meter_number = meter_number
50+
"""@ivar: Web services meter number."""
1451
self.integrator_id = integrator_id
52+
"""@ivar: Web services integrator ID."""
1553

1654
# Allow overriding of the WDSL path.
1755
if wsdl_path == None:

fedex/services/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
This module contains the wrappers around Fedex Web Service requests which you
3+
will want to instantiate and use with a L{FedexConfig} object supplying
4+
your static details. Each module here corresponds to a Fedex WSDL.
5+
"""

fedex/services/ship_service.py

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,56 @@
1+
"""
2+
Ship Service Module
3+
===================
4+
This package contains the shipping and tracking methods defined by Fedex's
5+
ShipService WSDL file. Each is encapsulated in a class for easy access.
6+
For more details on each, refer to the respective class's documentation.
7+
"""
18
from .. base_service import FedexBaseService
29

310
class FedexTrackRequest(FedexBaseService):
11+
"""
12+
This class allows you to track shipments by providing a tracking
13+
number or other identifying features. By default, you
14+
can simply pass a tracking number to the constructor. If you would like
15+
to query shipments based on something other than tracking number, you will
16+
want to read the documentation for the L{__init__} method.
17+
Particularly, the tracking_value and package_identifier arguments.
18+
"""
419
def __init__(self, config_obj, tracking_value,
520
package_identifier='TRACKING_NUMBER_OR_DOORTAG',
621
*args, **kwargs):
722
"""
8-
Sends a shipment tracking request.
23+
Sends a shipment tracking request. The optional keyword args
24+
detailed on L{FedexBaseService} apply here as well.
925
10-
package_identifier: (str) Determines what you are using to query for
11-
the shipment. The default assumes that
12-
tracking_value will be a Fedex tracking #.
13-
tracking_value: (str) Based on the value of package_identifier, this
14-
will be anything from a tracking number to
15-
a purchase order number.
26+
@type tracking_value: L{str}
27+
@param tracking_value: Based on the value of package_identifier,
28+
this will be anything from a tracking number to a purchase order
29+
number.
30+
@type package_identifier: L{str}
31+
@keyword package_identifier: Determines what you are using to query for
32+
the shipment. The default assumes that tracking_value will be a Fedex
33+
tracking number.
1634
"""
17-
self.config_obj = config_obj
35+
self._config_obj = config_obj
36+
1837
# Holds version info for the VersionId SOAP object.
19-
self.version_info = {'service_id': 'trck', 'major': '4',
38+
self._version_info = {'service_id': 'trck', 'major': '4',
2039
'intermediate': '0', 'minor': '0'}
2140
# Call the parent FedexBaseService class for basic setup work.
22-
super(FedexTrackRequest, self).__init__(config_obj,
41+
super(FedexTrackRequest, self).__init__(self._config_obj,
2342
'TrackService_v4.wsdl',
2443
*args, **kwargs)
25-
# Start preparing the Fedex-specific things.
26-
self.tracking_value = tracking_value
44+
45+
# Important request-specific instance variables.
2746
self.package_identifier = package_identifier
28-
self.set_track_package_identifier()
47+
"""@ivar: Determines what L{tracking_value} is, be it a tracking number,
48+
purchase order, or other things."""
49+
self.tracking_value = tracking_value
50+
"""@ivar: This is typically a Fedex tracking number, but setting
51+
L{package_identifier} to other values makes this change."""
2952

30-
def set_track_package_identifier(self):
53+
def __set_track_package_identifier(self):
3154
"""
3255
This sets the package identifier information. This may be a tracking
3356
number or a few different things as per the Fedex spec.
@@ -38,12 +61,14 @@ def set_track_package_identifier(self):
3861
self.logger.debug(TrackPackageIdentifier)
3962
self.TrackPackageIdentifier = TrackPackageIdentifier
4063

41-
def assemble_and_send_request(self):
64+
def _assemble_and_send_request(self):
4265
"""
4366
Fires off the Fedex request.
44-
NEVER CALL THIS METHOD DIRECTLY. CALL SEND_REQUEST(), WHICH RESIDES
45-
ON FedexBaseService AND IS INHERITED.
67+
68+
@warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_request(), WHICH RESIDES
69+
ON FedexBaseService AND IS INHERITED.
4670
"""
71+
self.__set_track_package_identifier()
4772
client = self.client
4873
# Fire off the query.
4974
response = client.service.track(WebAuthenticationDetail=self.WebAuthenticationDetail,

0 commit comments

Comments
 (0)