This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am downes on github. | |
* I am downes (https://keybase.io/downes) on keybase. | |
* I have a public key whose fingerprint is 2DDC 6D6B CD3C AC38 918F CF7B 6815 A072 C592 2E94 | |
To claim this, I am signing this object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gRSShopper::Badgr; | |
use strict; | |
use warnings; | |
use HTTP::Request::Common qw(POST); | |
use LWP::UserAgent; | |
use JSON qw(encode_json decode_json); | |
our $VERSION = "1.00"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub generate_access_token { | |
my ($self) = @_; | |
my $access_token_url = $self->{badgr_url}."/o/token"; | |
my $ua = LWP::UserAgent->new; | |
my $req = POST $access_token_url,[ username => $self->{badgr_account}, password => $self->{badgr_password} ]; | |
my $response = $ua->request($req); | |
if ($response->is_success) { | |
my $hashref = decode_json $response->decoded_content; | |
$self->{access_token} = $hashref->{access_token}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initialize Badgr | |
our $Badgr = gRSShopper::Badgr->new({ | |
badgr_url => $Site->{badgr_url}, | |
badgr_account => $Site->{badgr_account}, | |
badgr_password => $Site->{badgr_password}, | |
badgr_issuerid => $Site->{badgr_issuerid}, | |
secure => 1, # Turns on SSH | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$content .= &admin_configtable($dbh,$query,"Badgr", | |
("Badgr API base URL:badgr_url","Badgr Account ID (email):badgr_account","Badgr Account Password:badgr_password","Access Key:badgr_cckey","Issuer ID:badgr_issuerid")); | |
$content .= sprintf(qq|To create and award badges, <a href="https://badgr.io/auth/login">create a Badgr account</a> and input email address and password above. The Base URL is usually https://api.badgr.io and the Access key is automatically generated. | |
However, before badges are awarded, a Badge Issuer must be created; <a href="%sadmin.cgi?action=badgr&badgr=issuer">Click here</a> to generate an Issuer | |
automatically.|,$Site->{st_cgi}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create Request JSON | |
my $issuer_json = qq|{ | |
"name": "$issuer->{name}", | |
"email": "$issuer->{email}", | |
"description": "$issuer->{description}", | |
"url": "$issuer->{url}" | |
}|; | |
# Format Request | |
my $create_issuer_url = $self->{badgr_url}."/v2/issuers"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $badge_json = qq| | |
{"criteriaUrl":"$badge->{criteriaUrl}", | |
"issuer":"$self->{badgr_issuerid}", | |
"name":"$badge->{badge_title}", | |
"image":"$badge->{image}", | |
"description":"$badge->{badge_description}", | |
"alignments": [ | |
{"targetName":"Testing", | |
"targetUrl":"$badge->{criteriaUrl}", | |
"targetDescription":"$badge->{badge_description}", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ($filerecord->{file_dirname} eq "image/png") { | |
my $imgfilename = $Site->{st_urlf}.$filerecord->{file_dirname}; | |
use File::Slurp; | |
use MIME::Base64 qw|encode_base64|; | |
$imagestr = encode_base64( read_file( $imgfilename ) ); | |
$imagestr =~ s/\n//g;$imagestr =~ s/\n//g; # because they get inserted somehow and Badgr chokes on them | |
$imagestr = "data:image/png;base64,".$imagestr; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Button --> | |
<span class="nav-link" style="cursor:pointer" data-toggle="modal" data-target="#exampleModal"><img src="https://www.downes.ca/assets/icons/grssicon.JPG" alt="Open Reader" title="Open Reader" width="20" border="0"></span> | |
<!-- Modal --> | |
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> | |
<div class="modal-dialog" role="document"> | |
<div class="modal-content"> | |
<div class="modal-header"> | |
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5> | |
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
@media (min-width: 768px) { | |
.modal-xl { | |
width: 90%; | |
max-width:1200px; | |
} | |
} | |
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> | |
<div class="modal-dialog modal-xl" role="document"><!-- cf http://output.jsbin.com/yefas/1 --> |
OlderNewer