Coder Social home page Coder Social logo

mk-fg / txboxdotnet Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 263 KB

Twisted-based python async interface for Box (box.net) API v2.0

License: Do What The F*ck You Want To Public License

Python 100.00%
python twisted box-api api-wrapper deprecated

txboxdotnet's Introduction

txboxdotnet

Twisted-based python async interface for Box (box.net) API (version 2.0).

Usage Example

Following script will print listing of the root box.net folder, upload "test.txt" file there, try to find it in updated folder listing and then remove it.

from twisted.internet import defer, reactor
from txboxdotnet.api_v2 import txBoxAPI

api = txBoxAPI(
	client_id='...',
	client_secret='...', ... )

if not api.auth_code:
	print '\n'.join([
		'Visit the following URL in any web browser (firefox, chrome, safari, etc),',
			'  authorize there, confirm access permissions, and paste URL of an empty page',
			'  (starting with "https://success.box.com/") you will get',
			'  redirected to into "auth_code" value in "config" dict above.\n',
		'URL to visit:\n  {}'.format(api.auth_user_get_url()) ])
	exit()

if re.search(r'^https?://', api.auth_code):
	api.auth_user_process_url(api.auth_code)

@defer.inlineCallbacks
def do_stuff():

	# Print root directory listing
	print list(e['name'] for e in (yield api.listdir()))

	# Upload "test.txt" file from local current directory
	file_info = yield api.put('test.txt')

	# Find just-uploaded "test.txt" file by name
	file_id = yield api.resolve_path('test.txt')

	# Check that id matches uploaded file
	assert file_info['id'] == file_id

	# Remove the file
	yield api.delete(file_id)

do_stuff().addBoth(lambda ignored: reactor.stop())
reactor.run()

Note that parameters passed to txBoxAPI class init above should contain authentication data, which can/should be derived from "client_id" and "client_secret", provided after app registration on box.net.

Service (at least now) has quite annoying requirement that the "auth_code" it will provide after authorizing API access request is only valid for 30 seconds. See API auth docs for more info on the process.

For more complete example (including oauth2 stuff), see api_v2.py code after if __name__ == '__main__': (will need better examples in the future, patches welcome!).

Installation

It's a regular package for Python 2.7 (not 3.X).

Using pip is the best way:

% pip install txboxdotnet

If you don't have it, use:

% easy_install pip
% pip install txboxdotnet

Alternatively (see also):

% curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
% pip install txboxdotnet

Or, if you absolutely must:

% easy_install txboxdotnet

But, you really shouldn't do that.

Current-git version can be installed like this:

% pip install 'git+https://github.com/mk-fg/txboxdotnet.git#egg=txboxdotnet'

Note that to install stuff in system-wide PATH and site-packages, elevated privileges are often required. Use "install --user", ~/.pydistutils.cfg or virtualenv to do unprivileged installs into custom paths.

Requirements

Implemented methods

Matrix of implemented API method wrappers (same order as in the docs):

  • folders

    • list: listdir
    • create: mkdir
    • get info: info_folder
    • copy
    • delete: delete_folder
    • update info
    • create shared link
    • view discussions
    • view collaborations
    • list from trash
    • info from trash
    • restore from trash
    • delete permanently
  • files

    • upload: put
    • download: get
    • get info: info_file
    • upload overwrite: put
    • upload rename
    • view versions
    • update info
    • delete: delete_file
    • copy
    • create shared link
    • view comments
    • get thumbnail
    • get from trash
    • restore from trash
    • delete permanently
  • comments

  • discussions

  • collaborations

  • users

    • current user info: info_user
    • all the rest ;)
  • search

  • shared items

  • events

Note that these wrappers tend to be very thin, just taking python method arguments and translating these into appropriate API keys, typically looking somewhat like this:

def info_file(self, file_id):
  return self(join('files', file_id))

Any missing methods can also be replaced by calling api object in the same way as above, passing all the appropriate (as per docs) parameters.

My purposes are quite narrow - I use service only for file storage - so missing sharing/collaboration wrappers are unlikely to be implemented here without patches from someone interested in having these.

txboxdotnet's People

Contributors

mk-fg avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

txboxdotnet's Issues

Cannot import name txBoxAPI

I installed the module using pip install but It's not working

from txboxdotnet import txBoxAPI
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name txBoxAPI

Restart the reactor

Do you have any idea how to stop and restart the reactor?

after reactor.stop() I can not call again reactor.run()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.