Skip to content

Commit

Permalink
Merge pull request #48 from upwork/v2.0.1
Browse files Browse the repository at this point in the history
Add send_message_to_rooms
  • Loading branch information
mnovozhylov authored Sep 18, 2020
2 parents 86e12f0 + acfaea6 commit a149f28
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
packages=find_packages(),
setup_requires=[],
url="https://github.com/upwork/python-upwork",
version="2.0.0",
version="2.0.1",
zip_safe=False,
)
6 changes: 6 additions & 0 deletions tests/routers/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def test_send_message_to_room(mocked_method):
mocked_method.assert_called_with("/messages/v3/company/rooms/room_id/stories", {})


@patch.object(upwork.Client, "post")
def test_send_message_to_rooms(mocked_method):
messages.Api(upwork.Client).send_message_to_rooms("company")
mocked_method.assert_called_with("/messages/v3/company/stories/batch", {})


@patch.object(upwork.Client, "put")
def test_get_update_room_settings(mocked_method):
messages.Api(upwork.Client).update_room_settings("company", "room_id", "username")
Expand Down
2 changes: 1 addition & 1 deletion upwork/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

__author__ = """Maksym Novozhylov"""
__email__ = "[email protected]"
__version__ = "2.0.0"
__version__ = "2.0.1"

__all__ = ("Config", "Client", "routers")
11 changes: 6 additions & 5 deletions upwork/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_request_token(self):
request_token_url = full_url(self.__uri_rtoken, upwork.DEFAULT_EPOINT)

try:
r = requests.post(url=request_token_url, auth=oauth)
r = requests.post(url=request_token_url, auth=oauth, verify=self.config.verify_ssl)
except Exception as e:
raise e

Expand Down Expand Up @@ -96,7 +96,7 @@ def get_access_token(self, verifier):
access_token_url = full_url(self.__uri_atoken, upwork.DEFAULT_EPOINT)

try:
r = requests.post(url=access_token_url, auth=oauth)
r = requests.post(url=access_token_url, auth=oauth, verify=self.config.verify_ssl)
except Exception as e:
raise e

Expand Down Expand Up @@ -165,17 +165,18 @@ def send_request(self, uri, method="get", params={}):
url = full_url(get_uri_with_format(uri, self.epoint), self.epoint)

if method == "get":
r = requests.get(url, params=params, auth=oauth)
r = requests.get(url, params=params, auth=oauth, verify=self.config.verify_ssl)
elif method == "put":
headers = {"Content-type": "application/json"}
r = requests.put(url, json=params, headers=headers, auth=oauth)
r = requests.put(url, json=params, headers=headers, auth=oauth, verify=self.config.verify_ssl)
elif method in {"post", "delete"}:
headers = {"Content-type": "application/json"}
r = requests.post(url, json=params, headers=headers, auth=oauth)
r = requests.post(url, json=params, headers=headers, auth=oauth, verify=self.config.verify_ssl)
else:
raise ValueError(
'Do not know how to handle http method "{0}"'.format(method)
)
print(r)

return r.json()

Expand Down
5 changes: 5 additions & 0 deletions upwork/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
class Config:
"""Configuration container"""

verify_ssl = True

def __init__(self, config):
self.consumer_key, self.consumer_secret = (
config["consumer_key"],
Expand All @@ -26,3 +28,6 @@ def __init__(self, config):

if "access_token_secret" in config:
self.access_token_secret = config["access_token_secret"]

if "verify_ssl" in config:
self.verify_ssl = config["verify_ssl"]
16 changes: 14 additions & 2 deletions upwork/routers/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ def create_room(self, company, params={}):

def send_message_to_room(self, company, room_id, params={}):
"""Send a message to a room
Parameters:
:param company:
:param company:
:param room_id:
:param params: (Default value = {})
Expand All @@ -119,6 +119,18 @@ def send_message_to_room(self, company, room_id, params={}):
"/messages/v3/{0}/rooms/{1}/stories".format(company, room_id), params
)

def send_message_to_rooms(self, company, params={}):
"""Send a message to a batch of rooms
Parameters:
:param company:
:param params: (Default value = {})
"""
return self.client.post(
"/messages/v3/{0}/stories/batch".format(company), params
)

def update_room_settings(self, company, room_id, username, params={}):
"""Update a room settings
Expand Down

0 comments on commit a149f28

Please sign in to comment.