• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hivesolutions / crossline / 116

pending completion
116

push

travis-ci-com

joamag
feat: dashed based dependencies

320 of 404 relevant lines covered (79.21%)

5.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.27
/src/crossline/controllers/api.py
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3

4
import csv
7✔
5
import appier
7✔
6

7
import crossline
7✔
8

9
ROW_ORDER = (
7✔
10
    "app",
11
    "year",
12
    "month",
13
    "day",
14
    "hour",
15
    "counter"
16
)
17
""" The list defining the sequence of the various
18
columns to be used in the creation of the rows """
19

20
class APIController(appier.Controller, appier.Mongo):
7✔
21

22
    def __init__(self, owner, *args, **kwargs):
7✔
23
        appier.Controller.__init__(self, owner, *args, **kwargs)
7✔
24
        appier.Mongo.__init__(self, *args, **kwargs)
7✔
25
        self.adapters = crossline.get_adapters()
7✔
26

27
    @appier.route("/api/cross", ("GET", "POST"), json = True)
7✔
28
    @appier.route("/api/<str:app>/cross", ("GET", "POST"), json = True)
7✔
29
    def cross(self, app = None):
7✔
30
        return crossline.CounterFact.increment_s(
×
31
            app,
32
            adapters = self.adapters,
33
            action = "cross",
34
            payload = appier.get_object()
35
        )
36

37
    @appier.route("/api/enter", ("GET", "POST"), json = True)
7✔
38
    @appier.route("/api/<str:app>/enter", ("GET", "POST"), json = True)
7✔
39
    def enter(self, app = None):
7✔
40
        return crossline.CounterFact.increment_s(
×
41
            app,
42
            adapters = self.adapters,
43
            action = "enter",
44
            payload = appier.get_object()
45
        )
46

47
    @appier.route("/api/facts", "GET", json = True)
7✔
48
    @appier.route("/api/<str:app>/facts", "GET", json = True)
7✔
49
    @appier.ensure(token = "admin")
7✔
50
    def facts(self, app = None):
7✔
51
        object = appier.get_object(
×
52
            alias = True,
53
            find = True,
54
            sort = [("_id", -1)]
55
        )
56
        if app: object["app"] = app
×
57
        facts = crossline.CounterFact.find(map = True, **object)
×
58
        return facts
×
59

60
    @appier.route("/api/facts.csv", "GET", json = True)
7✔
61
    @appier.route("/api/<str:app>/facts.csv", "GET", json = True)
7✔
62
    @appier.ensure(token = "admin")
7✔
63
    def facts_csv(self, app = None):
7✔
64
        object = appier.get_object(
×
65
            alias = True,
66
            find = True,
67
            sort = [("_id", -1)]
68
        )
69
        if app: object["app"] = app
×
70
        facts = crossline.CounterFact.find(map = True, **object)
×
71

72
        buffer = appier.legacy.StringIO()
×
73
        writer = csv.writer(buffer, delimiter = ";")
×
74
        writer.writerow(ROW_ORDER)
×
75

76
        for fact in facts:
×
77
            row = []
×
78
            for name in ROW_ORDER:
×
79
                value = fact[name]
×
80
                row.append(value)
×
81
            writer.writerow(row)
×
82

83
        data = buffer.getvalue()
×
84

85
        self.content_type("text/csv")
×
86
        return data
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc