This repository has been archived by the owner on Nov 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Api.php
executable file
·126 lines (115 loc) · 2.99 KB
/
Api.php
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* @version $Id$
* @author Brian Smith <[email protected]>
* @package ABS
*/
/*
* Include the ABS exceptions, core classes.
*/
//require_once 'Exception.php';
/**
* Include the ABS Request, core classes.
*/
//require_once 'Request.php';
/**
* Include the ABS Request, core classes.
*/
//require_once 'Response.php';
class ABS_Api {
/**
* Should an exception be thrown when an API call fails?
*
* @var boolean
*/
private $_throwOnFail = true;
/**
* The default American Bible Society API endpoint URL for REST requests.
*
* @var string
* @see setEndpointUrl()
*/
const REST_ENDPOINT_URL = 'http://bibles.org/';
/*
* An American Bible Society API key.
*
* To obtain one see ...
*
* @var string
* @see getKey()
*/
private $_key = null;
/**
* The American Bible Society REST endpoint URL.
*
* @var string
* @see getEndpointUrl(), setEndpointUrl()
* @uses REST_ENDPOINT_URL Used as a default.
*/
private $_endpointUrl = ABS_Api::REST_ENDPOINT_URL;
/**
* Constructor.
*
* @param string $key ABS API key.
*/
public function __construct($key) {
// key (required)
if (isset($key)) {
$this->_key = (string) $key;
} else {
throw new ABS_Exception('Must provide a valid API key.');
}
}
/**
* Get the API key.
*
* @return string
* @see __construct()
*/
public function getKey() {
return $this->_key;
}
/**
* Create a ABS_Request associated with this API object.
*
* @param string $method Name of the ABS API method
* @param array $params Associative array of parameter name/value pairs
* @return object ABS_Request
* @uses ABS_Request
*/
public function createRequest($url, $params = array()) {
return new ABS_Request($this, $url, $params);
}
/**
* Return the URL of the ABS endpoint.
*
* @return string
* @see setEndpointUrl()
*/
public function getEndpointUrl() {
return $this->_endpointUrl;
}
/**
* Return true if an exception will be thrown if the API returns a fail
* for the request.
*
* @return boolean
* @see setExceptionThrownOnFailure()
*/
public function isExceptionThrownOnFailure()
{
return $this->_throwOnFail;
}
/**
* Set an exception will be thrown if the API returns a fail for the
* request.
*
* @param boolean $throwOnFail
* @return void
* @see isExceptionThrownOnFailure()
*/
public function setExceptionThrownOnFailure($throwOnFail)
{
$this->_throwOnFail = (boolean) $throwOnFail;
}
}