aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/feeds/feeds-command.ts
blob: 3c95f95363bf05c0ee02079428e1685aec367d4f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { HttpStatusCode } from '@shared/models'
import { AbstractCommand, OverrideCommandOptions } from '../shared'

type FeedType = 'videos' | 'video-comments' | 'subscriptions'

export class FeedCommand extends AbstractCommand {

  getXML (options: OverrideCommandOptions & {
    feed: FeedType
    format?: string
  }) {
    const { feed, format } = options
    const path = '/feeds/' + feed + '.xml'

    return this.getRequestText({
      ...options,

      path,
      query: format ? { format } : undefined,
      accept: 'application/xml',
      implicitToken: false,
      defaultExpectedStatus: HttpStatusCode.OK_200
    })
  }

  getJSON (options: OverrideCommandOptions & {
    feed: FeedType
    query?: { [ id: string ]: any }
  }) {
    const { feed, query } = options
    const path = '/feeds/' + feed + '.json'

    return this.getRequestText({
      ...options,

      path,
      query,
      accept: 'application/json',
      implicitToken: false,
      defaultExpectedStatus: HttpStatusCode.OK_200
    })
  }
}