This repository has been archived by the owner on Jul 14, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from zigdon/master
Add first /char/ API call, and example on using authenticated calls.
- Loading branch information
Showing
5 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class Char(object): | ||
"""Wrapper around /char/ of the EVE API. | ||
Note that a valid API key is required. | ||
""" | ||
|
||
def __init__(self, api): | ||
self.api = api | ||
|
||
def wallet_info(self, character_id): | ||
"""Return a given character's wallet.""" | ||
api_result = self.api.get('char/AccountBalance', | ||
{'characterID': character_id}) | ||
|
||
rowset = api_result.find('rowset') | ||
row = rowset.find('row') | ||
result = { | ||
'balance': float(row.attrib['balance']), | ||
'id': int(row.attrib['accountID']), | ||
'key': int(row.attrib['accountKey']), | ||
} | ||
return result | ||
|
||
def wallet_balance(self, character_id): | ||
"""Helper to return just the balance from a given character wallet""" | ||
|
||
return self.wallet_info(character_id)['balance'] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ mock==1.0b1 | |
nose==1.1.2 | ||
unittest2==0.5.1 | ||
wsgiref==0.1.2 | ||
unittest2==0.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import mock | ||
|
||
import evelink.char as evelink_char | ||
from tests.utils import APITestCase | ||
|
||
class CharTestCase(APITestCase): | ||
|
||
def setUp(self): | ||
super(CharTestCase, self).setUp() | ||
self.char = evelink_char.Char(api=self.api) | ||
|
||
def test_wallet_info(self): | ||
self.api.get.return_value = self.make_api_result(r""" | ||
<result> | ||
<rowset name="accounts" key="accountID" columns="accountID,accountKey,balance"> | ||
<row accountID="1" accountKey="1000" balance="209127923.31" /> | ||
</rowset> | ||
</result> | ||
""") | ||
|
||
result = self.char.wallet_info(1) | ||
|
||
self.assertEqual(result, | ||
{ | ||
'balance': 209127923.31, | ||
'id': 1, | ||
'key': 1000, | ||
} | ||
) | ||
self.assertEqual(self.api.mock_calls, [ | ||
mock.call.get('char/AccountBalance', {'characterID': 1}), | ||
]) | ||
|
||
def test_wallet_balance(self): | ||
self.api.get.return_value = self.make_api_result(r""" | ||
<result> | ||
<rowset name="accounts" key="accountID" columns="accountID,accountKey,balance"> | ||
<row accountID="1" accountKey="1000" balance="209127923.31" /> | ||
</rowset> | ||
</result> | ||
""") | ||
|
||
result = self.char.wallet_balance(1) | ||
|
||
self.assertEqual(result, 209127923.31) | ||
self.assertEqual(self.api.mock_calls, [ | ||
mock.call.get('char/AccountBalance', {'characterID': 1}), | ||
]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters