Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix regression described in mobolic#161 by adding a default API version to all
calls.

Note that while the default version is 1.0, Facebook will automatically
coerce API calls to later versions for newer applications that are
unable to access this version.
  • Loading branch information
martey committed Oct 13, 2014
1 parent e3a7c11 commit 1da18b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions facebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ class GraphAPI(object):
for the active user from the cookie saved by the SDK.
"""

def __init__(self, access_token=None, timeout=None, version=None):
# The default version is only used if the version kwarg does not exist.
default_version = "1.0"
valid_API_versions = ["1.0", "2.0", "2.1"]

self.access_token = access_token
self.timeout = timeout

valid_API_versions = ["1.0", "2.0", "2.1"]
if version:
version_regex = re.compile("^\d\.\d$")
match = version_regex.search(str(version))
Expand All @@ -100,7 +104,7 @@ def __init__(self, access_token=None, timeout=None, version=None):
raise GraphAPIError("Version number should be in the"
" following format: #.# (e.g. 1.0).")
else:
self.version = ""
self.version = "v" + default_version

def get_object(self, id, **args):
"""Fetchs the given object from the graph."""
Expand Down
6 changes: 6 additions & 0 deletions test/test_facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def test_get_app_access_token(self):

class TestAPIVersion(FacebookTestCase):
"""Test if using the correct version of Graph API."""
def test_no_version(self):
graph = facebook.GraphAPI()
self.assertNotEqual(graph.version, None, "Version should not be None.")
self.assertNotEqual(
graph.version, "", "Version should not be an empty string.")

def test_version_1_0(self):
graph = facebook.GraphAPI(version=1.0)
self.assertEqual(graph.get_version(), 1.0)
Expand Down

0 comments on commit 1da18b7

Please sign in to comment.