# coding=utf-8

import requests
import datetime
import json


class HttpClient(object):

    def post(self, url, data, headers):
        return requests.post(url, data=json.dumps(data), headers=headers)

    def get(self, url, data, headers):
        return requests.get(url, data=data, headers=headers)

    def delete(self, url, data, headers):
        return requests.delete(url, data=json.dumps(data), headers=headers)

    def put(self, url, data, headers):
        return requests.put(url, data=json.dumps(data), headers=headers)


if __name__ == "__main__":
    # 在上面所有接口中除特殊情况应该返回相同数据结构 要么全是json 要么全不是
    # 学习一下 py 中 private public protected，该什么时候使用这三种访问限定符
    client = HttpClient()
    now_time = datetime.datetime.now()

    headers_target = {
        "reqtme":datetime.datetime.strftime(now_time, '%Y-%m-%d %H:%M:%S'),
        "Content-Type":"application/json;charset=UTF-8"
    }

    # postMethod = 'post'
    host_target = 'http://47.96.183.143:9091'

    loginUrl = host_target + '/' + '/api/ums/login/signin'

    loginData = {
        "account": "ces001",
        "password": "123456"
    }

    # getMethod = 'get'
    logoutUrl = host_target + '/' + '/api/ums/login/signout/'

    #TODO: getMethod = 'delete'
    sealShapeDelUrl = host_target + '/' + '/api/office/seal/delete'

    sealShapeDelData = {
        "id": 58,
        "type": 2
    }

    #TODO: getMethod = 'put'
    sealConfigUrl = host_target + '/' + 'api/office/seal/config'

    sealConfigData = {
        "sealName": "测试行政印章类型",
        "type": 2,
        "adscription": "2",
        "id": 55,
        "approvalNeed": 0
    }

    loginResult = client.post(loginUrl, loginData, headers_target)
    logoutResult = client.get(logoutUrl + '2', None, headers_target)
    sealShapeDelResult = client.delete(sealShapeDelUrl, sealShapeDelData, headers_target)
    sealConfigResult = client.put(sealShapeDelUrl, sealConfigData, headers_target)

    print(loginResult.headers)
    print(logoutResult.headers)
    print(sealShapeDelResult.headers)
    print(sealConfigResult.headers)
