Skip to content

Commit e61f617

Browse files
committed
Merge branch 'master' into packaging-and-distribution
2 parents 0d66b41 + 5a72def commit e61f617

19 files changed

+662
-396
lines changed

README.md

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,72 @@
22
Simple, lightweight and scalable Python API wrapper for the Cisco Spark APIs
33

44
## Overview
5-
A single Pythonic wrapper class representing the Cisco Spark API interfaces and returned JSON objects as method calls that return native Python objects.
5+
Provides single Pythonic wrapper class that represents the Cisco Spark API interfaces and returned JSON objects as native Python objects.
66

7-
* Leverages generator containers and RFC5988 web linking to provide simple and efficient 'paging' of Cisco Spark data objects returned by the Cisco Spark clout.
7+
* Supports Python versions 2 and 3.
8+
9+
* Leverages generator containers and RFC5988 web linking to provide simple and efficient 'paging' of Cisco Spark data objects returned by the Cisco Spark cloud.
810

911
* All Cisco Spark JSON objects and attributes are represented as native python objects.
1012
* As new Cisco Spark attributes are added and returned by the Spark cloud service, they will be automatically available in the respective Python objects - no library update required.
1113
* New object types can be quickly created and modeled by via the generic SparkData class, or you can easily subclass SparkData to provide additional functionality.
1214

13-
* The CiscoSparkAPI class facilitates the creation of simple 'connection objects' that are associated with the access_token used to create the object. All API calls are wrapped by this single class, and are available via a simple hierarchical structure - like api.rooms.list().
14-
* API defaults are provided to make getting connected simple, and can be easily overridden if needed.
15-
* The only setting required to get connected is your Cisco Spark Access Token (see [developer.ciscospark.com](https://developer.ciscospark.com/getting-started.html)).
15+
* The CiscoSparkAPI class facilitates the creation of simple 'connection objects.' All API calls are wrapped by this single class, and are available via a simple hierarchical structure - like CiscoSparkAPI.rooms.list().
16+
* Argument defaults are provided to make getting connected simple, and can be easily overridden if needed.
17+
* The only setting required to get connected is your Cisco Spark Access Token (see [developer.ciscospark.com](https://developer.ciscospark.com/getting-started.html)). When creating a new CiscoSparkAPI object, you may provide your access token one of two ways:
18+
1. By setting a SPARK_ACCESS_TOKEN environment variable.
19+
2. Via the ```CiscoSparkAPI(access_token="")``` argument.
1620
* All API calls are provided as simple method calls on the API connection objects.
1721

18-
### Examples
22+
23+
## Installation
24+
ciscosparkapi is available on PyPI. Install it via PIP, or alternatively you can download the package from GitHub and install it via setuptools.
25+
26+
**PIP Installation**
27+
```
28+
$ pip install ciscosparkapi
29+
```
30+
31+
**git / setuptools Installation**
32+
```
33+
$ git clone https://github.com/CiscoDevNet/ciscosparkapi.git
34+
$ python setup.py install
35+
```
36+
37+
## Examples
1938

2039
```python
2140
from ciscosparkapi import CiscoSparkAPI
2241

23-
access_token = "abcdefg..."
24-
api = CiscoSparkAPI(access_token)
42+
43+
# By default retrieves your access token from the SPARK_ACCESS_TOKEN environement variable
44+
api = CiscoSparkAPI()
45+
2546

2647
rooms = api.rooms.list() # Returns an generator container providing support for RFC5988 paging
2748
for room in rooms: # Efficiently iterates through returned objects
2849
print room.title # JSON objects are represented as native Python objects
2950

51+
3052
# Creating a list from the returned generator containers is easy
31-
team_list = list(api.teams.list())
32-
print team_list
53+
teams = api.teams.list()
54+
team_list = list(teams)
55+
print teams_list
3356
```
3457

3558

36-
## Community Development Project Information
37-
This is a collaborative community development project to create two packages to be published to the Python Package Index:
59+
## Current Status
60+
**Beta(s) Released!**
3861

39-
1. [**ciscosparkapi**](https://github.com/CiscoDevNet/ciscosparkapi) - A simple, scalable and lightweight API wrapper for the Cisco Spark services APIs
40-
2. [**ciscosparksdk**](https://github.com/CiscoDevNet/ciscosparksdk) - Additional features and functionality useful to Cisco Spark API developers
62+
Please check the [releases page](https://github.com/CiscoDevNet/ciscosparkapi/releases) for details on the latest releases.
4163

42-
All are welcome to contribute to this project. Information on contributing this project can be found [here in the project Charter](https://github.com/CiscoDevNet/spark-python-packages-team/blob/master/Charter.md).
64+
We have released the first beta distributions for this package! Please test out the package for your use cases, and raise [issues](https://github.com/CiscoDevNet/ciscosparkapi/issues) for any problems you encounter. Also, **PLEASE** create new [issues](https://github.com/CiscoDevNet/ciscosparkapi/issues) to provide any feedback on the package API structure (names, method calls and etc.). The package APIs are still subject to change, and we would like to get these nailed down before we release v1 for the package.
4365

44-
## Current Status
45-
**Wrappers for all Cisco API endpoints and data objects have now been completed!**
4666

67+
## Community Development Project Information
68+
This is a collaborative community development project working to create two packages to be published to the Python Package Index:
69+
70+
1. [**ciscosparkapi**](https://github.com/CiscoDevNet/ciscosparkapi) - Simple, lightweight and scalable Python API wrapper for the Cisco Spark APIs
71+
2. [**ciscosparksdk**](https://github.com/CiscoDevNet/ciscosparksdk) - Additional features and functionality useful to developers building on Cisco Spark API
4772

48-
_Beta release imminent._
49-
We are preparing to release the first _beta_ for this package. Please test out the package for your use cases, and raise issues for any problems you encounter. Also, **PLEASE** create new issues to provide feedback and foster discussion on the package API structure (names, method calls and etc.). The package APIs are still subject to change, and I would like to get these nailed down before we release v1 for the package.
73+
Contributions and feedback are welcome. Information on contributing this project can be found [here in the project Charter](https://github.com/CiscoDevNet/spark-python-packages-team/blob/master/Charter.md).

ciscosparkapi/__init__.py

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,91 @@
1+
# -*- coding: utf-8 -*-
2+
"""Python API wrapper for the Cisco Spark APIs."""
3+
4+
5+
from __future__ import absolute_import
6+
from builtins import object
7+
from six import string_types
8+
9+
import os
10+
11+
from .exceptions import ciscosparkapiException, SparkApiError
12+
from .restsession import RestSession
13+
from .api.accesstokens import AccessToken, AccessTokensAPI
14+
from .api.people import Person, PeopleAPI
15+
from .api.rooms import Room, RoomsAPI
16+
from .api.memberships import Membership, MembershipsAPI
17+
from .api.messages import Message, MessagesAPI
18+
from .api.teams import Team, TeamsAPI
19+
from .api.teammemberships import TeamMembership, TeamMembershipsAPI
20+
from .api.webhooks import Webhook, WebhooksAPI
21+
22+
123
# Versioneer version control
224
from ._version import get_versions
325
__version__ = get_versions()['version']
426
del get_versions
527

6-
from exceptions import ciscosparkapiException, SparkApiError
7-
from restsession import RestSession
8-
from api.accesstokens import AccessToken, AccessTokensAPI
9-
from api.people import Person, PeopleAPI
10-
from api.rooms import Room, RoomsAPI
11-
from api.memberships import Membership, MembershipsAPI
12-
from api.messages import Message, MessagesAPI
13-
from api.teams import Team, TeamsAPI
14-
from api.teammemberships import TeamMembership, TeamMembershipsAPI
15-
from api.webhooks import Webhook, WebhooksAPI
1628

17-
18-
# Default base URL
1929
DEFAULT_BASE_URL = 'https://api.ciscospark.com/v1/'
2030

2131

2232
class CiscoSparkAPI(object):
2333
"""Cisco Spark API wrapper class."""
2434

25-
def __init__(self, access_token, base_url=DEFAULT_BASE_URL, timeout=None):
35+
def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
36+
timeout=60):
37+
"""Init a new CiscoSparkAPI object.
38+
39+
An access token must be used when interacting with the Cisco Spark API.
40+
This package supports two methods for you to provide that access token:
41+
42+
1. You may manually specify the access token via the access_token
43+
argument, when creating a new CiscoSparkAPI object.
44+
45+
2. If an access_token argument is not supplied, the package checks
46+
for a SPARK_ACCESS_TOKEN environment variable, and if available,
47+
it uses the value of this environment variable as the access_token
48+
when new CiscoSparkAPI objects are created.
49+
50+
A ciscosparkapiException is raised if an access token is not provided
51+
via one of these two methods.
52+
53+
Args:
54+
access_token(string_types): The access token to be used for API
55+
calls to the Cisco Spark service. Defaults to checking for a
56+
SPARK_ACCESS_TOKEN environment variable.
57+
base_url(string_types): The base URL to be prefixed to the
58+
individual API endpoint suffixes.
59+
Defaults to ciscosparkapi.DEFAULT_BASE_URL.
60+
timeout(int): Timeout (in seconds) for RESTful HTTP requests.
61+
Defaults to 60 seconds.
62+
63+
Returns:
64+
CiscoSparkAPI: A new CiscoSparkAPI connection object.
65+
66+
Raises:
67+
AssertionError: If the parameter types are incorrect.
68+
ciscosparkapiException: If an access token is not provided via the
69+
access_token argument or SPARK_ACCESS_TOKEN environment
70+
variable.
71+
72+
"""
2673
# Process args
27-
assert isinstance(access_token, basestring)
28-
# Process kwargs
29-
session_args = {}
30-
if timeout:
31-
session_args['timeout'] = timeout
74+
assert access_token is None or isinstance(access_token, string_types)
75+
assert isinstance(base_url, string_types)
76+
assert isinstance(timeout, int)
77+
spark_access_token = os.environ.get('SPARK_ACCESS_TOKEN', None)
78+
access_token = access_token if access_token else spark_access_token
79+
if not access_token:
80+
error_message = "You must provide an access token to interact " \
81+
"with the Cisco Spark APIs, either via the " \
82+
"access_token argument or via a " \
83+
"SPARK_ACCESS_TOKEN environment variable. " \
84+
"None provided."
85+
raise ciscosparkapiException(error_message)
86+
session_args = {u'timeout': timeout}
3287

33-
# Create API session
88+
# Create the API session
3489
# All of the API calls associated with a CiscoSparkAPI object will
3590
# leverage a single RESTful 'session' connecting to the Cisco Spark
3691
# cloud.

ciscosparkapi/_version.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12

23
# This file helps to compute a version number in source trees obtained from
34
# git-archive tarball (such as those provided by githubs download-from-tag
@@ -9,6 +10,9 @@
910
# versioneer-0.16 (https://github.com/warner/python-versioneer)
1011

1112
"""Git implementation of _version.py."""
13+
from __future__ import print_function
14+
from builtins import str
15+
from builtins import object
1216

1317
import errno
1418
import os
@@ -29,7 +33,7 @@ def get_keywords():
2933
return keywords
3034

3135

32-
class VersioneerConfig:
36+
class VersioneerConfig(object):
3337
"""Container for Versioneer configuration parameters."""
3438

3539

0 commit comments

Comments
 (0)