Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes: Fixed request authorization method #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions tests/api/test_api_request_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def test_set_webhook_sanity():
def post_request(endpoint, payload):
request = json.loads(payload)
assert endpoint == BOT_API_ENDPOINT.SET_WEBHOOK
assert request['auth_token'] == VIBER_BOT_CONFIGURATION.auth_token
assert request['event_types'] == webhook_events
assert request['url'] == url
return dict(status=0, event_types=webhook_events)
Expand Down Expand Up @@ -56,7 +55,6 @@ def test_post_request_success(monkeypatch):
def callback(endpoint, data, headers):
request = json.loads(data)
assert endpoint == VIBER_BOT_API_URL + "/" + BOT_API_ENDPOINT.GET_ACCOUNT_INFO
assert request['auth_token'] == VIBER_BOT_CONFIGURATION.auth_token
assert headers['User-Agent'] == VIBER_BOT_USER_AGENT
response = Stub()
response.raise_for_status = stub
Expand Down Expand Up @@ -124,7 +122,7 @@ def test_get_online_success(monkeypatch):
def callback(endpoint, data, headers):
request = json.loads(data)
assert endpoint == VIBER_BOT_API_URL + "/" + BOT_API_ENDPOINT.GET_ONLINE
assert request['auth_token'] == VIBER_BOT_CONFIGURATION.auth_token
assert headers['X-Viber-Auth-Token'] == VIBER_BOT_CONFIGURATION.auth_token
response = Stub()
response.raise_for_status = stub
response.text = "{\"status\": 0, \"status_message\": \"OK\", \"users\": []}"
Expand All @@ -141,7 +139,7 @@ def test_get_user_details_success(monkeypatch):
def callback(endpoint, data, headers):
request = json.loads(data)
assert endpoint == VIBER_BOT_API_URL + "/" + BOT_API_ENDPOINT.GET_USER_DETAILS
assert request['auth_token'] == VIBER_BOT_CONFIGURATION.auth_token
assert headers['X-Viber-Auth-Token'] == VIBER_BOT_CONFIGURATION.auth_token
response = Stub()
response.raise_for_status = stub
response.text = "{\"status\": 0, \"status_message\": \"OK\", \"user\": {}}"
Expand Down
12 changes: 4 additions & 8 deletions viberbot/api/api_request_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def __init__(self, logger, viber_bot_api_url, bot_configuration, viber_bot_user_

def set_webhook(self, url, webhook_events=None, is_inline=False):
payload = {
'auth_token': self._bot_configuration.auth_token,
'url': url,
'is_inline': is_inline
}
Expand All @@ -34,18 +33,17 @@ def set_webhook(self, url, webhook_events=None, is_inline=False):
return result['event_types']

def get_account_info(self):
payload = {
'auth_token': self._bot_configuration.auth_token
}
return self.post_request(
endpoint=BOT_API_ENDPOINT.GET_ACCOUNT_INFO,
payload=json.dumps(payload))
payload=json.dumps(None)
)

def post_request(self, endpoint, payload):
try:
headers = requests.utils.default_headers()
headers.update({
'User-Agent': self._user_agent
'User-Agent': self._user_agent,
'X-Viber-Auth-Token': self._bot_configuration.auth_token
})
response = requests.post(self._viber_bot_api_url + '/' + endpoint, data=payload, headers=headers)
response.raise_for_status()
Expand All @@ -66,7 +64,6 @@ def get_online_status(self, ids=[]):
raise Exception(u"missing parameter ids, should be a list of viber memberIds")

payload = {
'auth_token': self._bot_configuration.auth_token,
'ids': ids
}
result = self.post_request(
Expand All @@ -83,7 +80,6 @@ def get_user_details(self, user_id):
raise Exception(u"missing parameter id")

payload = {
'auth_token': self._bot_configuration.auth_token,
'id': user_id
}
result = self.post_request(
Expand Down