Skip to content

Instantly share code, notes, and snippets.

@firoze firoze/instaService
Last active Aug 29, 2015

Embed
What would you like to do?
Cordova Instagram wrapper
angular.module("ycf").factory("ycfInstagram", function($q, social, groupVerification, loadingDialog, validationAlert, $ionicPopup) {
var insta = {};
insta.msg = "Support my YC Fundraiser!";
insta.post = function(type) {
if (type == "marketing") {
return insta.market();
} else {
return insta.invite();
}
};
insta.invite = function() {
insta.msg = insta.cleanMsg(social.messages.invite.instagram);
return insta.share(insta.msg);
};
insta.market = function() {
insta.msg = insta.cleanMsg(social.messages.marketing.instagram);
insta.share(insta.msg);
};
insta.cleanMsg = function(msg) {
return
insta.msg
.replace("GROUPNAME", groupVerification.currentGroup.groupName)
.replace("GROUPNUMBER", groupVerification.currentGroup.id);;
};
insta.share = function(msg) {
var dfd = $q.defer();
Instagram.isInstalled(function (err, installed) {
if (installed) {
var img = new Image();
img.src = "img/ycf-insta.png";
img.onload = function () {
var canvas = document.createElement("canvas");
canvas.width = this.width;
canvas.height = this.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(this, 0, 0);
var dataURL = canvas.toDataURL("image/png");
loadingDialog.hide();
Instagram.share(dataURL, msg, function (err) {
$q.resolve();
// callback for Instagram.share doesn't matter because Instagram app stopped returning results
// https://github.com/vstirbu/InstagramPlugin/issues/31
/*if (callback) {
callback();
}*/
});
};
} else {
loadingDialog.hide();
$ionicPopup.alert({
title: "Error",
template: "The Instagram app is not installed."
}).then(function() {
$q.resolve();
});
}
});
return dfd.promise;
};
return insta;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.