Skip to content

Commit abe87b8

Browse files
committed
Improve docs.
1 parent f816ffc commit abe87b8

File tree

6 files changed

+145
-13
lines changed

6 files changed

+145
-13
lines changed

README.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,20 +262,18 @@ supported by the SDK. You can still use these endpoints by using the ``make_requ
262262
.. code-block:: python
263263
264264
# https://box-content.readme.io/reference#get-metadata-schema
265-
from boxsdk.config import API
266265
# Returns a Python dictionary containing the result of the API request
267266
json_response = client.make_request(
268267
'GET',
269-
'{0}/metadata_templates/enterprise/customer/schema'.format(API.BASE_API_URL),
268+
client.get_url('metadata_templates', 'enterprise', 'customer', 'schema'),
270269
).json()
271270
272271
``make_request()`` takes two parameters:
273272

274273
- ``method`` -an HTTP verb like ``GET`` or ``POST``
275274
- ``url`` - the URL of the requested API endpoint
276275

277-
``boxsdk.config.API`` is an object specifying which URLs to use in order to access the Box API. It can be used for
278-
formatting the URLs to use with ``make_request``. Box objects also have a ``get_url`` method. Pass it an endpoint
276+
The ``Client`` class and Box objects have a ``get_url`` method. Pass it an endpoint
279277
to get the correct URL for use with that object and endpoint.
280278

281279
Box Developer Edition

boxsdk/client/client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from ..object.group_membership import GroupMembership
1717
from ..util.shared_link import get_shared_link_header
1818
from ..util.translator import Translator
19+
from ..util.url import get_url
1920

2021

2122
class Client(object):
@@ -393,3 +394,21 @@ def with_shared_link(self, shared_link, shared_link_password):
393394
self._network,
394395
self._session.with_shared_link(shared_link, shared_link_password),
395396
)
397+
398+
def get_url(self, endpoint, *args):
399+
"""
400+
Return the URL for the given Box API endpoint.
401+
402+
:param endpoint:
403+
The name of the endpoint.
404+
:type endpoint:
405+
`url`
406+
:param args:
407+
Additional parts of the endpoint URL.
408+
:type args:
409+
`Iterable`
410+
:rtype:
411+
`unicode`
412+
"""
413+
# pylint:disable=no-self-use
414+
return get_url(endpoint, *args)

boxsdk/object/base_endpoint.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# coding: utf-8
22

33
from __future__ import unicode_literals
4-
from boxsdk.config import API
4+
5+
from boxsdk.util.url import get_url
56

67

78
class BaseEndpoint(object):
@@ -33,9 +34,7 @@ def get_url(self, endpoint, *args):
3334
`unicode`
3435
"""
3536
# pylint:disable=no-self-use
36-
url = ['{0}/{1}'.format(API.BASE_API_URL, endpoint)]
37-
url.extend(['/{0}'.format(x) for x in args])
38-
return ''.join(url)
37+
return get_url(endpoint, *args)
3938

4039
def as_user(self, user):
4140
"""

boxsdk/util/url.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# coding: utf-8
2+
3+
from __future__ import unicode_literals, absolute_import
4+
5+
from boxsdk.config import API
6+
7+
8+
def get_url(endpoint, *args):
9+
"""
10+
Return the URL for the given Box API endpoint.
11+
12+
:param endpoint:
13+
The name of the endpoint.
14+
:type endpoint:
15+
`url`
16+
:param args:
17+
Additional parts of the endpoint URL.
18+
:type args:
19+
`Iterable`
20+
:rtype:
21+
`unicode`
22+
"""
23+
url = ['{0}/{1}'.format(API.BASE_API_URL, endpoint)]
24+
url.extend(['/{0}'.format(x) for x in args])
25+
return ''.join(url)

docs/source/boxsdk.util.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ boxsdk.util.translator module
8484
:undoc-members:
8585
:show-inheritance:
8686

87+
boxsdk.util.url module
88+
----------------------
89+
90+
.. automodule:: boxsdk.util.url
91+
:members:
92+
:undoc-members:
93+
:show-inheritance:
94+
8795

8896
Module contents
8997
---------------

docs/source/index.rst

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,98 @@
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
55
6-
Welcome to The Box Python SDK's documentation!
7-
===================================
6+
Box Python SDK
7+
==============
88

9-
Contents:
9+
10+
Installing
11+
----------
12+
13+
.. code-block:: console
14+
15+
pip install boxsdk
16+
17+
18+
Source Code
19+
-----------
20+
21+
https://github.com/box/box-python-sdk
22+
23+
24+
Quickstart
25+
----------
26+
27+
Create a developer token from your app's configuration page (https://app.box.com/developers/services).
28+
29+
You'll be prompted for it on the command line.
30+
31+
.. code-block:: pycon
32+
33+
$ from boxsdk import DevelopmentClient
34+
$ client = DevelopmentClient()
35+
>>> Enter developer token: <enter your developer token>
36+
$ me = client.user().get()
37+
38+
GET https://api.box.com/2.0/users/me {'headers': {u'Authorization': u'Bearer ----KkeV',
39+
u'User-Agent': u'box-python-sdk-1.4.3'},
40+
'params': None}
41+
42+
{"type":"user","id":"----6009","name":"Jeffrey Meadows","login":"[email protected]",...}
43+
44+
$ me.name
45+
>>> Jeffrey Meadows
46+
47+
The ``DevelopmentClient`` uses Box developer tokens for auth (and will prompt you for a new token upon
48+
expiration), and logs API requests and responses, making it really easy to get started learning the SDK and Box API.
49+
50+
51+
Creating an App for Users
52+
-------------------------
53+
54+
Authorization
55+
~~~~~~~~~~~~~
56+
57+
If you'd like other users to use your app, you need to set up a way for them to authorize your app and
58+
grant it access to their Box account. The ``auth`` module contains several classes to help you do that.
59+
60+
The simplest class is the ``OAuth2`` class. To use it, instantiate it with your ``client_id`` and ``client_secret``.
61+
62+
Follow the `tutorial on GitHub <https://github.com/box/box-python-sdk/blob/master/README.rst#id2>`_ for
63+
instructions on how to get an authorized client for a user. Using the ``store_tokens`` callback, you may persist
64+
the user's auth and refresh tokens for the next time they use your app. Once they return to your app, you can
65+
create an authorized client like so:
66+
67+
.. code-block:: python
68+
69+
from boxsdk import OAuth2, Client
70+
71+
oauth = OAuth2(
72+
client_id='YOUR_CLIENT_ID',
73+
client_secret='YOUR_CLIENT_SECRET',
74+
store_tokens=your_store_tokens_callback_method,
75+
access_token=persisted_access_token,
76+
refresh_token=persisted_refresh_token,
77+
)
78+
client = Client(oauth)
79+
80+
81+
Making requests to Box
82+
~~~~~~~~~~~~~~~~~~~~~~
83+
84+
Once you have an authorized client, you can use it to make requests to Box on your user's behalf. The client
85+
has several methods to help you get started, many of which return Box objects, which, in turn, have methods that
86+
correspond to Box API endpoints.
87+
88+
The module documentation below describes each of these methods and which parameters they require. Some API endpoints
89+
do not have corresponding SDK methods; for those, you can use the generic ``make_request`` method of the client.
90+
91+
Module Documentation
92+
--------------------
1093

1194
.. toctree::
12-
:maxdepth: 4
95+
:maxdepth: 4
1396

14-
boxsdk
97+
boxsdk
1598

1699

17100
Indices and tables

0 commit comments

Comments
 (0)