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

Commit c0446fe

Browse files
committed
Allowed object oriented coros with temp clients
1 parent 9dfb72a commit c0446fe

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

crasync/models.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'''
2424
import json
2525
from os import path
26+
from .core import Client
2627

2728
_path = path.join(
2829
path.dirname(path.realpath(__file__)),
@@ -52,7 +53,11 @@ async def from_data(self):
5253

5354
async def update(self):
5455
'''Update an object with current info.'''
55-
data = await self.client.request(self.url)
56+
if self.client.session.closed:
57+
async with Client() as client:
58+
data = await client.request(self.url)
59+
else:
60+
data = await self.client.request(self.url)
5661

5762
self.raw_data = data
5863
self.from_data(data)
@@ -144,6 +149,8 @@ def __repr__(self):
144149
return '<Member tag={0.tag}>'.format(self)
145150

146151
def get_profile(self):
152+
if self.client.session.closed:
153+
return crasync.get_profile(self.tag)
147154
return self.client.get_profile(self.tag)
148155

149156
class Alliance:
@@ -206,7 +213,10 @@ def badge_url(self):
206213
return "http://api.cr-api.com" + url
207214

208215
def get_clan(self):
209-
return self.client.get_clan(self.tag)
216+
if self.client.session.closed:
217+
return crasync.get_clan(self.tag)
218+
else:
219+
return self.client.get_clan(self.tag)
210220

211221
def __repr__(self):
212222
return '<ClanInfo tag={0.tag}>'.format(self)
@@ -311,7 +321,10 @@ def get_chest(self, index=0):
311321
def get_clan(self):
312322
if self.clan_tag is None:
313323
raise ValueError('Profile has no Clan')
314-
return self.client.get_clan(self.clan_tag)
324+
if self.client.session.closed:
325+
return crasync.get_clan(self.clan_tag)
326+
else:
327+
return self.client.get_clan(self.clan_tag)
315328

316329
def __repr__(self):
317330
return '<Profile tag={0.tag}>'.format(self)

0 commit comments

Comments
 (0)