Total Complexity | 6 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | 1 | from json import dumps |
|
14 | 1 | class Deployment(object): |
|
15 | 1 | ENDPOINT = 'https://api.newrelic.com/v2/applications/%(app_id)s/deployments.json' |
|
16 | |||
17 | 1 | def __init__(self, api_key, app_id, user): |
|
18 | 1 | self.__api_key = api_key |
|
19 | 1 | self.__app_id = app_id |
|
20 | 1 | self.__user = user |
|
21 | |||
22 | 1 | @property |
|
23 | def endpoint(self): |
||
24 | 1 | return self.ENDPOINT % dict(app_id=self.__app_id) |
|
25 | |||
26 | 1 | @property |
|
27 | def headers(self): |
||
28 | 1 | return { |
|
29 | 'Content-Type': 'application/json', |
||
30 | 'X-Api-Key': self.__api_key |
||
31 | } |
||
32 | |||
33 | 1 | def get_payload(self, revision, changelog, description): |
|
34 | 1 | return { |
|
35 | "deployment" : { |
||
36 | "revision": str(revision), |
||
37 | "changelog": str(changelog), |
||
38 | "description": str(description), |
||
39 | "user": str(self.__user) |
||
40 | } |
||
41 | } |
||
42 | |||
43 | 1 | def deploy(self, revision, changelog, description): |
|
44 | 1 | payload = self.get_payload(revision, changelog, description) |
|
45 | 1 | response = requests.post(self.endpoint, headers=self.headers, json=payload) |
|
46 | |||
47 | 1 | if response.status_code != 201: |
|
48 | 1 | raise NewRelicDeploymentException |
|
49 | |||
50 | return response |
||
51 |