Skip to content

Commit

Permalink
Beginnings of the library.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paddy Foran committed Apr 16, 2012
0 parents commit 877e568
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 0 deletions.
8 changes: 8 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,8 @@
Copyright (c) 2012, Iron.io, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -0,0 +1 @@
include LICENSE.txt
29 changes: 29 additions & 0 deletions README.md
@@ -0,0 +1,29 @@
# iron_rest_python

iron_rest_python is a collection of common functions for working with the RESTful APIs
that we build at [Iron.io](http://www.iron.io) from Python.

## It Is

* Service-agnostic
* Pip- and easy_install-installable
* Well documented

## It Is Not

* An API wrapper. Those are specific to each service, and you can generally find them
by checking the documentation for the service.
* A place for service-specific code. This is only meant to handle the basic, RESTful
interaction.

## Installation

You can use [pip](http://pip-installer.org) or [easy_install](http://wiki.python.org/moin/EasyInstall)
to install the [release version](http://pypi.python.org/pypi/iron_rest_python). If you'd
like to work with a development or beta version, retrieve the files [from Github](https://github.com/iron-io/iron_rest_python)
and run `python setup.py install` from the root directory.

## License

This software is released under the BSD 2-Clause License. You can find the full text of
this license under LICENSE.txt in the module's root directory.
127 changes: 127 additions & 0 deletions iron_cache.py
@@ -0,0 +1,127 @@
from iron_rest import *
import ConfigParser

class IronCache:
def __init__(self, project_id=None, token=None, protocol='https',
host='cache-aws-us-east-1.iron.io', port=443, version=1,
config=None):
"""Prepare a configured instance of the API wrapper and return it.
Keyword arguments:
project_id -- The ID for the project, found on http://hud.iron.io.
Defaults to None. project_id or config must be set
(with a project_id value in the config file) or a
ValueError will be raised.
token -- The OAuth2 token that grants access to the project specified
by project_id or in the config file. Found on
http://hud.iron.io. Defaults to None. token or config must
be set (with a token value in the config file) or a ValueError
will be raised.
protocol -- The protocol to use for requests. Defaults to 'https'.
Overrides the protocol specified in the config file, if
config is set.
host -- The hostname of the API server. Defaults to
'cache-aws-us-east-1.iron.io'. Overrides the host specified in
the config file, if config is set.
port -- The port to connect to the API server on. Defaults to 443.
Overrides the port specified in the config file, if config is
set.
version -- The version of the API to use. Defaults to 1. Overrides the
version specified in the config file, if config is set.
config -- The path to the config file to use when configuring the
client. Should be a valid .ini file. Defaults to None. If
None, both token and project_id must be set, or a ValueError
will be thrown.
"""
self.token = None
self.version = None
self.project_id = None
self.protocol = None
self.host = None
self.port = None
self.config = None
self.client = None

if config is not None:
config_file = ConfigParser.RawConfigParser()
config_file.read(config)
try:
self.token = config_file.get("iron_cache", "token")
except ConfigParser.NoOptionError:
pass
try:
self.project_id = config_file.get("iron_cache", "project_id")
except ConfigParser.NoOptionError:
pass
try:
self.version = config_file.get("iron_cache", "version")
except ConfigParser.NoOptionError:
pass
try:
self.protocol = config_file.get("iron_cache", "protocol")
except ConfigParser.NoOptionError:
pass
try:
self.host = config_file.get("iron_cache", "host")
except ConfigParser.NoOptionError:
pass
try:
self.port = config_file.get("iron_cache", "port")
except ConfigParser.NoOptionError:
pass

if token is not None:
self.token = token
if project_id is not None:
self.project_id = project_id
if protocol is not None:
self.protocol = protocol
if host is not None:
self.host = host
if port is not None:
self.port = port
if version is not None:
self.version = version

if self.token is None:
raise ValueError("No token provided.")
if self.project_id is None:
raise ValueError("No project_id provided.")
if self.protocol is None:
raise ValueError("No protocol specified.")
if self.host is None:
raise ValueError("No host specified.")
if self.port is None:
raise ValueError("No port specified.")
if self.version is None:
raise ValueError("No API version specified.")

self.client = IronClient(name="iron_cache_python", version="0.1.0",
host=self.host, project_id=self.project_id, token=self.token,
protocol=self.protocol, port=self.port,
api_version=self.version)

def listCaches(self, options={}):
"""Query the server for a list of caches, parse the JSON response, and
return the result.
Keyword arguments:
options -- a dict of arguments to send with the request. See
http://dev.iron.io/cache/reference/api/#list_caches for more
information on defaults and possible values.
"""

return self.client.get("caches")

def getCache(self, cache, options={}):
"""Query the server for info on a specific cache, parse the JSON, and
return the result.
Keyword arguments:
cache -- the name of the cache to be retrieved. Required.
options -- a dict of arguments to send with the request. See
http://dev.iron.io/cache/reference/api/#get_cache for more
information on defaults and possible values.
"""

return self.client.get("caches/%s" % cache)
36 changes: 36 additions & 0 deletions setup.py
@@ -0,0 +1,36 @@
from distutils.core import setup

setup(
name = "IronCache",
py_modules = ["iron_cache"],
install_requires = ["iron_rest"],
version = "0.1.0",
description = "Client library for IronCache, the cache-in-the-cloud provided by Iron.io.",
author = "Iron.io",
author_email = "thirdparty@iron.io",
url = "https://www.github.com/iron-io/iron_cache_python",
keywords = ["Iron.io", "cache", "iron_cache"],
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Development Status :: 2 - Pre-Alpha",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Topic :: Internet",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development :: Libraries :: Python Modules",
],
long_description = """\
IronCache client library
------------------------
This package wraps the IronCache API. It provides a simple and intuitive
way to interact with the IronCache service.
IronCache is a service provided by Iron.io. It is a temporary key/value
storage mechanism built on cloud providers. It provides a cache that
is reliable and scales based on demand, without requiring developers to
provision servers themselves."""
)

0 comments on commit 877e568

Please sign in to comment.