8000 Allow users to set their own user-agent. · doismellburning/github3.py@3219660 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3219660

Browse files
committed
Allow users to set their own user-agent.
github/developer.github.com@0f7a142
1 parent df92991 commit 3219660

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

github3/github.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,13 @@ def search_email(self, email):
993993
u = json.get('user', {})
994994
return LegacyUser(u, self) if u else None
995995

996+
def set_user_agent(self, user_agent):
997+
"""Allows the user to set their own user agent string to identify with
998+
the API."""
999+
if not user_agent:
1000+
return
1001+
self._session.config['base_headers']['User-Agent'] = user_agent
1002+
9961003
def star(self, login, repo):
9971004
"""Star to login/repo
9981005

github3/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self, json, ses=None):
6767
self._session.headers.update({'Accept-Charset': 'utf-8'})
6868
# Identify who we are
6969
self._session.config['base_headers'].update(
70-
{'User-Agent': 'github3.py/pre-alpha'})
70+
{'User-Agent': 'github3.py/0.1b0'})
7171

7272
# set a sane default
7373
self._github_url = 'https://api.github.com'

tests/test_github.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,11 @@ def test_subscribe_unsub(self):
444444
expect(self._g.subscribe(*args)).isinstance(bool)
445445
expect(self._g.unsubscribe(*args)).isinstance(bool)
446446

447+
def test_set_user_agent(self):
448+
ua = 'Foo Bar Bogus'
449+
self.g.set_user_agent(ua)
450+
expect(self.g._session.config['base_headers']['User-Agent']) == ua
451+
447452
def test_star_unstar(self):
448453
args = (self.gh3py, self.test_repo)
449454
self.raisesGHE(self.g.star, *args)

0 commit comments

Comments
 (0)
0