Skip to content

Commit

Permalink
Define URLs as constants.
Browse files Browse the repository at this point in the history
Thanks to @crohling, who submitted a pull request that included these
changes that I never responded to. Close mobolic#79.
  • Loading branch information
martey committed Feb 13, 2016
1 parent 42655b1 commit ebf77b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions facebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@

__version__ = version.__version__


FACEBOOK_GRAPH_URL = "https://graph.facebook.com/"
FACEBOOK_OAUTH_DIALOG_URL = "https://www.facebook.com/dialog/oauth?"
VALID_API_VERSIONS = ["2.0", "2.1", "2.2", "2.3", "2.4", "2.5"]


Expand Down Expand Up @@ -202,12 +203,12 @@ def get_version(self):
"""Fetches the current version number of the Graph API being used."""
args = {"access_token": self.access_token}
try:
response = requests.request("GET",
"https://graph.facebook.com/" +
self.version + "/me",
params=args,
timeout=self.timeout,
proxies=self.proxies)
response = requests.request(
"GET",
FACEBOOK_GRAPH_URL + self.version + "/me",
params=args,
timeout=self.timeout,
proxies=self.proxies)
except requests.HTTPError as e:
response = json.loads(e.read())
raise GraphAPIError(response)
Expand Down Expand Up @@ -241,8 +242,7 @@ def request(

try:
response = requests.request(method or "GET",
"https://graph.facebook.com/" +
path,
FACEBOOK_GRAPH_URL + path,
timeout=self.timeout,
params=args,
data=post_args,
Expand Down Expand Up @@ -449,7 +449,7 @@ def parse_signed_request(signed_request, app_secret):


def auth_url(app_id, canvas_url, perms=None, **kwargs):
url = "https://www.facebook.com/dialog/oauth?"
url = FACEBOOK_OAUTH_DIALOG_URL
kvps = {'client_id': app_id, 'redirect_uri': canvas_url}
if perms:
kvps['scope'] = ",".join(perms)
Expand Down
2 changes: 1 addition & 1 deletion test/test_facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def test_auth_url(self):
perms = ['email', 'birthday']
redirect_url = 'https://localhost/facebook/callback/'

expected_url = 'https://www.facebook.com/dialog/oauth?' + urlencode(
expected_url = facebook.FACEBOOK_OAUTH_DIALOG_URL + urlencode(
dict(client_id=self.app_id,
redirect_uri=redirect_url,
scope=','.join(perms)))
Expand Down

0 comments on commit ebf77b3

Please sign in to comment.