import { Injectable } from '@angular/core' ; import { Client } from '../../services/api/client' ; @ Injectable ( ) export class PlusService { protected cachedResponse : any ; constructor ( protected client ) { } async isActive ( ) { const result = await this . client . get ( 'api/v1/plus' ) ; if ( ! result || typeof result . active === 'undefined' ) { throw new Error ( 'Unable to check your Plus status' ) ; } this . cachedResponse = result ; return Boolean ( result . active ) ; } async canBeCancelled ( ) { if ( ! this . cachedResponse ) { await this . isActive ( ) ; } return Boolean ( this . cachedResponse . can_be_cancelled ) ; } async hasSubscription ( ) { if ( ! this . cachedResponse ) { await this . isActive ( ) ; } return Boolean ( this . cachedResponse . has_subscription ) ; } async expires ( ) { if ( ! this . cachedResponse ) { await this . isActive ( ) ; } return Number ( this . cachedResponse . expires ) || 0 ; } async disable ( ) { await this . client . delete ( 'api/v1/plus/subscription' ) ; return true ; } }