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 Changes Only README.txt Stacked
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
 
 
 
 
 
 
 
46
47
 
48
49
50
51
52
53
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
55
56
57
58
59
60
61
 Python FogBugz API Wrapper  --------------------------    This Python API is simply a wrapper around the FogBugz API, with some help from Leonard Richardson's BeautifulSoup (http://www.crummy.com/software/BeautifulSoup/) and the magic of Python's __getattr__().    Getting Started:  ----------------    To use the FogBugz API, install the package either by downloading the source and running     $ python setup.py install    or by using pip     $ pip install fogbugz    A Quick Example:  ----------------    ::     >>> from fogbugz import FogBugz   >>> fb = FogBugz("http://example.fogbugz.com/") # URL is to your FogBugz install   >>> fb.logon("logon@example.com", "password")   >>> resp = fb.search(q="assignedto:tyler") # All calls take named parameters, per the API   >>> resp # Responses are BeautifulSoup objects of the response XML.   <response><cases count="2"><case ixbug="1" operations="edit,assign,resolve,email,remind"></case><case ixbug="2" operations="edit,spam,assign,resolve,reply,forward,remind"></case></cases></response>   >>> # You shouldn't need to know too much about BeautifulSoup, but the documentation can be found here:   >>> # http://www.crummy.com/software/BeautifulSoup/documentation.html   >>> for case in resp.cases.childGenerator(): # One way to access the cases   ... print case['ixbug']   ...   1   2   >>> for case in resp.findAll('case'): # Another way to access the cases   ... print case['operations']   ...   edit,assign,resolve,email,remind   edit,spam,assign,resolve,reply,forward,remind   >>> resp = fb.edit(ixbug=1, sEvent="Edit from the API") # Note the named parameters   >>> resp   <response><case ixbug="1" operations="edit,assign,resolve,email,remind"></case></response>    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    ``fogbugz_bis`` is a fork of the FogCreek codebase to support Python 3 and  BeautifulSoup 4. You should install/require only one of ``fogbugz`` or  ``fogbugz_bis`` as they both implement the same module.
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