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 #6 from zigdon/master
Browse files Browse the repository at this point in the history
Add first /char/ API call, and example on using authenticated calls.
  • Loading branch information
ayust committed Jul 18, 2012
2 parents f1d0570 + 2699292 commit 3736a14
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -54,6 +54,11 @@ print result.find('rowset').findall('row')[0].attrib['name']
# Using the wrapped access level to get the name of a character
eve = evelink.eve.EVE()
print eve.character_name_from_id(1)

# Using authenticated calls
api = evelink.api.API(api_key=(12345, 'longvcodestring'))
char = evelink.char.Char(api=api)
print char.wallet_balance(1234567)
```


Expand Down
28 changes: 28 additions & 0 deletions evelink/char.py
@@ -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']

1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -4,3 +4,4 @@ mock==1.0b1
nose==1.1.2
unittest2==0.5.1
wsgiref==0.1.2
unittest2==0.5.1
49 changes: 49 additions & 0 deletions tests/test_char.py
@@ -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}),
])

3 changes: 2 additions & 1 deletion tests/test_server.py
@@ -1,5 +1,4 @@
import unittest2 as unittest

import mock

import evelink.server as evelink_server
Expand All @@ -26,3 +25,5 @@ def test_server_status(self):
mock.call.get('server/ServerStatus'),
])

if __name__ == "__main__":
unittest.main()

0 comments on commit 3736a14

Please sign in to comment.