Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / endpoints / aquarium / client.py @ 4319c408

History | View | Annotate | Download (2 kB)

1 6e029beb Sofia Papagiannaki
# Copyright 2011-2012 GRNET S.A. All rights reserved.
2 6e029beb Sofia Papagiannaki
#
3 6e029beb Sofia Papagiannaki
# Redistribution and use in source and binary forms, with or
4 6e029beb Sofia Papagiannaki
# without modification, are permitted provided that the following
5 6e029beb Sofia Papagiannaki
# conditions are met:
6 6e029beb Sofia Papagiannaki
#
7 6e029beb Sofia Papagiannaki
#   1. Redistributions of source code must retain the above
8 6e029beb Sofia Papagiannaki
#      copyright notice, this list of conditions and the following
9 6e029beb Sofia Papagiannaki
#      disclaimer.
10 6e029beb Sofia Papagiannaki
#
11 6e029beb Sofia Papagiannaki
#   2. Redistributions in binary form must reproduce the above
12 6e029beb Sofia Papagiannaki
#      copyright notice, this list of conditions and the following
13 6e029beb Sofia Papagiannaki
#      disclaimer in the documentation and/or other materials
14 6e029beb Sofia Papagiannaki
#      provided with the distribution.
15 6e029beb Sofia Papagiannaki
#
16 6e029beb Sofia Papagiannaki
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 6e029beb Sofia Papagiannaki
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 6e029beb Sofia Papagiannaki
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 6e029beb Sofia Papagiannaki
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 6e029beb Sofia Papagiannaki
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 6e029beb Sofia Papagiannaki
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 6e029beb Sofia Papagiannaki
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 6e029beb Sofia Papagiannaki
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 6e029beb Sofia Papagiannaki
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 6e029beb Sofia Papagiannaki
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 6e029beb Sofia Papagiannaki
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 6e029beb Sofia Papagiannaki
# POSSIBILITY OF SUCH DAMAGE.
28 6e029beb Sofia Papagiannaki
#
29 6e029beb Sofia Papagiannaki
# The views and conclusions contained in the software and
30 6e029beb Sofia Papagiannaki
# documentation are those of the authors and should not be
31 6e029beb Sofia Papagiannaki
# interpreted as representing official policies, either expressed
32 6e029beb Sofia Papagiannaki
# or implied, of GRNET S.A.
33 6e029beb Sofia Papagiannaki
34 6e029beb Sofia Papagiannaki
import requests
35 6e029beb Sofia Papagiannaki
36 6e029beb Sofia Papagiannaki
from django.utils import simplejson as json
37 6e029beb Sofia Papagiannaki
38 6e029beb Sofia Papagiannaki
from astakos.im.settings import AQUARIUM_URL
39 6e029beb Sofia Papagiannaki
40 5ce3ce4f Sofia Papagiannaki
41 6e029beb Sofia Papagiannaki
class AquariumClient():
42 6e029beb Sofia Papagiannaki
    def get_billing(self, user, start, end):
43 6e029beb Sofia Papagiannaki
        if not AQUARIUM_URL:
44 6e029beb Sofia Papagiannaki
            return
45 5ce3ce4f Sofia Papagiannaki
46 6e029beb Sofia Papagiannaki
        url = AQUARIUM_URL.rstrip('/')
47 6e029beb Sofia Papagiannaki
        url = '%s/%s/bill/%d/%d' % (url, user, start, end)
48 6e029beb Sofia Papagiannaki
        r = requests.get(url)
49 6e029beb Sofia Papagiannaki
        try:
50 6e029beb Sofia Papagiannaki
            return r.status_code, json.loads(r.text)
51 6e029beb Sofia Papagiannaki
        except ValueError:
52 6e029beb Sofia Papagiannaki
            pass
53 5ce3ce4f Sofia Papagiannaki
        return r.status_code, None