Skip to content

Commit d7c3de2

Browse files
committed
Added version number to headers.
1 parent 1d2405c commit d7c3de2

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ bb2_env/
159159
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160160
# and can be added to the global gitignore or merged into this file. For a more nuclear
161161
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162-
#.idea/
162+
# NOTE: Using this option is fine in this case as we don't use other JetBrains tools in
163+
# this codebase.
164+
.idea/
163165

164166
# End of https://www.toptal.com/developers/gitignore/api/python
165167
#

cms_bluebutton/auth.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import urllib
88
from requests_toolbelt.multipart.encoder import MultipartEncoder
99

10-
from .constants import SDK_HEADER, SDK_HEADER_KEY
10+
from .constants import SDK_HEADERS
1111

1212

1313
class AuthorizationToken:
@@ -58,9 +58,7 @@ def refresh_auth_token(bb, auth_token):
5858
"refresh_token": auth_token.refresh_token,
5959
}
6060

61-
headers = {
62-
SDK_HEADER_KEY: SDK_HEADER,
63-
}
61+
headers = SDK_HEADERS
6462

6563
token_response = requests.post(
6664
url=bb.auth_token_url,
@@ -132,10 +130,12 @@ def get_access_token_from_code(bb, auth_data, callback_code):
132130
}
133131

134132
mp_encoder = MultipartEncoder(data)
133+
headers = SDK_HEADERS
134+
headers["content-type"] = mp_encoder.content_type
135135
token_response = requests.post(
136136
url=bb.auth_token_url,
137137
data=mp_encoder,
138-
headers={"content-type": mp_encoder.content_type, SDK_HEADER_KEY: SDK_HEADER},
138+
headers=headers
139139
)
140140
token_response.raise_for_status()
141141
token_dict = token_response.json()

cms_bluebutton/constants.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
SDK_HEADER = "python"
2-
SDK_HEADER_KEY = "X-BLUEBUTTON-SDK"
1+
SDK_VERSION = "0.1.0"
2+
3+
SDK_HEADERS = {
4+
"X-BLUEBUTTON-SDK": "python",
5+
"X-BLUEBUTTON-SDK-VERSION": SDK_VERSION
6+
}
37

48
REFRESH_TOKEN_ENDPOINT = "/o/token/"
59

cms_bluebutton/fhir_request.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import requests
22
from requests.adapters import HTTPAdapter, Retry
33

4-
from .constants import SDK_HEADER, SDK_HEADER_KEY
4+
from .constants import SDK_HEADERS
55

66

77
def fhir_request(bb, config):
@@ -15,10 +15,8 @@ def fhir_request(bb, config):
1515
total=3, backoff_factor=5, status_forcelist=[500, 502, 503, 504]
1616
)
1717
full_url = "{}/v{}/{}".format(bb.base_url, bb.version, config["url"])
18-
headers = {
19-
"Authorization": "Bearer " + auth_token.access_token,
20-
SDK_HEADER_KEY: SDK_HEADER,
21-
}
18+
headers = SDK_HEADERS
19+
headers["Authorization"] = "Bearer " + auth_token.access_token
2220
adapter = HTTPAdapter(max_retries=retry_config)
2321
sesh = requests.Session()
2422
sesh.mount("https://", adapter)

0 commit comments

Comments
 (0)