SmokeAPI Classes and Methods

This portion of the documentation covers all the interfaces of SmokeAPI.

SmokeAPI

class smokeapi.SmokeAPI(key=None, **kwargs)
__init__(key=None, **kwargs)

The object used to interact with the MetaSmoke API

Parameters:
  • key – (string) (Required) A valid API key. An API key can be received by following the current instructions in the API Documentation.
  • token – (string) (Required for write access/Optional is no write routes are called) This is a valid write token retreived by following instructions in the API Documentation. If this is not set, calls to send_data will fail.
  • proxy

    (dict) (optional) A dictionary of http and https proxy locations Example:

    {'http': 'http://example.com',
     'https': 'https://example.com'}
    

    By default, this is None.

  • max_pages – (int) (optional) The maximum number of pages to retrieve (Default: 5)
  • per_page – (int) (optional) The number of elements per page. The API limits this to a maximum of 100 items on all end points (Default: 100)
fetch(endpoint=None, page=1, **kwargs)

Returns the results of an API call.

This is the main work horse of the class. It builds the API query string and sends the request to MetaSmoke. If there are multiple pages of results, and we’ve configured max_pages to be greater than 1, it will automatically paginate through the results and return a single object.

Returned data will appear in the items key of the resulting dictionary.

Parameters:
  • endpoint

    (string) The API end point being called. Available endpoints are listed on the official API Documentation.

    This can be as simple as fetch('posts/feedback'), to call feedback end point

    If calling an end point that takes additional parameter, such as id`s pass the ids as a list to the `ids key:

    fetch('posts/{ids}', ids=[1,2,3])
    

    This will attempt to retrieve the posts for the three listed ids.

    If no end point is passed, a ValueError will be raised

  • page – (int) The page in the results to start at. By default, it will start on the first page and automatically paginate until the result set reaches max_pages.
  • kwargs – Parameters accepted by individual endpoints. These parameters must be named the same as described in the endpoint documentation
Return type:

(dictionary) A dictionary containing wrapper data regarding the API call and the results of the call in the items key. If multiple pages were received, all of the results will appear in the items tag.

send_data(endpoint=None, **kwargs)

Sends data to the API.

This call is similar to fetch, but sends data to the API instead of retrieving it.

Returned data will appear in the items key of the resulting dictionary.

Sending data requires that the token is set.

Parameters:
  • endpoint

    (string) (Required) The API end point being called. Available endpoints are listed on the official API Documentation.

    If no end point is passed, a ValueError will be raised

  • kwargs – Parameters accepted by individual endpoints. These parameters must be named the same as described in the endpoint documentation
Return type:

(dictionary) A dictionary containing wrapper data regarding the API call and the results of the call in the items key. If multiple pages were received, all of the results will appear in the items tag.

SmokeAPIError

class smokeapi.SmokeAPIError(url, code, name, message)

The Exception that is thrown when ever there is an API error.

Parameters:
  • url – (string) The URL that was called and generated an error
  • code – (int) The error_code returned by the API
  • name – (string) The error_name returned by the API and is human friendly
  • message – (string) The error_message returned by the API