Delivering Faculty Interests & Badges
DOCUMENTATION
VERSION HISTORY
The Affinity web service gives information acknowledging and celebrating teaching interests and accomplishments and helps promote faculty community and networking. This information is derived from the Research and Graduate Studies and faculty submitted information using Scholarship. The web service provides a gateway to access the information via a REST-ful API. The information is retrieved by creating a specific URI and giving values to filter the data. The information that is returned is a JSON object that contains a set of interest or badges attached to a particular member; the format of the JSON object is as follows:
{
"success": "true",
"status": 200,
"api": "affinity",
"version": "1.0",
"collection": "badges",
"count": 2,
"badges": [
{
"name": "Probationary Faculty Grant",
"issuer": "Faculty Development",
"url_image": "https://cdn.metalab.csun.edu/badges/FacDev.png",
"url_web": "https://www.csun.edu/undergraduate-studies/faculty-development/probationary-faculty-support-program",
"award_date": "2014"
},
{
"name": "Teaching Conference Grant",
"issuer": "Faculty Development",
"url_image": "https://cdn.metalab.csun.edu/badges/FacDev.png",
"url_web": "https://www.csun.edu/undergraduate-studies/faculty-development/competition-attending-teaching-conference",
"award_date": "Fall 2015"
}
]
}
Loop through the data to display its information. See the Usage Example session.
//construct a function to get url and iterate over
$(document).ready(function() {
//generate a url
var url = 'https://www.csun.edu/web-dev/api/affinity/1.0/badges?email=nr_steven.fitzgerald@csun.edu';
//use the URL as a request
$.ajax({
url: url
}).done(function(data) {
// save the degree list
var badgeList = data.badges;
//iterate over the degree list
$(badgeList).each(function(index, badge) {
//append each degree and institute
$('#badge-results').append(''+ badge.name + '
by: ' + badge.issuer + '
');
});
});
});
//generate a url
$url = 'https://www.csun.edu/web-dev/api/affinity/1.0/badges?email=nr_steven.fitzgerald@csun.edu';
//add extra necessary options
$arrContextOptions = [
"ssl" => [
"verify_peer"=>false,
"verify_peer_name"=>false
]
];
//perform the query
$data = file_get_contents($url, false, stream_context_create($arrContextOptions));
//decode the json
$data = json_decode($data, true);
//iterate over the list of data and print
foreach($data['badges'] as $badge){
echo = $badge['name'] . '
by: ' . $badge['issuer'].'
';
}
#python
import urllib2
import json
#generate a url
url = u'https://www.csun.edu/web-dev/api/affinity/1.0/badges?email=nr_steven.fitzgerald@csun.edu'
#open the url
try:
u = urllib2.urlopen(url)
data = u.read()
except Exception as e:
data = {}
#load data with json object
data = json.loads(data)
#iterate over the json object and print
for badge in data['badges']:
print badge['name'] + '\nby: ' + badge['issuer']
require 'net/http'
require 'json'
#generate a url
source = 'https://www.csun.edu/web-dev/api/affinity/1.0/badges?email=nr_steven.fitzgerald@csun.edu'
#prepare the uri
uri = URI.parse(source)
#request the data
response = Net::HTTP.get(uri)
#parse the json
badges = JSON.parse(response)
#print the json
badges['badges'].each do |badge|
puts "#{badge['name']}\nby: #{badge['issuer']}"