Skip to content

Commit

Permalink
Merge pull request #25 from ambitioninc/develop
Browse files Browse the repository at this point in the history
1.0.4
  • Loading branch information
Micah Hausler committed Jan 8, 2015
2 parents 9bab5d4 + a5fac2f commit eb3de8d
Show file tree
Hide file tree
Showing 19 changed files with 845 additions and 41 deletions.
6 changes: 6 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Release Notes
=============

v1.0.4
------

* Added ``pages`` in response for paginated responses
* Added Labels and Browser Application support

v1.0.3
------

Expand Down
15 changes: 13 additions & 2 deletions newrelic_api/alert_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def list(
:param page: Pagination index
:rtype: dict
:return: The JSON response of the API
:return: The JSON response of the API, with an additional 'pages' key
if there are paginated results
::
Expand Down Expand Up @@ -67,7 +68,17 @@ def list(
]
}
}
]
],
"pages": {
"last": {
"url": "https://api.newrelic.com/v2/alert_policies.json?page=2",
"rel": "last"
},
"next": {
"url": "https://api.newrelic.com/v2/alert_policies.json?page=2",
"rel": "next"
}
}
}
"""
Expand Down
32 changes: 28 additions & 4 deletions newrelic_api/application_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def list(
:param page: Pagination index
:rtype: dict
:return: The JSON response of the API
:return: The JSON response of the API, with an additional 'pages' key
if there are paginated results
::
Expand Down Expand Up @@ -59,7 +60,17 @@ def list(
"server": "integer"
}
}
]
],
"pages": {
"last": {
"url": "https://api.newrelic.com/v2/applications/{application_id}/hosts.json?page=2",
"rel": "last"
},
"next": {
"url": "https://api.newrelic.com/v2/applications/{application_id}/hosts.json?page=2",
"rel": "next"
}
}
}
"""
Expand Down Expand Up @@ -148,7 +159,8 @@ def metric_names(self, application_id, host_id, name=None, page=None):
:param page: Pagination index
:rtype: dict
:return: The JSON response of the API
:return: The JSON response of the API, with an additional 'pages' key
if there are paginated results
::
Expand All @@ -160,7 +172,19 @@ def metric_names(self, application_id, host_id, name=None, page=None):
"string"
]
}
]
],
"pages": {
"last": {
"url": "https://api.newrelic.com/v2/\
applications/{application_id}/hosts/{host_id}/metrics.json?page=2",
"rel": "last"
},
"next": {
"url": "https://api.newrelic.com/v2/\
applications/{application_id}/hosts/{host_id}/metrics.json?page=2",
"rel": "next"
}
}
}
"""
Expand Down
29 changes: 26 additions & 3 deletions newrelic_api/application_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def list(
:param page: Pagination index
:rtype: dict
:return: The JSON response of the API
:return: The JSON response of the API, with an additional 'pages' key
if there are paginated results
::
Expand Down Expand Up @@ -58,7 +59,17 @@ def list(
"server": "integer"
}
}
]
],
"pages": {
"last": {
"url": "https://api.newrelic.com/v2/applications/{application_id}/instances.json?page=2",
"rel": "last"
},
"next": {
"url": "https://api.newrelic.com/v2/applications/{application_id}/instances.json?page=2",
"rel": "next"
}
}
}
"""
Expand Down Expand Up @@ -158,7 +169,19 @@ def metric_names(self, application_id, instance_id, name=None, page=None):
"string"
]
}
]
],
"pages": {
"last": {
"url": "https://api.newrelic.com/v2/\
applications/{application_id}/instances/{instance_id}/metrics.json?page=2",
"rel": "last"
},
"next": {
"url": "https://api.newrelic.com/v2/\
applications/{application_id}/instances/{instance_id}/metrics.json?page=2",
"rel": "next"
}
}
}
"""
Expand Down
40 changes: 32 additions & 8 deletions newrelic_api/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def list(
:param page: Pagination index
:rtype: dict
:return: The JSON response of the API
:return: The JSON response of the API, with an additional 'pages' key
if there are paginated results
::
Expand Down Expand Up @@ -71,7 +72,17 @@ def list(
]
}
}
]
],
"pages": {
"last": {
"url": "https://api.newrelic.com/v2/applications.json?page=2",
"rel": "last"
},
"next": {
"url": "https://api.newrelic.com/v2/applications.json?page=2",
"rel": "next"
}
}
}
"""
Expand Down Expand Up @@ -317,16 +328,29 @@ def metric_names(self, id, name=None, page=None):
:param page: Pagination index
:rtype: dict
:return: The JSON response of the API
:return: The JSON response of the API, with an additional 'pages' key
if there are paginated results
::
{
"metric": {
"name": "string",
"values": [
"string"
]
"metrics": [
{
"name": "string",
"values": [
"string"
]
}
],
"pages": {
"last": {
"url": "https://api.newrelic.com/v2/applications/{application_id}/metrics.json?page=2",
"rel": "last"
},
"next": {
"url": "https://api.newrelic.com/v2/applications/{application_id}/metrics.json?page=2",
"rel": "next"
}
}
}
Expand Down
26 changes: 25 additions & 1 deletion newrelic_api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ def _get(self, *args, **kwargs):
response = requests.get(*args, **kwargs)
if not response.ok:
raise NewRelicAPIServerException('{}: {}'.format(response.status_code, response.text))
return response.json()

json_response = response.json()

if response.links:
json_response['pages'] = response.links

return json_response

def _put(self, *args, **kwargs):
"""
Expand All @@ -65,6 +71,24 @@ def _put(self, *args, **kwargs):
raise NewRelicAPIServerException('{}: {}'.format(response.status_code, response.text))
return response.json()

def _post(self, *args, **kwargs):
"""
A wrapper for posting things. It will also json encode your 'data' parameter
:returns: The response of your post
:rtype: dict
:raises: This will raise a
:class:`NewRelicAPIServerException<newrelic_api.exceptions.NewRelicAPIServerException>`
if there is an error from New Relic
"""
if 'data' in kwargs:
kwargs['data'] = json.dumps(kwargs['data'])
response = requests.post(*args, **kwargs)
if not response.ok:
raise NewRelicAPIServerException('{}: {}'.format(response.status_code, response.text))
return response.json()

def _delete(self, *args, **kwargs):
"""
A wrapper for deleting things
Expand Down
98 changes: 98 additions & 0 deletions newrelic_api/browser_applications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from .base import Resource


class BrowserApplications(Resource):
"""
An interface for interacting with the NewRelic Browser Application API.
"""
def list(self, filter_name=None, filter_ids=None, page=None):
"""
This API endpoint returns a list of the Browser Applications associated
with your New Relic account.
Browser Applications can be filtered by their name, or by the
application IDs.
:type filter_name: str
:param filter_name: Filter by application name
:type filter_ids: list of ints
:param filter_ids: Filter by application ids
:type page: int
:param page: Pagination index
:rtype: dict
:return: The JSON response of the API, with an additional 'pages' key
if there are paginated results
::
{
"browser_applications": [
{
"id": "integer",
"name": "string",
"browser_monitoring_key": "string",
"loader_script": "string"
}
],
"pages": {
"last": {
"url": "https://api.newrelic.com/v2/browser_applications.json?page=2",
"rel": "last"
},
"next": {
"url": "https://api.newrelic.com/v2/browser_applications.json?page=2",
"rel": "next"
}
}
}
"""
filters = [
'filter[name]={0}'.format(filter_name) if filter_name else None,
'filter[ids]={0}'.format(','.join([str(app_id) for app_id in filter_ids])) if filter_ids else None,
'page={0}'.format(page) if page else None
]

return self._get(
url='{0}browser_applications.json'.format(self.URL),
headers=self.headers,
params=self.build_param_string(filters)
)

def create(self, name):
"""
This API endpoint allows you to create a standalone Browser Application
:type name: str
:param name: The name of the application
:rtype: dict
:return: The JSON response of the API
::
{
"browser_application": {
"id": "integer",
"name": "string",
"browser_monitoring_key": "string",
"loader_script": "string"
}
}
"""

data = {
"browser_application": {
"name": name
}
}

return self._post(
url='{0}browser_applications.json'.format(self.URL),
headers=self.headers,
data=data
)
Loading

0 comments on commit eb3de8d

Please sign in to comment.