Changeset 6e2b61292464…
Parent e2a407f8ff9f…
by Nathan Gerhart
Changes to 3 files · Browse files at 6e2b61292464 Showing diff from parent e2a407f8ff9f Diff from another changeset...
|
|
@@ -43,8 +43,16 @@
Note that, per API v5.0, all data between tags, such as the token, is now wrapped in CDATA. BeautifulSoup's implementation of CData generally allows for it to be treated as a string, except for one important case: CData.__str__() (a.k.a. str(CData)) returns the full text, including the CDATA wrapper (e.g. "<![CDATA[foo]]>"). To avoid accidentally including the CDATA tage, use CData.encode('utf-8')
+Additional Details:
+-------------------
+
+If your script requires a certain version of the FogBugz API, make sure to pass it as an argument to the constructor. This will protect you from unexpected differences should we make backwards-incompatible changes.
+
+ >>> from fogbugz import FogBugz
+ >>> fb = FogBugz("http://example.fogbugz.com", api_version=5)
+
For more info on the API:
-http://our.fogbugz.com/help/topics/advanced/API.html
+http://help.fogcreek.com/the-fogbugz-api
Much of the API has not been thoroughly tested. Please report bugs to customer-service@fogcreek.com
|
@@ -1,3 +1,4 @@ + from __future__ import print_function
import sys
try:
from email.generator import _make_boundary
@@ -30,8 +31,11 @@class FogBugzConnectionError(FogBugzAPIError):
pass
+class FogBugzAPIVersionError(FogBugzAPIError):
+ pass
+
class FogBugz:
- def __init__(self, url, token=None):
+ def __init__(self, url, token=None, api_version=8):
self.__handlerCache = {}
if not url.endswith('/'):
url += '/'
@@ -48,6 +52,20 @@ except (urllib_request.URLError, urllib_request.HTTPError):
e = sys.exc_info()[1]
raise FogBugzConnectionError("Library could not connect to the FogBugz API. Either this installation of FogBugz does not support the API, or the url, %s, is incorrect.\n\nError: %s" % (self._url, e))
+
+ # check API version
+ self._minversion = int(soup.response.minversion.string)
+ self._maxversion = int(soup.response.version.string)
+ if api_version and type(api_version) is int:
+ if api_version < self._maxversion:
+ print("There is a newer version of the FogBugz API available. Please update to version %d to avoid errors in the future" % self._maxversion, file=sys.stderr)
+ elif api_version > self._maxversion:
+ raise FogBugzAPIVersionError("This script requires API version %d and the maximum version supported by %s is %d." % (api_version, url, self._maxversion))
+ if api_version < self._minversion:
+ raise FogBugzAPIVersionError("This script requires API version %d and the minimum version supported by %s is %d. Please update to use the latest API version" % (api_version, url, self._minversion))
+ else:
+ raise FogBugzAPIVersionError("api_version parameter must be an int")
+
self._url = url + soup.response.url.string
self.currentFilter = None
|
Loading...