-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoclcService.php
More file actions
59 lines (50 loc) · 1.28 KB
/
oclcService.php
File metadata and controls
59 lines (50 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/*
* Core class for accessing WorldCat REST API's via JSON
* Created by terrywbrady at OCLC Developer House 2014.
*/
class oclcService {
protected $inst_id;
protected $wskey;
protected $config;
public function __construct($configFile){
$this->config = parse_ini_file($configFile);
$this->inst_id = $this->config['inst_id'];
$this->wskey = $this->config['wskey'];
}
public function getInstId() {return $this->inst_id;}
public $baseUrl = "http://worldcat.org/webservices/";
public $service = "dummy/rest/";
public function getUrl($func, $opt = null) {
if ($opt == null) $opt = $this->getDefaultOptions();
$url = $this->baseUrl . $this->service . $func;
$url .= oclcService::makeQuery($opt);
return $url;
}
public static function makeQuery($opt) {
$q = "";
if (count($opt) > 0) {
$q .= "?";
foreach($opt as $k => $v) {
$q .= $k . "=" . $v . "&";
}
}
return $q;
}
public function getDefaultOptions() {
return array(
"alt" => "json",
"institution_id" => $this->inst_id,
"wskey" => $this->wskey
);
}
public function getResponseRaw($req) {
$ret = file_get_contents($req);
return $ret;
}
public function getResponseJson($req) {
$ret = file_get_contents($req);
return json_decode($ret, true);
}
}
?>