Last active
August 29, 2015 14:07
-
-
Save flyhigher139/c7fe7b4ed363dd92e561 to your computer and use it in GitHub Desktop.
code api sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
base_url = "http://172.28.193.221:8000" | |
project_id = 1 | |
code_type_id = 36 | |
def code_api(project_id, code_type_id): | |
url="/api/v1/codes/project/{project_id}/code-type/{code_type_id}".format(project_id=project_id, code_type_id=code_type_id) | |
return url | |
def wrap_url(url): | |
full_url = base_url + url | |
return full_url | |
def get_codes(project_id, code_type_id): | |
url = wrap_url(code_api(project_id, code_type_id)) | |
response = requests.get(url, auth=('admin', 'admin')) | |
print response.status_code | |
return response.json() if response.status_code==200 else None | |
def create_data(): | |
data={ | |
"full_code": "AAA12-BBB13-C4", | |
"dict_value_json": ["AAA12", "BBB13", "C4"], | |
"project": 1, | |
"code_type": 36 | |
} | |
data=json.dumps(data) | |
return data | |
def post_data(): | |
data = create_data() | |
url = wrap_url(code_api(project_id, code_type_id)) | |
headers = {'content-type': 'application/json'} | |
response = requests.post(url, data=data, headers=headers, auth=('admin', 'admin')) | |
print response.status_code | |
return response | |
if __name__ == '__main__': | |
# print get_codes(project_id, code_type_id) | |
# print create_data() | |
post_data() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment