Skip to content

Commit

Permalink
refactor: (1.2.0 release) Remove Ads and getPlatform features
Browse files Browse the repository at this point in the history
These features aren't part of the release scope for v1.2.0, so removing them for that release.
  • Loading branch information
corycaywood committed Oct 2, 2020
1 parent c8bfe3a commit 0be954a
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 365 deletions.
67 changes: 0 additions & 67 deletions js-miniapp-bridge/src/common-bridge.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/* tslint:disable:no-any */

import {
AdTypes,
InterstitialAdResponse,
CustomPermission,
CustomPermissionResult,
RewardedAdResponse,
ShareInfoType,
} from 'js-miniapp-sdk';

Expand Down Expand Up @@ -113,70 +110,6 @@ export class MiniAppBridge {
});
}

/**
* Associating showInterstitialAd function to MiniAppBridge object
* @param {string} id ad unit id of the intertitial ad
*/
showInterstitialAd(id: string) {
return new Promise<InterstitialAdResponse>((resolve, reject) => {
return this.executor.exec(
'showAd',
{ adType: AdTypes.INTERSTITIAL, adUnitId: id },
adResponse => resolve(JSON.parse(adResponse) as InterstitialAdResponse),
error => reject(error)
);
});
}

/**
* Associating loadInterstitialAd function to MiniAppBridge object.
* This function preloads interstitial ad before they are requested for display.
* Can be called multiple times to pre-load multiple ads.
* @param {string} id ad unit id of the intertitial ad that needs to be loaded.
*/
loadInterstitialAd(id: string) {
return new Promise<null | Error>((resolve, reject) => {
return this.executor.exec(
'loadAd',
{ adType: AdTypes.INTERSTITIAL, adUnitId: id },
loadResponse => resolve(JSON.parse(loadResponse) as null | Error),
error => reject(error)
);
});
}

/**
* Associating loadRewardedAd function to MiniAppBridge object.
* This function preloads Rewarded ad before they are requested for display.
* Can be called multiple times to pre-load multiple ads.
* @param {string} id ad unit id of the Rewarded ad that needs to be loaded.
*/
loadRewardedAd(id: string) {
return new Promise<null | Error>((resolve, reject) => {
return this.executor.exec(
'loadAd',
{ adType: AdTypes.REWARDED, adUnitId: id },
loadResponse => resolve(JSON.parse(loadResponse) as null | Error),
error => reject(error)
);
});
}

/**
* Associating showRewardedAd function to MiniAppBridge object
* @param {string} id ad unit id of the Rewarded ad
*/
showRewardedAd(id: string) {
return new Promise<RewardedAdResponse>((resolve, reject) => {
return this.executor.exec(
'showAd',
{ adType: AdTypes.REWARDED, adUnitId: id },
adResponse => resolve(JSON.parse(adResponse) as RewardedAdResponse),
error => reject(error)
);
});
}

/**
* Associating requestCustomPermissions function to MiniAppBridge object
* @param [CustomPermissionType[] permissionTypes, Types of custom permissions that are requested
Expand Down
28 changes: 1 addition & 27 deletions js-miniapp-bridge/test/test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
AdTypes,
CustomPermissionName,
CustomPermissionStatus,
} from 'js-miniapp-sdk';
import { CustomPermissionName, CustomPermissionStatus } from 'js-miniapp-sdk';
import * as Bridge from '../src/common-bridge';
import { expect } from 'chai';
import sinon, { mock } from 'sinon';
Expand Down Expand Up @@ -71,28 +67,6 @@ describe('execErrorCallback', () => {
});
});

describe('showRewardedAd', () => {
it('will parse the RewardedAdResponse JSON response', () => {
const bridge = new Bridge.MiniAppBridge(mockExecutor);
mockExecutor.exec.callsArgWith(2, '{ "adType": 1 }');

return expect(bridge.showRewardedAd('test_id')).to.eventually.deep.equal({
adType: AdTypes.REWARDED,
});
});
});

describe('showInterstitialAd', () => {
it('will parse the InterstitialAdResponse JSON response', () => {
const bridge = new Bridge.MiniAppBridge(mockExecutor);
mockExecutor.exec.callsArgWith(2, '{ "adType": 0 }');

return expect(
bridge.showInterstitialAd('test_id')
).to.eventually.deep.equal({ adType: AdTypes.INTERSTITIAL });
});
});

describe('requestCustomPermissions', () => {
const requestPermissions = [
{ name: CustomPermissionName.USER_NAME, description: 'test_description' },
Expand Down
42 changes: 1 addition & 41 deletions js-miniapp-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,47 +108,7 @@ miniApp.requestCustomPermissions([
});
```
### 4. Show Ads
Mini App SDK allows you to display ads upon requesting from a Mini App with an ad unit id.
This requires you to first load an Ad by passing an ID. You can then display an Ad in the Ad Unit by passing the same ID which was used for loading.
Note that typically you should load your Ads at some point earlier than you intend to use them, such as at App launch time. You can also pre-load multiple Ads by calling `MiniApp.loadInterstialAd` or `MiniApp.loadRewardedAd` multiple times.
Currently two ad types are supported,
1. Interstitial
2. Rewarded
**Interstitial**
The results of the display `Interstitial` ad action is captured as [InterstitialAdResponse](src/types/responseTypes/interstitial/index.ts).
```javascript
const adUnitID = 'xxx-xxx-xxxxxxxxxxxxx';

miniApp.loadInterstitialAd(adUnitID)
.then(response => {
miniApp.showInterstitialAd(adUnitID)
.then(response => console.log(response) )
.catch( error => console.error(response) );
})
.catch( error => console.error(response) );
```
**Rewarded**
The results of the display `Reward` ad action is captured as [RewardedAdResponse](src/types/responseTypes/rewarded/index.ts).
```javascript
const adUnitID = 'xxx-xxx-xxxxxxxxxxxxx';

miniApp.loadRewardedAd(adUnitID)
.then(response => {
miniApp.showRewardedAd(adUnitID)
.then(response => console.log(response) )
.catch( error => console.error(response) );
})
.catch( error => console.error(response) );
```
### 5. Share Info
### 4. Share Info
It is possible for the mini app user to share the mini app data across Android/iOS interface. The data format must match the [ShareInfoType](src/types/ShareInfoType.ts).
Expand Down
6 changes: 0 additions & 6 deletions js-miniapp-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
*/

import { MiniApp } from './miniapp';
import { AdTypes } from './types/adTypes';
import { InterstitialAdResponse } from './types/responseTypes/interstitial';
import { RewardedAdResponse } from './types/responseTypes/rewarded';
import { ShareInfoType } from './types/ShareInfoType';
import {
CustomPermission,
Expand All @@ -21,12 +18,9 @@ const miniAppInstance = new MiniApp();

export default miniAppInstance;
export {
AdTypes,
InterstitialAdResponse,
CustomPermission,
CustomPermissionName,
CustomPermissionStatus,
CustomPermissionResult,
RewardedAdResponse,
ShareInfoType,
};
60 changes: 1 addition & 59 deletions js-miniapp-sdk/src/miniapp.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { InterstitialAdResponse } from './types/responseTypes/interstitial';
import {
CustomPermission,
CustomPermissionResult,
} from './types/CustomPermission';
import { DevicePermission } from './types/DevicePermission';
import { RewardedAdResponse } from './types/responseTypes/rewarded';
import { ShareInfoType } from './types/ShareInfoType';

/**
Expand Down Expand Up @@ -37,48 +35,8 @@ interface MiniAppFeatures {
shareInfo(info: ShareInfoType): Promise<string>;
}

/**
* A contract declaring the interaction mechanism between mini-apps and native host app to display ads.
*/
interface Ad {
/**
* Loads the specified Interstittial Ad Unit ID.
* Can be called multiple times to pre-load multiple ads.
* Promise is resolved when successfully loaded.
* @returns The Promise of load ad response result from injected side.
* Promise is rejected if failed to load.
*/
loadInterstitialAd(id: string): Promise<null | Error>;

/**
* Loads the specified Rewarded Ad Unit ID.
* Can be called multiple times to pre-load multiple ads.
* Promise is resolved when successfully loaded.
* * @returns The Promise of load ad response result from injected side.
* Promise is rejected if failed to load.
*/
loadRewardedAd(id: string): Promise<null | Error>;

/**
* Shows the Interstitial Ad for the specified ID.
* Promise is resolved after the user closes the Ad.
* @returns The Promise of Interstitial ad response result from injected side.
* Promise is rejected if the Ad failed to display wasn't loaded first using MiniApp.loadRewardedAds.
*/
showInterstitialAd(id: string): Promise<InterstitialAdResponse>;

/**
* Shows the Rewarded Ad for the specified ID.
* Promise is resolved with an object after the user closes the Ad. The object contains the reward earned by the user.
* Reward will be null if the user did not earn the reward.
* @returns The Promise of Rewarded ad response result from injected side.
* Promise is rejected if the Ad failed to display wasn't loaded first using MiniApp.loadRewardedAds.
*/
showRewardedAd(id: string): Promise<RewardedAdResponse>;
}

/* tslint:disable:no-any */
export class MiniApp implements MiniAppFeatures, Ad {
export class MiniApp implements MiniAppFeatures {
private requestPermission(permissionType: string): Promise<string> {
return (window as any).MiniAppBridge.requestPermission(permissionType);
}
Expand All @@ -99,22 +57,6 @@ export class MiniApp implements MiniAppFeatures, Ad {
).then(permissionResult => permissionResult.permissions);
}

loadInterstitialAd(id: string): Promise<null | Error> {
return (window as any).MiniAppBridge.loadInterstitialAd(id);
}

loadRewardedAd(id: string): Promise<null | Error> {
return (window as any).MiniAppBridge.loadRewardedAd(id);
}

showInterstitialAd(id: string): Promise<InterstitialAdResponse> {
return (window as any).MiniAppBridge.showInterstitialAd(id);
}

showRewardedAd(id: string): Promise<RewardedAdResponse> {
return (window as any).MiniAppBridge.showRewardedAd(id);
}

shareInfo(info: ShareInfoType): Promise<string> {
return (window as any).MiniAppBridge.shareInfo(info);
}
Expand Down
8 changes: 0 additions & 8 deletions js-miniapp-sdk/src/types/adTypes/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions js-miniapp-sdk/src/types/responseTypes/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions js-miniapp-sdk/src/types/responseTypes/interstitial/index.ts

This file was deleted.

16 changes: 0 additions & 16 deletions js-miniapp-sdk/src/types/responseTypes/rewarded/index.ts

This file was deleted.

Loading

0 comments on commit 0be954a

Please sign in to comment.