项目作者: phistrom

项目描述 :
A Python API for Basecamp 3
高级语言: Python
项目地址: git://github.com/phistrom/basecampy3.git
创建时间: 2018-04-18T00:31:56Z
项目社区:https://github.com/phistrom/basecampy3

开源协议:MIT License

下载


BasecamPY3

An easy-to-use Python interface to
the Basecamp 3 API.

BasecamPY3 will drop Python 2.7 and 3.5 support in the 1.0.0 release.

Features

  • Easy, AWS CLI-like configuration and installation
  • Object-oriented API
  • Handles rate-limiting, caching, and authentication for you!

Install

  1. pip install basecampy3
  2. bc3 configure

Follow the prompts to obtain an access and refresh token which is then saved
to ~/.config/basecamp.conf, allowing you to call Basecamp3() without any
parameters. You will need to make your own
Basecamp 3 app integration
first.

Storing in environment variables

Once you have the credentials you can store them in environment variables:

  • BASECAMP_CLIENT_ID
  • BASECAMP_CLIENT_SECRET
  • BASECAMP_REDIRECT_URL
  • BASECAMP_ACCESS_TOKEN
  • BASECAMP_REFRESH_TOKEN

This will allow for easier deploys using CI, initializing with:

  1. from basecampy3 import Basecamp3
  2. bc3 = Basecamp3.from_environment()

Usage

Basic Example

  1. from basecampy3 import Basecamp3
  2. bc3 = Basecamp3()
  3. for project in bc3.projects.list():
  4. print(project.name)
  5. new_project = bc3.projects.create("My New Project",
  6. description="The best project ever made.")
  7. new_project.campfire.post_message("Hello World!")
  8. new_message = new_project.message_board.post_message("Check this out",
  9. content="This is a new message thread start.")
  10. new_message.archive()
  11. todolist = new_project.todoset.create("Things to be done")
  12. todolist.create("Get Milk")
  13. todolist.create("Get Eggs")
  14. go_to_bed = todolist.create("Go to bed.")
  15. go_to_bed.check() # this is marked as done

Not all functionality of the API is available yet. For anything missing, you
can use the requests Session object yourself directly and
consult the Basecamp 3 API docs. The benefit of using this Session object
is you will benefit from the authentication, rate-limiting, and caching
features.

The full API is implemented in the basecampy3.urls package, however. The
Basecamp3 object now has a urls object that implements a 1:1 mapping
with the Basecamp 3 API. Using this urls object, you can create the URL
you need to get the information you want, and then call .request() on it to
receive a Response object, from which you can use .json() to get the
data you are looking for.

Direct Session Example

  1. from basecampy3 import Basecamp3
  2. import json
  3. bc3 = Basecamp3()
  4. # replace these with actual IDs of the Basecamp objects you wish to get
  5. recording_id = 123456789
  6. project_id = 1234567
  7. # Reference:
  8. # https://github.com/basecamp/bc3-api/blob/master/sections/comments.md#get-comments
  9. url = bc3.urls.comments.list_by_recording(project=project_id,
  10. recording=recording_id)
  11. response = url.request(bc3.session)
  12. if not response.ok:
  13. print("Something went wrong. %s: %s" % (
  14. response.status_code, response.text))
  15. exit(1)
  16. data = response.json()
  17. pretty_print = json.dumps(data, indent=4)
  18. print(pretty_print)

CLI Example

COMING SOON!
Command Line interface for doing stuff with Basecamp.
(not working yet)

  1. $ bc3 copy-access 12341234 87658765 # give user 87658765 access to all the projects that 12341234 does

Todo

  • The rest of the Basecamp 3 API
  • Command line tool (beyond just the “configure” command)
  • Better testing coverage