Passed
Push — develop ( e76d2d...088138 )
by Jace
01:20
created

get()   A

Complexity

Conditions 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
c 2
b 0
f 0
dl 0
loc 17
ccs 13
cts 13
cp 1
crap 4
rs 9.2
1
"""API client functions."""
2
3 1
import logging
4 1
import time
5
6 1
import requests
7
8 1
from .cache import Cache
9
10
11 1
log = logging.getLogger(__name__)
12 1
cache = Cache()
13
14
15 1
def get(url, data):
16 1
    log.info("Getting %s: %s", url, data)
17
18 1
    response = cache.get((url, data))
19 1
    if response is None:
20 1
        for i in range(3):
21 1
            response = requests.put(url, data=data)
22 1
            if response.status_code == 500:
23 1
                time.sleep(i + 1)
24 1
                continue
25
            else:
26 1
                break
27 1
        cache.set((url, data), response)
28
29 1
    log.info("Response: %s", response)
30
31 1
    return response
32
33
34 1
def delete(url, data):
35 1
    log.info("Deleting %s: %s", url, data)
36
37 1
    for i in range(3):
38 1
        response = requests.delete(url, data=data)
39 1
        if response.status_code == 500:
40
            time.sleep(i + 1)
41
            continue
42
        else:
43 1
            break
44
45 1
    log.info("Response: %s", response)
0 ignored issues
show
introduced by
The variable response does not seem to be defined in case the for loop on line 37 is not entered. Are you sure this can never be the case?
Loading history...
46
47
    return response
48