Skip to content

Commit 162fc82

Browse files
committed
Merge pull request #121 from Jeff-Meadows/docs
Docs
2 parents 8f89ae5 + dad00ee commit 162fc82

27 files changed

+418
-70
lines changed

AUTHORS.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The Box Python SDK is an open source project supported by `Box <https://box.com>`_
2+
used to interact with the Box API. This is a list of contributors.
3+
4+
- `@Jeff-Meadows <https://github.com/Jeff-Meadows>`_
5+
- `@jmoldow <https://github.com/jmoldow>`_
6+
- `@aptxkid <https://github.com/aptxkid>`_
7+
- `@hnguyen08 <https://github.com/hnguyen08>`_
8+
- `@potrebic <https://github.com/potrebic>`_
9+
- `@nsundareswaran <https://github.com/nsundareswaran>`_

CONTRIBUTING.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ To add an upstream source for this project, type:
5353
5454
git remote add upstream [email protected]:box/box-python-sdk.git
5555
56-
This will come in useful later.
56+
This will become useful later.
5757

5858
Step 4: Create a feature branch
5959
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -103,3 +103,7 @@ a description that lets us know what work you did.
103103
Keep in mind that we like to see one issue addressed per pull request,
104104
as this helps keep our git history clean and we can more easily track
105105
down issues.
106+
107+
Finally, please add a note in HISTORY.rst under the Upcoming section detailing what's new in your change.
108+
These will become the release notes for the next release.
109+
In addition, feel free to add yourself to AUTHORS.rst if you aren't already listed.

HISTORY.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ Release History
66
Upcoming
77
++++++++
88

9+
10+
11+
1.5.0 (2016-03-17)
12+
++++++++++++++++++
13+
14+
- Added a new class, ``LoggingClient``. It's a ``Client`` that uses the ``LoggingNetwork`` class so that
15+
requests to the Box API and its responses are logged.
16+
- Added a new class, ``DevelopmentClient`` that combines ``LoggingClient`` with the existing
17+
``DeveloperTokenClient``. This client is ideal for exploring the Box API or for use when developing your application.
18+
- Made the ``oauth`` parameter to ``Client`` optional. The constructor now accepts new parameters that it will use
19+
to construct the ``OAuth2`` instance it needs to auth with the Box API.
20+
- Changed the default User Agent string sent with requests to the Box API. It is now 'box-python-sdk-<version>'.
21+
- Box objects have an improved ``__repr__``, making them easier to identify during debugging sessions.
22+
- Box objects now implement ``__dir__``, making them easier to explore. When created with a Box API response,
23+
these objects will now include the API response fields as attributes.
24+
25+
26+
927
1.4.2 (2016-02-23)
1028
++++++++++++++++++
1129

README.rst

Lines changed: 37 additions & 9 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
@@ -349,18 +347,48 @@ For advanced uses of the SDK, two additional auth classes are provided:
349347
multiple machines) to share access tokens while synchronizing token refresh. This could be useful for a multiprocess
350348
web server, for example.
351349

352-
Other Network Options
353-
---------------------
350+
Other Client Options
351+
--------------------
352+
353+
Logging Client
354+
~~~~~~~~~~~~~~
354355

355-
For more insight into the network calls the SDK is making, you can use the ``LoggingNetwork`` class. This class logs
356+
For more insight into the network calls the SDK is making, you can use the ``LoggingClient`` class. This class logs
356357
information about network requests and responses made to the Box API.
357358

358-
.. code-block:: python
359+
.. code-block:: pycon
360+
361+
>>> from boxsdk import LoggingClient
362+
>>> client = LoggingClient()
363+
>>> client.user().get()
364+
GET https://api.box.com/2.0/users/me {'headers': {u'Authorization': u'Bearer ---------------------------kBjp',
365+
u'User-Agent': u'box-python-sdk-1.5.0'},
366+
'params': None}
367+
{"type":"user","id":"..","name":"Jeffrey Meadows","login":"..",..}
368+
<boxsdk.object.user.User at 0x10615b8d0>
369+
370+
For more control over how the information is logged, use the ``LoggingNetwork`` class directly.
371+
372+
.. code-block:: pycon
359373
360374
from boxsdk import Client
361375
from boxsdk.network.logging_network import LoggingNetwork
362376
363-
client = Client(oauth, network_layer=LoggingNetwork())
377+
# Use a custom logger
378+
client = Client(oauth, network_layer=LoggingNetwork(logger))
379+
380+
Developer Token Client
381+
~~~~~~~~~~~~~~~~~~~~~~
382+
383+
The Box Developer Console allows for the creation of short-lived developer tokens. The SDK makes it easy to use these
384+
tokens. Use the ``get_new_token_callback`` parameter to control how the client will get new developer tokens as
385+
needed. The default is to prompt standard input for a token.
386+
387+
Development Client
388+
~~~~~~~~~~~~~~~~~~
389+
390+
For exploring the Box API, or to quickly get going using the SDK, the ``DevelopmentClient`` class combines the
391+
``LoggingClient`` with the ``DeveloperTokenClient``.
364392

365393
Contributing
366394
------------

boxsdk/__init__.py

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

3-
from __future__ import unicode_literals
3+
from __future__ import unicode_literals, absolute_import
44

55
from .auth import JWTAuth, OAuth2
6-
from .client import Client, DeveloperTokenClient
6+
from .client import * # pylint:disable=wildcard-import,redefined-builtin
77
from .object import * # pylint:disable=wildcard-import,redefined-builtin
8+
from .version import __version__

boxsdk/client/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# coding: utf-8
2+
3+
from __future__ import unicode_literals, absolute_import
4+
5+
from .client import Client
6+
from .developer_token_client import DeveloperTokenClient
7+
from .development_client import DevelopmentClient
8+
from .logging_client import LoggingClient

boxsdk/client.py renamed to boxsdk/client/client.py

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
# coding: utf-8
22

3-
from __future__ import unicode_literals
3+
from __future__ import unicode_literals, absolute_import
44
import json
55

6-
from .auth import DeveloperTokenAuth
7-
from .config import API
8-
from .session.box_session import BoxSession
9-
from .network.default_network import DefaultNetwork
10-
from .object.user import User
11-
from .object.folder import Folder
12-
from .object.search import Search
13-
from .object.events import Events
14-
from .object.file import File
15-
from .object.group import Group
16-
from .object.group_membership import GroupMembership
17-
from .util.shared_link import get_shared_link_header
18-
from .util.translator import Translator
6+
from ..config import API
7+
from ..session.box_session import BoxSession
8+
from ..network.default_network import DefaultNetwork
9+
from ..object.user import User
10+
from ..object.folder import Folder
11+
from ..object.search import Search
12+
from ..object.events import Events
13+
from ..object.file import File
14+
from ..object.group import Group
15+
from ..object.group_membership import GroupMembership
16+
from ..util.shared_link import get_shared_link_header
17+
from ..util.translator import Translator
1918

2019

2120
class Client(object):
2221

23-
def __init__(self, oauth, network_layer=None, session=None):
22+
def __init__(
23+
self,
24+
oauth=None,
25+
network_layer=None,
26+
session=None,
27+
):
2428
"""
2529
:param oauth:
2630
OAuth2 object used by the session to authorize requests.
@@ -40,6 +44,16 @@ def __init__(self, oauth, network_layer=None, session=None):
4044
self._network = network_layer
4145
self._session = session or BoxSession(oauth=oauth, network_layer=network_layer)
4246

47+
@property
48+
def auth(self):
49+
"""
50+
Get the :class:`OAuth2` instance the client is using for auth to Box.
51+
52+
:rtype:
53+
:class:`OAuth2`
54+
"""
55+
return self._oauth
56+
4357
def folder(self, folder_id):
4458
"""
4559
Initialize a :class:`Folder` object, whose box id is folder_id.
@@ -360,10 +374,20 @@ def with_shared_link(self, shared_link, shared_link_password):
360374
self._session.with_shared_link(shared_link, shared_link_password),
361375
)
362376

377+
def get_url(self, endpoint, *args):
378+
"""
379+
Return the URL for the given Box API endpoint.
363380
364-
class DeveloperTokenClient(Client):
365-
"""
366-
Box client subclass which authorizes with a developer token.
367-
"""
368-
def __init__(self, oauth=None, network_layer=None, session=None):
369-
super(DeveloperTokenClient, self).__init__(oauth or DeveloperTokenAuth(), network_layer, session)
381+
:param endpoint:
382+
The name of the endpoint.
383+
:type endpoint:
384+
`url`
385+
:param args:
386+
Additional parts of the endpoint URL.
387+
:type args:
388+
`Iterable`
389+
:rtype:
390+
`unicode`
391+
"""
392+
# pylint:disable=no-self-use
393+
return self._session.get_url(endpoint, *args)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# coding: utf-8
2+
3+
from __future__ import unicode_literals, absolute_import
4+
5+
from ..auth import DeveloperTokenAuth
6+
from .client import Client
7+
8+
9+
class DeveloperTokenClient(Client):
10+
"""
11+
Box client subclass which authorizes with a developer token.
12+
"""
13+
def __init__(self, oauth=None, network_layer=None, session=None):
14+
super(DeveloperTokenClient, self).__init__(
15+
oauth=oauth or DeveloperTokenAuth(),
16+
network_layer=network_layer,
17+
session=session,
18+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# coding: utf-8
2+
3+
from __future__ import unicode_literals, absolute_import
4+
5+
from .developer_token_client import DeveloperTokenClient
6+
from .logging_client import LoggingClient
7+
8+
9+
class DevelopmentClient(DeveloperTokenClient, LoggingClient):
10+
"""
11+
Client subclass that uses developer token auth and logs requests and responses.
12+
Great for use in development!
13+
"""
14+
pass

boxsdk/client/logging_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# coding: utf-8
2+
3+
from __future__ import unicode_literals, absolute_import
4+
5+
from .client import Client
6+
from ..network.logging_network import LoggingNetwork
7+
8+
9+
class LoggingClient(Client):
10+
"""
11+
Box client subclass which logs requests and responses.
12+
"""
13+
def __init__(self, oauth=None, network_layer=None, session=None):
14+
super(LoggingClient, self).__init__(
15+
oauth=oauth,
16+
network_layer=network_layer or LoggingNetwork(),
17+
session=session,
18+
)

0 commit comments

Comments
 (0)