Skip to content

Commit c601a61

Browse files
committed
Bump version to 1.5.0.
* Use custom user agent for requests to Box. * Add LoggingClient and DevelopmentClient classes.
1 parent 8f89ae5 commit c601a61

File tree

17 files changed

+236
-47
lines changed

17 files changed

+236
-47
lines changed

HISTORY.rst

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

9+
10+
1.5.0 (2016-02-26)
11+
++++++++++++++++++
12+
13+
- Added a new class, ``LoggingClient``. It's a ``Client`` that uses the ``LoggingNetwork`` class so that
14+
requests to the Box API and its responses are logged.
15+
- Added a new class, ``DevelopmentClient`` that combines ``LoggingClient`` with the existing
16+
``DeveloperTokenClient``. This client is ideal for exploring the Box API or for use when developing your application.
17+
- Made the ``oauth`` parameter to ``Client`` optional. The constructor now accepts new parameters that it will use
18+
to construct the ``OAuth2`` instance it needs to auth with the Box API.
19+
- Changed the default User Agent string sent with requests to the Box API. It is now 'box-python-sdk-<version>'.
20+
21+
22+
923
1.4.2 (2016-02-23)
1024
++++++++++++++++++
1125

README.rst

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,18 +349,47 @@ For advanced uses of the SDK, two additional auth classes are provided:
349349
multiple machines) to share access tokens while synchronizing token refresh. This could be useful for a multiprocess
350350
web server, for example.
351351

352-
Other Network Options
353-
---------------------
352+
Other Client Options
353+
--------------------
354+
355+
Logging Client
356+
~~~~~~~~~~~~~~
354357

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

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

365394
Contributing
366395
------------

boxsdk/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
from __future__ import unicode_literals
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 .config import Version
9+
__version__ = Version.VERSION

boxsdk/client/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 .logging_client import LoggingClient
8+
9+
10+
class DevelopmentClient(DeveloperTokenClient, LoggingClient):
11+
"""
12+
Client subclass that uses developer token auth and logs requests and responses.
13+
Great for use in development!
14+
"""
15+
pass

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

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,33 @@
33
from __future__ import unicode_literals
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 ..auth import OAuth2
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
1919

2020

2121
class Client(object):
2222

23-
def __init__(self, oauth, network_layer=None, session=None):
23+
def __init__(
24+
self,
25+
oauth=None,
26+
network_layer=None,
27+
session=None,
28+
client_id=None,
29+
client_secret=None,
30+
store_tokens=None,
31+
**kwargs
32+
):
2433
"""
2534
:param oauth:
2635
OAuth2 object used by the session to authorize requests.
@@ -34,12 +43,37 @@ def __init__(self, oauth, network_layer=None, session=None):
3443
The session object to use. If None is provided then an instance of :class:`BoxSession` will be used.
3544
:type session:
3645
:class:`BoxSession`
46+
:param client_id:
47+
Box API key used for identifying the application the user is authenticating with.
48+
Ignored if oauth instance is passed into this constructor.
49+
:type client_id:
50+
`unicode`
51+
:param client_secret:
52+
Box API secret used for making OAuth2 requests.
53+
Ignored if oauth instance is passed into this constructor.
54+
:type client_secret:
55+
`unicode`
56+
:param store_tokens:
57+
Optional callback for getting access to tokens for storing them.
58+
Ignored if oauth instance is passed into this constructor.
59+
:type store_tokens:
60+
`callable`
3761
"""
3862
network_layer = network_layer or DefaultNetwork()
39-
self._oauth = oauth
63+
self._oauth = oauth or OAuth2(client_id, client_secret, store_tokens=store_tokens, **kwargs)
4064
self._network = network_layer
4165
self._session = session or BoxSession(oauth=oauth, network_layer=network_layer)
4266

67+
@property
68+
def auth(self):
69+
"""
70+
Get the :class:`OAuth2` instance the client is using for auth to Box.
71+
72+
:rtype:
73+
:class:`OAuth2`
74+
"""
75+
return self._oauth
76+
4377
def folder(self, folder_id):
4478
"""
4579
Initialize a :class:`Folder` object, whose box id is folder_id.
@@ -359,11 +393,3 @@ def with_shared_link(self, shared_link, shared_link_password):
359393
self._network,
360394
self._session.with_shared_link(shared_link, shared_link_password),
361395
)
362-
363-
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)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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, **kwargs):
14+
super(DeveloperTokenClient, self).__init__(
15+
oauth=oauth or DeveloperTokenAuth(),
16+
network_layer=network_layer,
17+
session=session,
18+
**kwargs
19+
)

boxsdk/client/logging_client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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, **kwargs):
14+
super(LoggingClient, self).__init__(
15+
oauth,
16+
network_layer=network_layer or LoggingNetwork(),
17+
session=session,
18+
**kwargs
19+
)

boxsdk/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ class API(object):
99
UPLOAD_URL = 'https://upload.box.com/api/2.0'
1010
OAUTH2_API_URL = 'https://api.box.com/oauth2' # <https://developers.box.com/docs/#oauth-2>
1111
OAUTH2_AUTHORIZE_URL = 'https://app.box.com/api/oauth2/authorize' # <https://developers.box.com/docs/#oauth-2-authorize>
12+
13+
14+
class Version(object):
15+
"""Configuration object containing the package version and user agent string."""
16+
VERSION = '1.4.3'
17+
USER_AGENT_STRING = 'box-python-sdk-{0}'.format(VERSION)

boxsdk/session/box_session.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import unicode_literals
44

5+
from boxsdk.config import Version
56
from boxsdk.exception import BoxAPIException
67
from boxsdk.util.multipart_stream import MultipartStream
78
from boxsdk.util.shared_link import get_shared_link_header
@@ -81,7 +82,7 @@ def __init__(self, oauth, network_layer, default_headers=None):
8182
"""
8283
self._oauth = oauth
8384
self._network_layer = network_layer
84-
self._default_headers = default_headers or {}
85+
self._default_headers = default_headers or {'User-Agent': Version.USER_AGENT_STRING}
8586

8687
def as_user(self, user):
8788
"""

docs/source/boxsdk.client.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
boxsdk.client package
2+
=====================
3+
4+
Submodules
5+
----------
6+
7+
boxsdk.client.client module
8+
---------------------------
9+
10+
.. automodule:: boxsdk.client.client
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
boxsdk.client.developer_token_client module
16+
-------------------------------------------
17+
18+
.. automodule:: boxsdk.client.developer_token_client
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
22+
23+
boxsdk.client.logging_client module
24+
-----------------------------------
25+
26+
.. automodule:: boxsdk.client.logging_client
27+
:members:
28+
:undoc-members:
29+
:show-inheritance:
30+
31+
32+
Module contents
33+
---------------
34+
35+
.. automodule:: boxsdk.client
36+
:members:
37+
:undoc-members:
38+
:show-inheritance:

0 commit comments

Comments
 (0)