Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

OpenBadges.issue() should be able to take a string or an array #167

Closed
Rudloff opened this Issue · 3 comments

3 participants

@Rudloff

One of my projects uses badges. When the user clicks on one of his badges, he can import it to its backpack.
But, when I click on a badge, it says "You are about to submit 65 badges" (!?).
If I click "Cool, let's go!", the popup becomes blank and nothing happens.

Here is the output of the console:

Horodatage : 17/05/2012 19:27:13
Erreur : assertions.pop is not a function
Fichier Source : http://beta.openbadges.org/js/issuer-frame.js
Ligne : 446

Using Firebug, I also noticed this:

"NetworkError: 404 Not Found - http://beta.openbadges.org/issuer/%5B%5Bassertion.badge.image%5D%5D"
"NetworkError: 400 Bad Request - http://beta.openbadges.org/issuer/assertion?url=1"

Here is my JS code:

/*global $, OpenBadges*/
var i;
function getUrlVars() {
    "use strict";
    var vars, parts;
    vars = {};
    parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}
var GET = getUrlVars();

var issueBadge = function (e) {
    "use strict";
    var type = e.target.getAttribute("data-type") || e.target.parentNode.getAttribute("data-type");
    OpenBadges.issue("http://strasweb.fr/projets/assoquest/assertion.php?badge=" + type + "&user=" + GET.user);
};

var getBadges = function () {
    "use strict";
    $(".badge").bind("vclick", issueBadge);
};

$(document).bind("pageinit", getBadges);

And here is one of my assertions:
http://strasweb.fr/projets/assoquest/assertion.php?badge=1&user=1

Am I doing something wrong?

@brianloveswords

Hi!

OpenBadges.issue takes an array as a first param so it can accept multiple badges at once. Your code should read

    OpenBadges.issue(["http://strasweb.fr/projets/assoquest/assertion.php?badge=" + type + "&user=" + GET.user]);

That's why you're getting 65 badges:

"http://strasweb.fr/projets/assoquest/assertion.php?badge=1&user=1".length === 65

You can fix this now by passing in an array, but I'm leaving this open because it's bad behavior for the API to not take a string when there is a single badge being issued.

@brianloveswords brianloveswords referenced this issue from a commit
@brianloveswords brianloveswords Allow strings & arrays for first param of `issue` API .
Addresses issue #167. When a string was being passed in before, it would
not immediately fail and instead see it as an array with `"string".length`
members which is dumb and wrong. Instead of making it error, I Just made
it more lenient so that the first argument can be a string or an array.
5a97e69
@Rudloff

Oh yes, it works with an array, sorry about that.

@stenington
Owner

I believe this is fixed.

@stenington stenington closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.