Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

softened version check and set default version to 13.0 #503

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions facebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
FACEBOOK_GRAPH_URL = "https://graph.facebook.com/"
FACEBOOK_WWW_URL = "https://www.facebook.com/"
FACEBOOK_OAUTH_DIALOG_PATH = "dialog/oauth?"
VALID_API_VERSIONS = ["3.1", "3.2", "3.3", "4.0", "5.0", "6.0", "7.0", "8.0"]
DEFAULT_VERSION = "13.0"
VALID_SEARCH_TYPES = ["place", "placetopic"]


Expand Down Expand Up @@ -83,33 +83,25 @@ def __init__(
session=None,
app_secret=None,
):
# The default version is only used if the version kwarg does not exist.
default_version = VALID_API_VERSIONS[0]

self.access_token = access_token
self.timeout = timeout
self.proxies = proxies
self.session = session or requests.Session()
self.app_secret_hmac = None

if version:
version_regex = re.compile(r"^\d\.\d{1,2}$")
version_regex = re.compile(r"^\d+\.\d{1,2}$")
match = version_regex.search(str(version))
if match is not None:
if str(version) not in VALID_API_VERSIONS:
raise GraphAPIError(
"Valid API versions are "
+ str(VALID_API_VERSIONS).strip("[]")
)
else:
self.version = "v" + str(version)
self.version = "v" + str(version)
else:
raise GraphAPIError(
"Version number should be in the"
" following format: #.# (e.g. 2.0)."
)
else:
self.version = "v" + default_version
# The default version is only used if the version kwarg does not exist.
self.version = "v" + DEFAULT_VERSION

if app_secret and access_token:
self.app_secret_hmac = hmac.new(
Expand Down
5 changes: 2 additions & 3 deletions test/test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ def test_no_version(self):
)

def test_valid_versions(self):
for version in facebook.VALID_API_VERSIONS:
graph = facebook.GraphAPI(version=version)
self.assertEqual(str(graph.get_version()), version)
graph = facebook.GraphAPI(version=facebook.DEFAULT_VERSION)
self.assertEqual(str(graph.get_version()), facebook.DEFAULT_VERSION)

def test_invalid_version(self):
self.assertRaises(
Expand Down