Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.

Commit a149f28

Browse files
authored
Merge pull request #48 from upwork/v2.0.1
Add send_message_to_rooms
2 parents 86e12f0 + acfaea6 commit a149f28

File tree

6 files changed

+33
-9
lines changed

6 files changed

+33
-9
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
packages=find_packages(),
3232
setup_requires=[],
3333
url="https://github.com/upwork/python-upwork",
34-
version="2.0.0",
34+
version="2.0.1",
3535
zip_safe=False,
3636
)

tests/routers/test_messages.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ def test_send_message_to_room(mocked_method):
5555
mocked_method.assert_called_with("/messages/v3/company/rooms/room_id/stories", {})
5656

5757

58+
@patch.object(upwork.Client, "post")
59+
def test_send_message_to_rooms(mocked_method):
60+
messages.Api(upwork.Client).send_message_to_rooms("company")
61+
mocked_method.assert_called_with("/messages/v3/company/stories/batch", {})
62+
63+
5864
@patch.object(upwork.Client, "put")
5965
def test_get_update_room_settings(mocked_method):
6066
messages.Api(upwork.Client).update_room_settings("company", "room_id", "username")

upwork/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
__author__ = """Maksym Novozhylov"""
88
__email__ = "mnovozhilov@upwork.com"
9-
__version__ = "2.0.0"
9+
__version__ = "2.0.1"
1010

1111
__all__ = ("Config", "Client", "routers")

upwork/client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_request_token(self):
4242
request_token_url = full_url(self.__uri_rtoken, upwork.DEFAULT_EPOINT)
4343

4444
try:
45-
r = requests.post(url=request_token_url, auth=oauth)
45+
r = requests.post(url=request_token_url, auth=oauth, verify=self.config.verify_ssl)
4646
except Exception as e:
4747
raise e
4848

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

9898
try:
99-
r = requests.post(url=access_token_url, auth=oauth)
99+
r = requests.post(url=access_token_url, auth=oauth, verify=self.config.verify_ssl)
100100
except Exception as e:
101101
raise e
102102

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

167167
if method == "get":
168-
r = requests.get(url, params=params, auth=oauth)
168+
r = requests.get(url, params=params, auth=oauth, verify=self.config.verify_ssl)
169169
elif method == "put":
170170
headers = {"Content-type": "application/json"}
171-
r = requests.put(url, json=params, headers=headers, auth=oauth)
171+
r = requests.put(url, json=params, headers=headers, auth=oauth, verify=self.config.verify_ssl)
172172
elif method in {"post", "delete"}:
173173
headers = {"Content-type": "application/json"}
174-
r = requests.post(url, json=params, headers=headers, auth=oauth)
174+
r = requests.post(url, json=params, headers=headers, auth=oauth, verify=self.config.verify_ssl)
175175
else:
176176
raise ValueError(
177177
'Do not know how to handle http method "{0}"'.format(method)
178178
)
179+
print(r)
179180

180181
return r.json()
181182

upwork/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
class Config:
1616
"""Configuration container"""
1717

18+
verify_ssl = True
19+
1820
def __init__(self, config):
1921
self.consumer_key, self.consumer_secret = (
2022
config["consumer_key"],
@@ -26,3 +28,6 @@ def __init__(self, config):
2628

2729
if "access_token_secret" in config:
2830
self.access_token_secret = config["access_token_secret"]
31+
32+
if "verify_ssl" in config:
33+
self.verify_ssl = config["verify_ssl"]

upwork/routers/messages.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ def create_room(self, company, params={}):
108108

109109
def send_message_to_room(self, company, room_id, params={}):
110110
"""Send a message to a room
111-
111+
112112
Parameters:
113-
:param company:
113+
:param company:
114114
:param room_id:
115115
:param params: (Default value = {})
116116
@@ -119,6 +119,18 @@ def send_message_to_room(self, company, room_id, params={}):
119119
"/messages/v3/{0}/rooms/{1}/stories".format(company, room_id), params
120120
)
121121

122+
def send_message_to_rooms(self, company, params={}):
123+
"""Send a message to a batch of rooms
124+
125+
Parameters:
126+
:param company:
127+
:param params: (Default value = {})
128+
129+
"""
130+
return self.client.post(
131+
"/messages/v3/{0}/stories/batch".format(company), params
132+
)
133+
122134
def update_room_settings(self, company, room_id, username, params={}):
123135
"""Update a room settings
124136

0 commit comments

Comments
 (0)