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

Update athenahealthapi Python3 sample to support Apigee #31

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: 9 additions & 9 deletions samplecode/python3/athenahealthapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class APIConnection(object):
practiceid -- If set, this will be used as the practiceid parameter to API calls
"""

def __init__(self, version, key, secret, practiceid=None):
def __init__(self, environment, version, key, secret, practiceid=None):
"""Connects to the specified API version using key and secret.

If authentication fails due to JSON decoding, this raises a ResponseException.
Expand All @@ -85,16 +85,16 @@ def __init__(self, version, key, secret, practiceid=None):
Optional arguments:
practiceid -- the practice ID to be used in constructing URLs
"""
auth_prefix_from_version = {
'v1': '/oauth',
'preview1': '/oauthpreview',
'openpreview1': '/oauthopenpreview',
host_from_environment = {
'prod': 'api.platform.athenahealth.com',
'preview': 'api.preview.platform.athenahealth.com'
}

self._host = 'api.athenahealth.com'
self._environment = environment
self._version = version.strip('/')
self._host = host_from_environment[self._environment]
self._connection = http.client.HTTPSConnection(self._host)
self._auth_url = auth_prefix_from_version[self._version]
self._auth_url = '/oauth2/v1'
self._key = key
self._secret = secret
self._authenticate()
Expand All @@ -106,7 +106,7 @@ def _authenticate(self):
# URL to use is determined by the version of the API specified in __init__.
base64string = str(base64.b64encode(bytes('{0}:{1}'.format(self._key, self._secret), 'utf-8')), 'utf-8')

parameters = urllib.parse.urlencode({'grant_type': 'client_credentials'})
parameters = urllib.parse.urlencode({'grant_type': 'client_credentials', 'scope': 'athena/service/Athenanet.MDP.*'})
headers = {
'Content-type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic {0}'.format(base64string),
Expand Down
5 changes: 3 additions & 2 deletions samplecode/python3/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
####################################################################################################
key = 'CHANGEME: YOUR_API_KEY'
secret = 'CHANGEME: YOUR_API_SECRET'
version = 'preview1'
environment = 'preview'
version = 'v1'
practiceid = 000000

api = athenahealthapi.APIConnection(version, key, secret, practiceid)
api = athenahealthapi.APIConnection(environment, version, key, secret, practiceid)

# If you want to change which practice you're working with after initialization, this is how.
# api.practiceid = 000000
Expand Down