aboutsummaryrefslogblamecommitdiffhomepage
path: root/shared/extra-utils/feeds/feeds.ts
blob: 012ce6cfedd7add4a200a0954f44a1d92f5386be (plain) (tree)
1
2
3
4
5
6
7
8
 
                                                                                  
                                                                   
 
                                                             
 
                                                  
 





                                             
 

                                
 












                                                  
 

                                
 





                                                  
 
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
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',
      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',
      defaultExpectedStatus: HttpStatusCode.OK_200
    })
  }
}