Skip to content

Commit

Permalink
feat(instagram): add instagram sharing plugin (#453)
Browse files Browse the repository at this point in the history
Closes #307
  • Loading branch information
mattlewis92 authored and ihadeed committed Aug 19, 2016
1 parent 14e41a3 commit f3e698f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { ImagePicker } from './plugins/imagepicker';
import { ImageResizer } from './plugins/imageresizer';
import { InAppBrowser } from './plugins/inappbrowser';
import { Insomnia } from './plugins/insomnia';
import { Instagram } from './plugins/instagram';
import { Keyboard } from './plugins/keyboard';
import { LaunchNavigator } from './plugins/launchnavigator';
import { LocalNotifications } from './plugins/localnotifications';
Expand Down Expand Up @@ -151,6 +152,7 @@ export {
GoogleAnalytics,
Hotspot,
Insomnia,
Instagram,
Keyboard,
NativeAudio,
NativeStorage,
Expand Down Expand Up @@ -225,6 +227,7 @@ window['IonicNative'] = {
ImagePicker: ImagePicker,
ImageResizer: ImageResizer,
InAppBrowser: InAppBrowser,
Instagram: Instagram,
Keyboard: Keyboard,
LaunchNavigator: LaunchNavigator,
LocalNotifications: LocalNotifications,
Expand Down
57 changes: 57 additions & 0 deletions src/plugins/instagram.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {Plugin, Cordova} from './plugin';

/**
* @name Instagram
* @description Share a photo with the instagram app
*
* @usage
* ```
* import {Instagram} from 'ionic-native';
*
* Instagram.share('data:image/png;uhduhf3hfif33', 'Caption')
* .then(() => console.log('Shared!'))
* .catch((error: any) => console.error(error));
*
* ```
*/
@Plugin({
plugin: 'cordova-instagram-plugin',
pluginRef: 'Instagram',
repo: 'https://github.com/vstirbu/InstagramPlugin'
})
export class Instagram {

/**
* Detect if the Instagram application is installed on the device.
*
* @return {Promise<boolean|string>} Returns a promise that returns a boolean value if installed, or the app version on android
*/
@Cordova({
callbackStyle: 'node'
})
static isInstalled(): Promise<boolean|string> {return;}

/**
* Share an image on Instagram
* Note: Instagram app stopped accepting pre-filled captions on both iOS and Android. As a work-around, the caption is copied to the clipboard. You have to inform your users to paste the caption.
*
* @param canvasIdOrDataUrl The canvas element id or the dataURL of the image to share
* @param caption The caption of the image
* @return {Promise<any>} Returns a promise that resolves if the image was shared
*/
@Cordova({
callbackStyle: 'node'
})
static share(canvasIdOrDataUrl: string, caption?: string): Promise<any> {return;}

/**
* Share a library asset or video
* @param assetLocalIdentifier A local fileURI
* @return {Promise<any>} Returns a promise that resolves if the image was shared
*/
@Cordova({
callbackOrder: 'reverse'
})
static shareAsset(assetLocalIdentifier: string): Promise<any> {return;}

}
8 changes: 8 additions & 0 deletions src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ function setIndex(args: any[], opts: any = {}, resolve?: Function, reject?: Func
// Get those arguments in the order [resolve, reject, ...restOfArgs]
args.unshift(reject);
args.unshift(resolve);
} else if (opts.callbackStyle === 'node') {
args.push((err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
});
} else if (typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') {
// If we've specified a success/error index
args.splice(opts.successIndex, 0, resolve);
Expand Down

0 comments on commit f3e698f

Please sign in to comment.