@anmiles/google-api-wrapper 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "cSpell.words": [
3
3
  "anmiles",
4
+ "Calendarlist",
4
5
  "cicd",
5
6
  "colorette",
7
+ "Gaxios",
6
8
  "linebreak",
7
9
  "nycrc",
8
10
  "Playlistitems"
package/CHANGELOG.md CHANGED
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.0.2](../../tags/v2.0.2) - 2023-03-13
9
+ ### Added
10
+ - Calendars list API
11
+ - Export shared `getItems` to use for any other APIs
12
+
13
+ ## [2.0.1](../../tags/v2.0.1) - 2023-03-12
14
+ ### Changed
15
+ - Fixed exported types
16
+
8
17
  ## [2.0.0](../../tags/v2.0.0) - 2023-03-12
9
18
  ### Changed
10
19
  - Split APIs
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export { getEvents, getVideos } from './lib/data';
1
+ export * as calendar from './lib/api/calendar';
2
+ export * as youtube from './lib/api/youtube';
2
3
  export { createProfile, getProfiles } from './lib/profiles';
3
4
  export { login } from './lib/auth';
package/dist/index.js CHANGED
@@ -1,9 +1,31 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.login = exports.getProfiles = exports.createProfile = exports.getVideos = exports.getEvents = void 0;
4
- var data_1 = require("./lib/data");
5
- Object.defineProperty(exports, "getEvents", { enumerable: true, get: function () { return data_1.getEvents; } });
6
- Object.defineProperty(exports, "getVideos", { enumerable: true, get: function () { return data_1.getVideos; } });
26
+ exports.login = exports.getProfiles = exports.createProfile = exports.youtube = exports.calendar = void 0;
27
+ exports.calendar = __importStar(require("./lib/api/calendar"));
28
+ exports.youtube = __importStar(require("./lib/api/youtube"));
7
29
  var profiles_1 = require("./lib/profiles");
8
30
  Object.defineProperty(exports, "createProfile", { enumerable: true, get: function () { return profiles_1.createProfile; } });
9
31
  Object.defineProperty(exports, "getProfiles", { enumerable: true, get: function () { return profiles_1.getProfiles; } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkD;AAAzC,iGAAA,SAAS,OAAA;AAAE,iGAAA,SAAS,OAAA;AAC7B,2CAA4D;AAAnD,yGAAA,aAAa,OAAA;AAAE,uGAAA,WAAW,OAAA;AACnC,mCAAmC;AAA1B,6FAAA,KAAK,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAA+C;AAC/C,6DAA6C;AAC7C,2CAA4D;AAAnD,yGAAA,aAAa,OAAA;AAAE,uGAAA,WAAW,OAAA;AACnC,mCAAmC;AAA1B,6FAAA,KAAK,OAAA"}
@@ -0,0 +1,11 @@
1
+ import type GoogleApis from 'googleapis';
2
+ export { getAPI, getEvents, setEvent };
3
+ declare const _default: {
4
+ getAPI: typeof getAPI;
5
+ getEvents: typeof getEvents;
6
+ setEvent: typeof setEvent;
7
+ };
8
+ export default _default;
9
+ declare function getAPI(profile: string): Promise<GoogleApis.calendar_v3.Calendar>;
10
+ declare function getEvents(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Events$List): Promise<unknown[]>;
11
+ declare function setEvent(profile: string, eventId: string | undefined, args: GoogleApis.calendar_v3.Params$Resource$Events$Update): Promise<void>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setEvent = exports.getEvents = exports.getAPI = void 0;
7
+ const googleapis_1 = require("googleapis");
8
+ const auth_1 = require("../auth");
9
+ const shared_1 = require("./shared");
10
+ const calendar_1 = __importDefault(require("./calendar"));
11
+ exports.default = { getAPI, getEvents, setEvent };
12
+ async function getAPI(profile) {
13
+ const googleAuth = await (0, auth_1.getAuth)(profile);
14
+ return googleapis_1.google.calendar({
15
+ version: 'v3',
16
+ auth: googleAuth,
17
+ });
18
+ }
19
+ exports.getAPI = getAPI;
20
+ async function getEvents(profile, args) {
21
+ const api = await calendar_1.default.getAPI(profile);
22
+ return (0, shared_1.getItems)(api.events, args);
23
+ }
24
+ exports.getEvents = getEvents;
25
+ async function setEvent(profile, eventId, args) {
26
+ const api = await calendar_1.default.getAPI(profile);
27
+ api.events.update({ eventId, ...args });
28
+ }
29
+ exports.setEvent = setEvent;
30
+ //# sourceMappingURL=calendar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calendar.js","sourceRoot":"","sources":["../../../src/lib/api/calendar.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoC;AAEpC,kCAAkC;AAClC,qCAAoC;AACpC,0DAAkC;AAGlC,kBAAe,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AAE/C,KAAK,UAAU,MAAM,CAAC,OAAe;IACpC,MAAM,UAAU,GAAG,MAAM,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IAE1C,OAAO,mBAAM,CAAC,QAAQ,CAAC;QACtB,OAAO,EAAG,IAAI;QACd,IAAI,EAAM,UAAU;KACpB,CAAC,CAAC;AACJ,CAAC;AAVQ,wBAAM;AAWf,KAAK,UAAU,SAAS,CAAC,OAAe,EAAE,IAAwD;IACjG,MAAM,GAAG,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,OAAO,IAAA,iBAAQ,EAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC;AAdgB,8BAAS;AAgB1B,KAAK,UAAU,QAAQ,CAAC,OAAe,EAAE,OAA2B,EAAE,IAA0D;IAC/H,MAAM,GAAG,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC;AAnB2B,4BAAQ"}
@@ -0,0 +1,19 @@
1
+ import type GoogleApis from 'googleapis';
2
+ export { getItems };
3
+ declare const _default: {
4
+ getItems: typeof getItems;
5
+ };
6
+ export default _default;
7
+ type CommonApi<TArgs, TResponse> = {
8
+ list: (params: TArgs & {
9
+ pageToken: string | undefined;
10
+ }, options?: GoogleApis.Common.MethodOptions | undefined) => Promise<GoogleApis.Common.GaxiosResponse<TResponse>>;
11
+ };
12
+ type CommonResponse<TItem> = {
13
+ items?: TItem[];
14
+ pageInfo?: {
15
+ totalResults?: number | null | undefined;
16
+ };
17
+ nextPageToken?: string | null | undefined;
18
+ };
19
+ declare function getItems<TApi extends CommonApi<TArgs, TResponse>, TItem, TArgs, TResponse extends CommonResponse<TItem>>(api: TApi, args: TArgs): Promise<TItem[]>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getItems = void 0;
4
+ const logger_1 = require("../logger");
5
+ const sleep_1 = require("../sleep");
6
+ exports.default = { getItems };
7
+ const requestInterval = 300;
8
+ async function getItems(api, args) {
9
+ var _a, _b;
10
+ const items = [];
11
+ let pageToken = undefined;
12
+ do {
13
+ const response = await api.list({ ...args, pageToken });
14
+ (_a = response.data.items) === null || _a === void 0 ? void 0 : _a.forEach((item) => items.push(item));
15
+ (0, logger_1.log)(`Getting items (${items.length} of ${((_b = response.data.pageInfo) === null || _b === void 0 ? void 0 : _b.totalResults) || 'many'})...`);
16
+ pageToken = response.data.nextPageToken;
17
+ await (0, sleep_1.sleep)(requestInterval);
18
+ } while (pageToken);
19
+ return items;
20
+ }
21
+ exports.getItems = getItems;
22
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/lib/api/shared.ts"],"names":[],"mappings":";;;AACA,sCAAgC;AAChC,oCAAiC;AAGjC,kBAAe,EAAE,QAAQ,EAAE,CAAC;AAiB5B,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,KAAK,UAAU,QAAQ,CAKrB,GAAS,EAAE,IAAW;;IACvB,MAAM,KAAK,GAAY,EAAE,CAAC;IAE1B,IAAI,SAAS,GAA8B,SAAS,CAAC;IAErD,GAAG;QACF,MAAM,QAAQ,GAAgD,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACrG,MAAA,QAAQ,CAAC,IAAI,CAAC,KAAK,0CAAE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,IAAA,YAAG,EAAC,kBAAkB,KAAK,CAAC,MAAM,OAAO,CAAA,MAAA,QAAQ,CAAC,IAAI,CAAC,QAAQ,0CAAE,YAAY,KAAI,MAAM,MAAM,CAAC,CAAC;QAC/F,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC;QACxC,MAAM,IAAA,aAAK,EAAC,eAAe,CAAC,CAAC;KAC7B,QAAQ,SAAS,EAAE;IAEpB,OAAO,KAAK,CAAC;AACd,CAAC;AAvCQ,4BAAQ"}
@@ -0,0 +1,9 @@
1
+ import type GoogleApis from 'googleapis';
2
+ export { getAPI, getPlaylistItems };
3
+ declare const _default: {
4
+ getAPI: typeof getAPI;
5
+ getPlaylistItems: typeof getPlaylistItems;
6
+ };
7
+ export default _default;
8
+ declare function getAPI(profile: string): Promise<GoogleApis.youtube_v3.Youtube>;
9
+ declare function getPlaylistItems(profile: string, args: GoogleApis.youtube_v3.Params$Resource$Playlistitems$List): Promise<unknown[]>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getPlaylistItems = exports.getAPI = void 0;
7
+ const googleapis_1 = require("googleapis");
8
+ const auth_1 = require("../auth");
9
+ const shared_1 = require("./shared");
10
+ const youtube_1 = __importDefault(require("./youtube"));
11
+ exports.default = { getAPI, getPlaylistItems };
12
+ async function getAPI(profile) {
13
+ const googleAuth = await (0, auth_1.getAuth)(profile);
14
+ return googleapis_1.google.youtube({
15
+ version: 'v3',
16
+ auth: googleAuth,
17
+ });
18
+ }
19
+ exports.getAPI = getAPI;
20
+ async function getPlaylistItems(profile, args) {
21
+ const api = await youtube_1.default.getAPI(profile);
22
+ return (0, shared_1.getItems)(api.playlistItems, args);
23
+ }
24
+ exports.getPlaylistItems = getPlaylistItems;
25
+ //# sourceMappingURL=youtube.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"youtube.js","sourceRoot":"","sources":["../../../src/lib/api/youtube.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoC;AAEpC,kCAAkC;AAClC,qCAAoC;AACpC,wDAAgC;AAGhC,kBAAe,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;AAE5C,KAAK,UAAU,MAAM,CAAC,OAAe;IACpC,MAAM,UAAU,GAAG,MAAM,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IAE1C,OAAO,mBAAM,CAAC,OAAO,CAAC;QACrB,OAAO,EAAG,IAAI;QACd,IAAI,EAAM,UAAU;KACpB,CAAC,CAAC;AACJ,CAAC;AAVQ,wBAAM;AAYf,KAAK,UAAU,gBAAgB,CAAC,OAAe,EAAE,IAA8D;IAC9G,MAAM,GAAG,GAAG,MAAM,iBAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,IAAA,iBAAQ,EAAC,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC;AAfgB,4CAAgB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anmiles/google-api-wrapper",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Provides quick interface for getting google API data",
5
5
  "keywords": [
6
6
  "google",
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * as calendar from './lib/api/calendar';
2
2
  export * as youtube from './lib/api/youtube';
3
+ export { getItems } from './lib/api/shared';
3
4
  export { createProfile, getProfiles } from './lib/profiles';
4
5
  export { login } from './lib/auth';
@@ -7,11 +7,11 @@ import apiHelpers from './apiHelpers';
7
7
 
8
8
  const original = jest.requireActual('../calendar').default as typeof calendar;
9
9
  jest.mock<Partial<typeof calendar>>('../calendar', () => ({
10
- getAPI : jest.fn().mockImplementation(async () => ({ events : api })),
10
+ getAPI : jest.fn().mockImplementation(async () => ({ calendarList : calendarsAPI, events : eventsAPI })),
11
11
  }));
12
12
 
13
13
  jest.mock<Partial<typeof shared>>('../shared', () => ({
14
- getItems : jest.fn().mockImplementation(async () => events),
14
+ getItems : jest.fn(),
15
15
  }));
16
16
 
17
17
  jest.mock<Partial<typeof fs>>('fs', () => ({
@@ -20,7 +20,7 @@ jest.mock<Partial<typeof fs>>('fs', () => ({
20
20
 
21
21
  jest.mock('googleapis', () => ({
22
22
  google : {
23
- calendar : jest.fn().mockImplementation(() => ({ events : api })),
23
+ calendar : jest.fn().mockImplementation(() => ({ calendarList : calendarsAPI, events : eventsAPI })),
24
24
  },
25
25
  }));
26
26
 
@@ -28,12 +28,27 @@ jest.mock<Partial<typeof auth>>('../../auth', () => ({
28
28
  getAuth : jest.fn().mockImplementation(() => googleAuth),
29
29
  }));
30
30
 
31
+ const getItemsSpy = jest.spyOn(shared, 'getItems');
32
+
31
33
  const profile = 'username';
32
34
 
33
35
  const googleAuth = {
34
36
  setCredentials : jest.fn(),
35
37
  };
36
38
 
39
+ const calendars: Array<{ summary?: string, description?: string, hidden?: boolean }> = [
40
+ { summary : 'calendar 1', description : 'calendar 1 description', hidden : false },
41
+ { summary : 'calendar 2', description : 'calendar 2 description', hidden : undefined },
42
+ { summary : 'calendar 3', description : undefined, hidden : true },
43
+ { summary : 'calendar 4', description : undefined, hidden : undefined },
44
+ ];
45
+
46
+ const calendarsResponse = [
47
+ [ calendars[0], calendars[1] ],
48
+ null,
49
+ [ calendars[2], calendars[3] ],
50
+ ];
51
+
37
52
  const events: Array<{ summary?: string, source?: { url?: string, title?: string} }> = [
38
53
  { summary : 'event 1', source : { title : 'source 1', url : 'https://example.com' } },
39
54
  { summary : 'event 2', source : { title : 'source 2', url : undefined } },
@@ -53,8 +68,8 @@ const pageTokens = [
53
68
  'token2',
54
69
  ];
55
70
 
56
- const api = apiHelpers.getAPI(eventsResponse, pageTokens);
57
- const args = { timeMin : '2010-01-01T00:00:00', timeMax : '2019-12-31T23:59:59' };
71
+ const calendarsAPI = apiHelpers.getAPI(calendarsResponse, pageTokens);
72
+ const eventsAPI = apiHelpers.getAPI(eventsResponse, pageTokens);
58
73
 
59
74
  describe('src/lib/api/calendar', () => {
60
75
  describe('getAPI', () => {
@@ -73,11 +88,43 @@ describe('src/lib/api/calendar', () => {
73
88
  it('should return calendar api', async () => {
74
89
  const result = await original.getAPI(profile);
75
90
 
76
- expect(result).toEqual({ events : api });
91
+ expect(result).toEqual({ calendarList : calendarsAPI, events : eventsAPI });
92
+ });
93
+ });
94
+
95
+ describe('getCalendars', () => {
96
+ const args = { showHidden : true };
97
+
98
+ beforeEach(() => {
99
+ getItemsSpy.mockResolvedValue(calendars);
100
+ });
101
+
102
+ it('should get api', async () => {
103
+ await original.getCalendars(profile, args);
104
+
105
+ expect(calendar.getAPI).toBeCalledWith(profile);
106
+ });
107
+
108
+ it('should get items', async () => {
109
+ await original.getCalendars(profile, args);
110
+
111
+ expect(getItemsSpy).toBeCalledWith(calendarsAPI, args);
112
+ });
113
+
114
+ it('should return calendars', async () => {
115
+ const result = await original.getCalendars(profile, args);
116
+
117
+ expect(result).toEqual(calendars);
77
118
  });
78
119
  });
79
120
 
80
121
  describe('getEvents', () => {
122
+ const args = { timeMin : '2010-01-01T00:00:00', timeMax : '2019-12-31T23:59:59' };
123
+
124
+ beforeEach(() => {
125
+ getItemsSpy.mockResolvedValue(events);
126
+ });
127
+
81
128
  it('should get api', async () => {
82
129
  await original.getEvents(profile, args);
83
130
 
@@ -87,7 +134,7 @@ describe('src/lib/api/calendar', () => {
87
134
  it('should get items', async () => {
88
135
  await original.getEvents(profile, args);
89
136
 
90
- expect(shared.getItems).toBeCalledWith(api, args);
137
+ expect(getItemsSpy).toBeCalledWith(eventsAPI, args);
91
138
  });
92
139
 
93
140
  it('should return events', async () => {
@@ -98,19 +145,19 @@ describe('src/lib/api/calendar', () => {
98
145
  });
99
146
 
100
147
  describe('setEvent', () => {
101
- const eventId = 'eventId';
102
- const updateArgs = { requestBody : { summary : 'summary' } };
148
+ const eventId = 'eventId';
149
+ const args = { requestBody : { summary : 'summary' } };
103
150
 
104
151
  it('should get api', async () => {
105
- await original.setEvent(profile, eventId, updateArgs);
152
+ await original.setEvent(profile, eventId, args);
106
153
 
107
154
  expect(calendar.getAPI).toBeCalledWith(profile);
108
155
  });
109
156
 
110
157
  it('should set items', async () => {
111
- await original.setEvent(profile, eventId, updateArgs);
158
+ await original.setEvent(profile, eventId, args);
112
159
 
113
- expect(api.update).toBeCalledWith({ eventId, ...updateArgs });
160
+ expect(eventsAPI.update).toBeCalledWith({ eventId, ...args });
114
161
  });
115
162
  });
116
163
  });
@@ -7,11 +7,11 @@ import apiHelpers from './apiHelpers';
7
7
 
8
8
  const original = jest.requireActual('../youtube').default as typeof youtube;
9
9
  jest.mock<Partial<typeof youtube>>('../youtube', () => ({
10
- getAPI : jest.fn().mockImplementation(async () => ({ playlistItems : api })),
10
+ getAPI : jest.fn().mockImplementation(async () => ({ playlistItems : playlistItemsAPI })),
11
11
  }));
12
12
 
13
13
  jest.mock<Partial<typeof shared>>('../shared', () => ({
14
- getItems : jest.fn().mockImplementation(async () => playlistItems),
14
+ getItems : jest.fn(),
15
15
  }));
16
16
 
17
17
  jest.mock<Partial<typeof fs>>('fs', () => ({
@@ -20,7 +20,7 @@ jest.mock<Partial<typeof fs>>('fs', () => ({
20
20
 
21
21
  jest.mock('googleapis', () => ({
22
22
  google : {
23
- youtube : jest.fn().mockImplementation(() => ({ playlistItems : api })),
23
+ youtube : jest.fn().mockImplementation(() => ({ playlistItems : playlistItemsAPI })),
24
24
  },
25
25
  }));
26
26
 
@@ -28,6 +28,8 @@ jest.mock<Partial<typeof auth>>('../../auth', () => ({
28
28
  getAuth : jest.fn().mockImplementation(() => googleAuth),
29
29
  }));
30
30
 
31
+ const getItemsSpy = jest.spyOn(shared, 'getItems');
32
+
31
33
  const profile = 'username';
32
34
 
33
35
  const googleAuth = {
@@ -53,8 +55,7 @@ const pageTokens = [
53
55
  'token2',
54
56
  ];
55
57
 
56
- const api = apiHelpers.getAPI(playlistItemsResponse, pageTokens);
57
- const args = { playlistId : 'LL', part : [ 'snippet' ], maxResults : 50 };
58
+ const playlistItemsAPI = apiHelpers.getAPI(playlistItemsResponse, pageTokens);
58
59
 
59
60
  describe('src/lib/api/youtube', () => {
60
61
  describe('getAPI', () => {
@@ -73,11 +74,17 @@ describe('src/lib/api/youtube', () => {
73
74
  it('should return youtube api', async () => {
74
75
  const result = await original.getAPI(profile);
75
76
 
76
- expect(result).toEqual({ playlistItems : api });
77
+ expect(result).toEqual({ playlistItems : playlistItemsAPI });
77
78
  });
78
79
  });
79
80
 
80
81
  describe('getPlaylistItems', () => {
82
+ const args = { playlistId : 'LL', part : [ 'snippet' ], maxResults : 50 };
83
+
84
+ beforeEach(() => {
85
+ getItemsSpy.mockResolvedValue(playlistItems);
86
+ });
87
+
81
88
  it('should get api', async () => {
82
89
  await original.getPlaylistItems(profile, args);
83
90
 
@@ -87,7 +94,7 @@ describe('src/lib/api/youtube', () => {
87
94
  it('should call getItems', async () => {
88
95
  await original.getPlaylistItems(profile, args);
89
96
 
90
- expect(shared.getItems).toBeCalledWith(api, args);
97
+ expect(getItemsSpy).toBeCalledWith(playlistItemsAPI, args);
91
98
  });
92
99
 
93
100
  it('should return videos', async () => {
@@ -4,8 +4,8 @@ import { getAuth } from '../auth';
4
4
  import { getItems } from './shared';
5
5
  import calendar from './calendar';
6
6
 
7
- export { getAPI, getEvents, setEvent };
8
- export default { getAPI, getEvents, setEvent };
7
+ export { getAPI, getEvents, getCalendars, setEvent };
8
+ export default { getAPI, getEvents, getCalendars, setEvent };
9
9
 
10
10
  async function getAPI(profile: string): Promise<GoogleApis.calendar_v3.Calendar> {
11
11
  const googleAuth = await getAuth(profile);
@@ -15,6 +15,12 @@ async function getAPI(profile: string): Promise<GoogleApis.calendar_v3.Calendar>
15
15
  auth : googleAuth,
16
16
  });
17
17
  }
18
+
19
+ async function getCalendars(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Calendarlist$List) {
20
+ const api = await calendar.getAPI(profile);
21
+ return getItems(api.calendarList, args);
22
+ }
23
+
18
24
  async function getEvents(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Events$List) {
19
25
  const api = await calendar.getAPI(profile);
20
26
  return getItems(api.events, args);
@@ -1,23 +0,0 @@
1
- import type GoogleApis from 'googleapis';
2
- export { getEvents, getVideos };
3
- declare const _default: {
4
- getData: typeof getData;
5
- getEvents: typeof getEvents;
6
- getVideos: typeof getVideos;
7
- };
8
- export default _default;
9
- type CommonApi<TArgs, TResponse> = {
10
- list: (params: TArgs & {
11
- pageToken: string | undefined;
12
- }, options?: GoogleApis.Common.MethodOptions | undefined) => Promise<GoogleApis.Common.GaxiosResponse<TResponse>>;
13
- };
14
- type CommonResponse<TItem> = {
15
- items?: TItem[];
16
- pageInfo?: {
17
- totalResults?: number | null | undefined;
18
- };
19
- nextPageToken?: string | null | undefined;
20
- };
21
- declare function getData<TApi extends CommonApi<TArgs, TResponse>, TItem, TArgs, TResponse extends CommonResponse<TItem>>(api: TApi, args: TArgs): Promise<TItem[]>;
22
- declare function getEvents(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Events$List): Promise<GoogleApis.calendar_v3.Schema$Event[]>;
23
- declare function getVideos(profile: string, args: GoogleApis.youtube_v3.Params$Resource$Playlistitems$List): Promise<GoogleApis.youtube_v3.Schema$PlaylistItem[]>;
package/dist/lib/data.js DELETED
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getVideos = exports.getEvents = void 0;
7
- const googleapis_1 = require("googleapis");
8
- const auth_1 = require("./auth");
9
- const data_1 = __importDefault(require("./data"));
10
- const logger_1 = require("./logger");
11
- const sleep_1 = require("./sleep");
12
- exports.default = { getData, getEvents, getVideos };
13
- const requestInterval = 300;
14
- async function getData(api, args) {
15
- var _a, _b;
16
- const items = [];
17
- let pageToken = undefined;
18
- do {
19
- const response = await api.list({ ...args, pageToken });
20
- (_a = response.data.items) === null || _a === void 0 ? void 0 : _a.forEach((item) => items.push(item));
21
- (0, logger_1.log)(`Getting items (${items.length} of ${((_b = response.data.pageInfo) === null || _b === void 0 ? void 0 : _b.totalResults) || 'many'})...`);
22
- pageToken = response.data.nextPageToken;
23
- await (0, sleep_1.sleep)(requestInterval);
24
- } while (pageToken);
25
- return items;
26
- }
27
- async function getEvents(profile, args) {
28
- const googleAuth = await (0, auth_1.getAuth)(profile);
29
- const { events } = googleapis_1.google.calendar({
30
- version: 'v3',
31
- auth: googleAuth,
32
- });
33
- return data_1.default.getData(events, args);
34
- }
35
- exports.getEvents = getEvents;
36
- async function getVideos(profile, args) {
37
- const googleAuth = await (0, auth_1.getAuth)(profile);
38
- const { playlistItems } = googleapis_1.google.youtube({
39
- version: 'v3',
40
- auth: googleAuth,
41
- });
42
- return data_1.default.getData(playlistItems, args);
43
- }
44
- exports.getVideos = getVideos;
45
- //# sourceMappingURL=data.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/lib/data.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoC;AAEpC,iCAAiC;AACjC,kDAA0B;AAC1B,qCAA+B;AAC/B,mCAAgC;AAGhC,kBAAe,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;AAiBjD,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,KAAK,UAAU,OAAO,CAKpB,GAAS,EAAE,IAAW;;IACvB,MAAM,KAAK,GAAY,EAAE,CAAC;IAE1B,IAAI,SAAS,GAA8B,SAAS,CAAC;IAErD,GAAG;QACF,MAAM,QAAQ,GAAgD,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACrG,MAAA,QAAQ,CAAC,IAAI,CAAC,KAAK,0CAAE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,IAAA,YAAG,EAAC,kBAAkB,KAAK,CAAC,MAAM,OAAO,CAAA,MAAA,QAAQ,CAAC,IAAI,CAAC,QAAQ,0CAAE,YAAY,KAAI,MAAM,MAAM,CAAC,CAAC;QAC/F,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC;QAExC,MAAM,IAAA,aAAK,EAAC,eAAe,CAAC,CAAC;KAC7B,QAAQ,SAAS,EAAE;IAEpB,OAAO,KAAK,CAAC;AACd,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,OAAe,EAAE,IAAwD;IACjG,MAAM,UAAU,GAAG,MAAM,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IAE1C,MAAM,EAAE,MAAM,EAAE,GAAG,mBAAM,CAAC,QAAQ,CAAC;QAClC,OAAO,EAAG,IAAI;QACd,IAAI,EAAM,UAAU;KACpB,CAAC,CAAC;IAEH,OAAO,cAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC;AAnDQ,8BAAS;AAqDlB,KAAK,UAAU,SAAS,CAAC,OAAe,EAAE,IAA8D;IACvG,MAAM,UAAU,GAAG,MAAM,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IAE1C,MAAM,EAAE,aAAa,EAAE,GAAG,mBAAM,CAAC,OAAO,CAAC;QACxC,OAAO,EAAG,IAAI;QACd,IAAI,EAAM,UAAU;KACpB,CAAC,CAAC;IAEH,OAAO,cAAI,CAAC,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC;AA9DmB,8BAAS"}