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

donmahallem / lerna-coveralls / 11633243610

01 Nov 2024 05:04PM CUT coverage: 21.429%. Remained the same
11633243610

push

github

renovate[bot]
chore(deps): update dependency typedoc to v0.26.11

0 of 12 branches covered (0.0%)

Branch coverage included in aggregate %.

18 of 72 relevant lines covered (25.0%)

0.25 hits per line

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

19.51
/packages/package-1/src/flow-api-client.ts
1
/*!
2
 * Source https://github.com/abfluss/abfluss Package: api-client
3
 */
4

5
import {
6
    IDaySummary,
7
    IHistoryItem,
8
    ISleepInterval,
9
    ISleepNearby,
10
    ISleepReport,
11
} from '@abfluss/api-types';
12
import { FlowDate } from '@abfluss/util';
13
import * as request from 'request';
1✔
14
import * as requestPromise from 'request-promise-native';
1✔
15
import { URL } from 'url';
1✔
16

17
export class FlowApiClient {
1✔
18
    private cookieJar: request.CookieJar = request.jar();
1✔
19
    private mUserAgent: string = 'Mozilla/5.0';
1✔
20
    private requestClient: requestPromise.RequestPromiseAPI;
21
    constructor() {
22
        this.requestClient = requestPromise.defaults({
1✔
23
            headers: {
24
                'accept': 'application/json',
25
                'user-agent': this.userAgent,
26
            },
27
            jar: this.cookieJar,
28
        });
29
    }
30

31
    public get jar(): request.CookieJar {
32
        return this.cookieJar;
×
33
    }
34

35
    public get userAgent(): string {
36
        return this.mUserAgent;
1✔
37
    }
38

39
    public set userAgent(useragent: string) {
40
        this.mUserAgent = useragent;
×
41
    }
42

43
    /**
44
     *
45
     * @param mail The mail used to login to flow.polar.com
46
     * @param password the password used to login to flow.polar.com
47
     */
48
    public signin(mail: string, password: string): Promise<request.Response> {
49
        const data: any = {
×
50
            email: mail,
51
            password,
52
            returnUrl: '/',
53
        };
54
        return this.requestClient.post({
×
55
            form: data,
56
            uri: 'https://flow.polar.com/login',
57
        })
58
            .catch((err: any): Promise<any> => {
59
                if (err && err.response && err.response.statusCode === 303) {
×
60
                    return Promise.resolve(err.response);
×
61
                }
62
                return Promise.reject(err);
×
63
            });
64
    }
65

66
    public getSleep(id: number | string): Promise<ISleepInterval[]> {
67
        const getSleepUrl: URL = this.createBaseUrl();
×
68
        getSleepUrl.pathname = '/api/sleep/' + id;
×
69
        return this.get(getSleepUrl);
×
70
    }
71

72
    public getSleepNearby(date: FlowDate): Promise<ISleepNearby> {
73
        const url: URL = this.createBaseUrl();
×
74
        url.pathname = '/api/sleep/nights/nearby';
×
75
        url.searchParams.set('date', date.toString());
×
76
        return this.get(url);
×
77
    }
78

79
    public getSleepReport(from: FlowDate, to: FlowDate): Promise<ISleepReport[]> {
80
        return this.requestClient.get('https://sleep.flow-prd.api.polar.com/api/sleep/report?from=' +
×
81
            from.toString() + '&to=' + to.toString());
82
    }
83
    public getHistory(from: FlowDate, to: FlowDate, userId: string, types?: number[]): Promise<IHistoryItem[]> {
84
        const url: URL = this.createBaseUrl();
×
85
        url.pathname = '/api/training/history';
×
86
        const reqBody: any = {
×
87
            fromDate: from.toString(),
88
            sportIds: types,
89
            toDate: to.toString(),
90
            userId,
91
        };
92
        return this.post(url, reqBody);
×
93
    }
94

95
    public createBaseUrl(): URL {
96
        return new URL('https://flow.polar.com/');
×
97
    }
98

99
    public getActivityTimelineForDay(date: FlowDate,
100
        sampleCount: number = 50000): Promise<IDaySummary> {
×
101
        const url: URL = this.createBaseUrl();
×
102
        url.pathname = '/api/activity-timeline/load';
×
103
        url.searchParams.set('day', date.toString());
×
104
        url.searchParams.set('maxSampleCount', sampleCount.toString(10));
×
105
        return this.get(url);
×
106
    }
107
    /**
108
     * Executes a get request
109
     * @param url url to query
110
     */
111
    public get<T>(queryUrl: URL): Promise<T> {
112
        return this.requestClient.get(queryUrl.toString());
×
113
    }
114
    /**
115
     * Executes a post request
116
     * @param url url to request
117
     * @param body body to send
118
     */
119
    public post<T, B>(queryUrl: URL, body: B): Promise<T> {
120
        return this.requestClient.post(queryUrl.toString(), {
×
121
            body,
122
        });
123
    }
124

125
}
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