Created by Brian Cherinka on 2016-04-26 09:20:35 Licensed under a 3-clause BSD license.
marvin.api.api.
Interaction
(route, params=None, request_type='post', auth='netrc', timeout=(3.05, 300), headers=None, stream=None, datastream=None)[source]¶Bases: brain.api.api.BrainInteraction
Marvins Interaction class, subclassed from Brain
This is the main class to make calls to the Marvin API. Instantaiate the Interaction object with a URL to make the call.
GET requests can be made without passing parameters. POST requests require parameters to be passed.
A successful call results in a HTTP status code of 200. Failures result in some other HTTP status code. Results from the successful call are stored in an sttribute called results, as a dictionary. Any data requested is stored as a key inside results called “data”
Parameters: |
|
---|---|
Returns: | results (dict) – The Response JSON object from the API call. If the API is successful, the json data is extracted from the response and stored in this dictionary. See Marvin API/Web Routes for a description of the contents of results in each route. |
Examples
>>> from marvin import config
>>> config.mode = 'remote'
>>>
>>> # import the Marvin Interaction class
>>> from marvin.api.api import Interaction
>>>
>>> # get and format an API url to retrieve basic Cube properties
>>> plateifu = '7443-12701'
>>> url = config.urlmap['api']['getCube']['url']
>>>
>>> # create and send the request, and retrieve a response
>>> response = Interaction(url.format(name=plateifu))
>>>
>>> # check your response's status code
>>> print(response.status_code)
>>> 200
>>>
>>> # get the data in your response
>>> data = response.getData()
>>> print(data)