Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #223 from ayust/aegis
Browse files Browse the repository at this point in the history
Add API changes from the Aegis Sovereignty patch.
  • Loading branch information
ayust committed Jul 14, 2015
2 parents 139a385 + 937cf75 commit 536a375
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 41 deletions.
6 changes: 6 additions & 0 deletions evelink/char.py
Expand Up @@ -2,6 +2,7 @@

from evelink import api, constants
from evelink.parsing.assets import parse_assets
from evelink.parsing.bookmarks import parse_bookmarks
from evelink.parsing.contact_list import parse_contact_list
from evelink.parsing.contract_bids import parse_contract_bids
from evelink.parsing.contract_items import parse_contract_items
Expand Down Expand Up @@ -67,6 +68,11 @@ def assets(self, api_result=None):

return api.APIResult(parse_assets(api_result.result), api_result.timestamp, api_result.expires)

@auto_call('char/Bookmarks')
def bookmarks(self, api_result=None):
"""Retrieves this character's bookmarks."""
return api.APIResult(parse_bookmarks(api_result.result), api_result.timestamp, api_result.expires)

@auto_call('char/ContractBids')
def contract_bids(self, api_result=None):
"""Lists the latest bids that have been made to any recent auctions."""
Expand Down
9 changes: 9 additions & 0 deletions evelink/corp.py
@@ -1,5 +1,6 @@
from evelink import api, constants
from evelink.parsing.assets import parse_assets
from evelink.parsing.bookmarks import parse_bookmarks
from evelink.parsing.contact_list import parse_contact_list
from evelink.parsing.contract_bids import parse_contract_bids
from evelink.parsing.contract_items import parse_contract_items
Expand Down Expand Up @@ -215,6 +216,11 @@ def assets(self, api_result=None):

return api.APIResult(parse_assets(api_result.result), api_result.timestamp, api_result.expires)

@api.auto_call('corp/Bookmarks')
def bookmarks(self, api_result=None):
"""Retrieves this corp's bookmarks."""
return api.APIResult(parse_bookmarks(api_result.result), api_result.timestamp, api_result.expires)

@api.auto_call('corp/FacWarStats')
def faction_warfare_stats(self, api_result=None):
"""Returns stats from faction warfare if this corp is enrolled.
Expand Down Expand Up @@ -593,6 +599,9 @@ def stations(self, api_result=None):
'cut': float(a['reprocessingStationTake']),
},
'standing_owner_id': int(a['standingOwnerID']),
'x': float(a['x']),
'y': float(a['y']),
'z': float(a['z']),
}
results[station['id']] = station

Expand Down
5 changes: 4 additions & 1 deletion evelink/eve.py
Expand Up @@ -448,7 +448,10 @@ def conquerable_stations(self, api_result=None):
'system_id': int(row.attrib['solarSystemID']),
'corp': {
'id': int(row.attrib['corporationID']),
'name': row.attrib['corporationName'] }
'name': row.attrib['corporationName'] },
'x': float(row.attrib['x']),
'y': float(row.attrib['y']),
'z': float(row.attrib['z']),
}
results[station['id']] = station

Expand Down
35 changes: 35 additions & 0 deletions evelink/parsing/bookmarks.py
@@ -0,0 +1,35 @@
from evelink import api

def parse_bookmarks(api_results):
result = {}
folders = api_results.find('rowset')
for row in folders.findall('row'):
a = row.attrib
folder_id = int(a['folderID'])
folder = {
'id': folder_id,
'name': a['folderName'], # "" = toplevel
'creator_id': int(a['creatorID']),
'bookmarks': {},
}
bookmarks = row.find('rowset')
for row in bookmarks.findall('row'):
a = row.attrib
bookmark_id = int(a['bookmarkID'])
folder['bookmarks'][bookmark_id] = {
'id': bookmark_id,
'name': a['memo'],
'creator_id': int(a['creatorID']),
'created_ts': api.parse_ts(a['created']),
'item_id': int(a['itemID']),
'type_id': int(a['typeID']),
'location_id': int(a['locationID']),
'x': float(a['x']),
'y': float(a['y']),
'z': float(a['z']),
'note': a['note'],
}
result[folder_id] = folder
return result

# vim: set ts=4 sts=4 sw=4 et:
61 changes: 46 additions & 15 deletions evelink/parsing/contact_list.py
@@ -1,26 +1,57 @@

LABEL_MAP = {
CONTACTS_MAP = {
'allianceContactList': 'alliance',
'corporateContactList': 'corp',
'contactList': 'personal',
}

LABEL_MAP = {
'contactLabels': 'personal',
'corporateContactLabels': 'corp',
'allianceContactLabels': 'alliance',
}


def parse_contact_list(api_result):
result = {}
result = {'labels': {}}
for rowset in api_result.findall('rowset'):
contact_list = result[LABEL_MAP[rowset.get('name')]] = {}
for row in rowset.findall('row'):
in_watchlist = (row.get('inWatchlist') == 'True'
if 'inWatchlist' in row.attrib
else None)
contact_id = int(row.get('contactID'))
contact_list[contact_id] = {
'id': contact_id,
'name': row.get('contactName'),
'standing': float(row.get('standing')),
'in_watchlist': in_watchlist
}
setname = rowset.get('name')

if setname in CONTACTS_MAP:
contact_list = result[CONTACTS_MAP[rowset.get('name')]] = {}
for row in rowset.findall('row'):
in_watchlist = (row.get('inWatchlist') == 'True'
if 'inWatchlist' in row.attrib
else None)
contact_id = int(row.get('contactID'))
contact_list[contact_id] = {
'id': contact_id,
'name': row.get('contactName'),
'standing': float(row.get('standing')),
'in_watchlist': in_watchlist,
'label_mask': int(row.get('labelMask') or 0),
'labels': {},
}
elif setname in LABEL_MAP:
label_list = result['labels'][LABEL_MAP[setname]] = {}
for row in rowset.findall('row'):
label_id = int(row.get('labelID'))
label_list[label_id] = {
'id': label_id,
'name': row.get('name'),
}
for grouping in ('personal', 'corp', 'alliance'):
group = result.get(grouping)
if not group:
continue
labels = result['labels'][grouping]
for contact_id in group:
contact = group[contact_id]
labelMask = contact['label_mask']
if labelMask:
for label_id in labels:
if labelMask & label_id:
contact['labels'][label_id] = labels[label_id]
del contact['label_mask']

return result

73 changes: 73 additions & 0 deletions tests/parsing/test_bookmarks.py
@@ -0,0 +1,73 @@
from tests.compat import unittest
from tests.utils import make_api_result

from evelink.parsing import bookmarks as evelink_b

class BookmarksTestCase(unittest.TestCase):

def test_parse_bookmarks(self):
api_result, _, _ = make_api_result("char/bookmarks.xml")

result = evelink_b.parse_bookmarks(api_result)

self.assertEqual(result, {
0: {
'bookmarks': {
12: {
'created_ts': 1436391254,
'creator_id': 90000001,
'id': 12,
'item_id': 60014689,
'location_id': 30004971,
'name': 'Home Station',
'note': 'Our base of residence',
'type_id': 57,
'x': 0.0,
'y': 0.0,
'z': 0.0,
},
13: {
'created_ts': 1436391307,
'creator_id': 90000001,
'id': 13,
'item_id': 40314792,
'location_id': 30004971,
'name': 'Sun',
'note': '',
'type_id': 8,
'x': 0.0,
'y': 0.0,
'z': 0.0,
},
},
'creator_id': 0,
'id': 0,
'name': '',
},
1: {
'bookmarks': {},
'creator_id': 90000001,
'id': 1,
'name': 'A lovely empty folder',
},
4: {
'bookmarks': {
14: {
'created_ts': 1436391368,
'creator_id': 90000001,
'id': 14,
'item_id': 0,
'location_id': 30004971,
'name': 'spot in Duripant solar system',
'note': '',
'type_id': 5,
'x': -373405654941.733,
'y': 42718621667.0746,
'z': -1415023302173.46,
},
},
'creator_id': 90000001,
'id': 4,
'name': 'Random crap',
},
})
69 changes: 54 additions & 15 deletions tests/parsing/test_contact_list.py
Expand Up @@ -17,33 +17,57 @@ def test_parse_char_contact_list(self):
'corp': {
1082138174: {'standing': 10.0, 'id': 1082138174,
'name': 'Nomad LLP',
'in_watchlist': None},
'in_watchlist': None,
'labels': {}},
1086308227: {'standing': 0.0, 'id': 1086308227,
'name': 'Rebel Alliance of New Eden',
'in_watchlist': None},
'in_watchlist': None,
'labels': {
1: {'id': 1, 'name': 'Corp Spies!'}}},
1113838907: {'standing': -10.0, 'id': 1113838907,
'name': 'Significant other',
'in_watchlist': None}
'in_watchlist': None,
'labels': {}}
},
'alliance': {
2049763943: {'standing': -10.0, 'id': 2049763943,
'name': 'EntroPraetorian Aegis',
'in_watchlist': None},
'in_watchlist': None,
'labels': {}},
2067199408: {'standing': -10.0, 'id': 2067199408,
'name': 'Vera Cruz Alliance',
'in_watchlist': None},
'in_watchlist': None,
'labels': {
2: {'id': 2, 'name': 'Stupid'}}},
2081065875: {'standing': -7.5, 'id': 2081065875,
'name': 'TheRedMaple',
'in_watchlist': None}
'in_watchlist': None,
'labels': {}}
},
'personal': {
3009988: {'standing': 0.0, 'id': 3009988,
'name': 'Navittus Sildbena',
'in_watchlist': True},
'in_watchlist': True,
'labels': {}},
544497016: {'standing': 10.0, 'id': 544497016,
'name': 'Valkyries of Night',
'in_watchlist': False}
}
'in_watchlist': False,
'labels': {
1: {'id': 1, 'name': 'Alts'},
2: {'id': 2, 'name': 'Evil Twins'}}},

},
'labels': {
'corp': {
1: {'id': 1, 'name': 'Corp Spies!'}},
'alliance': {
1: {'id': 1, 'name': 'Alliance Friend'},
2: {'id': 2, 'name': 'Stupid'}},
'personal': {
1: {'id': 1, 'name': 'Alts'},
2: {'id': 2, 'name': 'Evil Twins'},
4611686018427387904: {'id': 4611686018427387904, 'name': 'Label 61'}},
},
}

self.assertEqual(result['personal'], expected_result['personal'])
Expand All @@ -60,24 +84,39 @@ def test_parse_corp_contact_list(self):
'corp': {
1082138174: {'standing': 10.0, 'id': 1082138174,
'name': 'Nomad LLP',
'in_watchlist': None},
'in_watchlist': None,
'labels': {}},
1086308227: {'standing': 0.0, 'id': 1086308227,
'name': 'Rebel Alliance of New Eden',
'in_watchlist': None},
'in_watchlist': None,
'labels': {
1: {'id': 1, 'name': 'Corp Spies!'}}},
1113838907: {'standing': -10.0, 'id': 1113838907,
'name': 'Significant other',
'in_watchlist': None}
'in_watchlist': None,
'labels': {}}
},
'alliance': {
2049763943: {'standing': -10.0, 'id': 2049763943,
'name': 'EntroPraetorian Aegis',
'in_watchlist': None},
'in_watchlist': None,
'labels': {}},
2067199408: {'standing': -10.0, 'id': 2067199408,
'name': 'Vera Cruz Alliance',
'in_watchlist': None},
'in_watchlist': None,
'labels': {
2: {'id': 2, 'name': 'Stupid'}}},
2081065875: {'standing': -10.0, 'id': 2081065875,
'name': 'TheRedMaple',
'in_watchlist': None}
'in_watchlist': None,
'labels': {}}
},
'labels': {
'corp': {
1: {'id': 1, 'name': 'Corp Spies!'}},
'alliance': {
1: {'id': 1, 'name': 'Alliance Friend'},
2: {'id': 2, 'name': 'Stupid'}},
},
}

Expand Down
16 changes: 16 additions & 0 deletions tests/test_char.py
Expand Up @@ -32,6 +32,22 @@ def test_assets(self, mock_parse):
self.assertEqual(current, 12345)
self.assertEqual(expires, 67890)

@mock.patch('evelink.char.parse_bookmarks')
def test_bookmarks(self, mock_parse):
self.api.get.return_value = API_RESULT_SENTINEL
mock_parse.return_value = mock.sentinel.parsed_bookmarks

result, current, expires = self.char.bookmarks()
self.assertEqual(result, mock.sentinel.parsed_bookmarks)
self.assertEqual(mock_parse.mock_calls, [
mock.call(mock.sentinel.api_result),
])
self.assertEqual(self.api.mock_calls, [
mock.call.get('char/Bookmarks', params={'characterID': 1}),
])
self.assertEqual(current, 12345)
self.assertEqual(expires, 67890)

@mock.patch('evelink.char.parse_contract_bids')
def test_contract_bids(self, mock_parse):
self.api.get.return_value = API_RESULT_SENTINEL
Expand Down

0 comments on commit 536a375

Please sign in to comment.