Source

apollo /

Filename Size Date modified Message
apollo
tests
94 B
2.7 KB
876 B
78 B

Overview

apollo is a wrapper for the apollohq.com API.

This wrapper provides two API clients, one that uses requests and one (in the works) that runs in tornado.

Dependencies

This dependencies depends on the wrapper that you use: the requests wrapper requires... requests. The tornado wrapper requires tornado.

This code is built in and tested on Python 2.7, but 2.6 support is available. Do not submit any bugs or requests for anything below 2.6.

Usage

This wrapper helps with a lot of the cruft code in forming and dealing with the request and its possible errors. There is no Object mapper for the responses, you only get back the raw text and the json object as a python dictionary.

import apollo
from apollo.clients.requestsclient import ApolloRequestsClient
from apollo.response import ApolloResponse

client = ApolloRequestsClient(APIKEY)

r = client.get("projects")
r.status    # ApolloResponse.SUCCESS or ApolloResponse.FAIL
r.rawdata   # string
r.data      # dictionary
r.success   # True or False
r.fail      # True or False
project_id = "1234"

# MAKE TASKLIST
# endpoint created manually (using concatenation)
r = self.apollo.post(
  "projects/" + project_id + "/taskLists",
  data = {
    "task-list": {
      "name": "Test List",
      "description": "This is a test list",
    }
  }
)
tasklist_id = r.data['task-list-id']

# MODIFY TASKLIST
# endpoint created manually (using str.format)
r = self.apollo.put(
  "taskLists/{0}".format(tasklist_id),
  data = {
    "task-list": {
      "name": "Modified Test List",
    }
  }
)

# DELETE TASKLIST
# endpoint created using wrapper builtin helper
r = self.apollo.delete(
  "taskLists/{tasklist_id}",
  tasklist_id = tasklist_id,
)
# UPLOADING A FILE
with open("tests/files/archer.jpg", 'rb') as fh:
  r = self.apollo.upload("archer.jpg", fh)
upload_id = r.data['attachment-id']

# WRITE MSG WITH UPLOAD
r = self.apollo.post(
  "projects/{project_id}/messages",
  project_id = project_id,
  data = {
    "message": {
      "title": "Test Message",
      "body": "Archer is so cute!",
      "attachments": [upload_id,],
    }
  }
)

Running Tests

Create a file called credentials.local that contains only your API key. Then run the test.sh shell script.

The test will create a API_TEST project and do some modifications over the wire. If you already have an API_TEST project, prepare to lose some data.

Contributors