@@ -9,7 +9,7 @@ def __init__(self, app_key):
9
9
10
10
def api_fetch (self , path , params = '' ):
11
11
"""
12
- Fetch some json from the API
12
+ Fetch some JSON from the API
13
13
14
14
>>> client = Sc2Ranks('github.com/phleet/sc2ranks')
15
15
>>> client.api_fetch('search/exact/us/phleet')
@@ -19,10 +19,13 @@ def api_fetch(self, path, params=''):
19
19
return fetch_json (url ,params )
20
20
21
21
def validate (self , data , exception ):
22
- if data .has_key ('error' ):
22
+ if type ( data ). __name__ == 'dict' and data .has_key ('error' ):
23
23
raise exception
24
24
else :
25
- return Sc2RanksResponse (data )
25
+ if type (data ).__name__ == 'dict' :
26
+ return Sc2RanksResponse (data )
27
+ elif type (data ).__name__ == 'list' :
28
+ return [Sc2RanksResponse (datum ) for datum in data ]
26
29
27
30
def search_for_character (self , region , name , search_type = 'exact' ):
28
31
"""
@@ -41,6 +44,37 @@ def search_for_character(self, region, name, search_type='exact'):
41
44
data = self .api_fetch ('search/%s/%s/%s' % (search_type ,region ,name )),
42
45
exception = NoSuchCharacterException ("Name: %s, region: %s" % (name ,region ))
43
46
)
47
+
48
+ def search_for_profile (self , region , name , search_type = '1t' , search_subtype = 'division' , value = 'Division' ):
49
+ """
50
+ Search for a character profile
51
+
52
+ >>> client = Sc2Ranks('github.com/phleet/sc2ranks')
53
+ >>> client.search_for_profile(name='phleet', region='us')
54
+ ... #doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
55
+ [<Sc2RanksResponse(bnet_id=299464,
56
+ name=phleet,
57
+ achievement_points=...,
58
+ character_code=...,
59
+ region=us,
60
+ team={u'division_id': ...,
61
+ u'division_name': ...,
62
+ u'wins': ...,
63
+ u'losses': ...,
64
+ u'points': ...,
65
+ u'id': ...},
66
+ id=...)>]
67
+ >>> client.search_for_profile(name='PleaseNobodyTakeThisUsername', region='us')
68
+ Traceback (most recent call last):
69
+ ...
70
+ NoSuchCharacterException: Name: PleaseNobodyTakeThisUsername, region: us
71
+ """
72
+
73
+ return self .validate (
74
+ data = self .api_fetch ('psearch/%s/%s/%s/%s/%s' % (region ,name ,search_type ,search_subtype ,value )),
75
+ exception = NoSuchCharacterException ("Name: %s, region: %s" % (name ,region ))
76
+ )
77
+
44
78
45
79
def fetch_base_character (self , region , name , code ):
46
80
"""
0 commit comments