FogBugz » FogBugzPy A Python wrapper for the FogBugz API Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master

master fogbugz.py: Check API Version information during init

The default version is the max API version at the time of this commit
and we check to make sure the expected version is between the min
and max versions supported by the FogBugz URL in use.

Changeset 6e2b61292464

Parent e2a407f8ff9f

by Profile picture of Nathan GerhartNathan Gerhart

Changes to 3 files · Browse files at 6e2b61292464 Showing diff from parent e2a407f8ff9f Diff from another changeset...

Change 1 of 1 Show Entire File .gitignore Stacked
 
 
 
 
 
 
 
 
1
2
3
4
5
6
@@ -1,0 +1,6 @@
+*.pyc +.eggs +venv +build +dist +fogbugz.egg-info
Change 1 of 1 Show Entire File README.txt Stacked
 
43
44
45
 
 
 
 
 
 
 
 
46
47
 
48
49
50
 
43
44
45
46
47
48
49
50
51
52
53
54
 
55
56
57
58
@@ -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  
Change 1 of 3 Show Entire File fogbugz.py Stacked
 
 
1
2
3
 
30
31
32
 
 
 
33
34
 
35
36
37
 
48
49
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
52
53
 
1
2
3
4
 
31
32
33
34
35
36
37
 
38
39
40
41
 
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@@ -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