public final class DegreeDaysApi
extends java.lang.Object
The starting point for all API operations. If you're new to this API, read the docs for this class first.
To create a DegreeDaysApi
object, you'll typically want
to use this constructor.
For example:
DegreeDaysApi api = new DegreeDaysApi(
new AccountKey("test-test-test"),
new SecurityKey("test-test-test-test-test-test-test-test-test-test-test-test-test"));
The API access keys above (account key and security key) are for the free test account, which is heavily limited but usable for basic development and testing. For much more flexibility and production use, you can sign up for a full Degree Days.net API account to get your own API access keys.
Assuming you have a DegreeDaysApi
object called
api
, as in the example code above, then you can make three main
types of request (and get three main types of response) using the objects and
methods accessible through that api
object. The links below
have more information and sample code for each:
api.dataApi().getLocationData(locationDataRequest)
to fetch degree-day
data and/or hourly temperature data from the API, for any specified weather
station, postal/zip code, or longitude/latitude position.api.dataApi().getLocationInfo(locationInfoRequest)
to find out what
weather station the API would use to represent any specified postal/zip code
or longitude/latitude position.api.regressionApi().runRegressions(regressionRequest)
to send your
energy data to the API so the API can test thousands of regressions against
it (using HDD and CDD with a wide range of base temperatures), and return the
regressions that give the best statistical fit (including base temperatures
and coefficients you can use for further calculations).Request
object that specifies what you want the API
to do. There are different types of Request
for different API
operations, like LocationDataRequest
for
requesting degree-day data.Request
gets processed. (Internally this library will
turn your request into XML, send it to the API servers, and parse the XML
response that the servers send back.)Response
object back (assuming no errors). There are
different types of Response
, mirroring the different types of
Request
. For example, if you use a
LocationDataRequest
to request some degree-day data, successful
processing will give you a
LocationDataResponse
.
If something goes wrong in sending your request to the API servers, or in
getting your response back, you'll get a TransportException
.
Typically that means there was a network error of some sort.
If your request was transported to the API servers OK, but couldn't be
processed properly, you'll get a RequestFailureException
instead of a
Response
. There are different types of
RequestFailureException
for the different types of
Request
. For example, take a look at the docs for
DataApi.getLocationData(LocationDataRequest)
to see the exceptions
that can be thrown if the API servers can't process a
LocationDataRequest
. The exceptions should help you determine
the cause of the failure and decide what to do next.
Every customer's API account is associated with two access keys: a public "account key" and a private "security key", both of which are generated automatically on signup. These keys are used to secure each request sent to the API by the customer (or by software trusted to work on their behalf), to protect the API usage that the customer has paid to enable.
The account key is used to uniquely identify the customer account. It is a public key in the sense that there is no need to keep it secret.
Here's an example account key:
k9vs-e6a3-zh8r
The security key is a private key that should be kept secret. In this respect it is like a password. The only entities that should have access to the security key are: Degree Days.net (systems and staff), the API account holder(s), and any trusted software systems that the API account holder(s) are using to manage their interactions with the API.
Here's an example security key:
b79h-tmgg-dwv5-cgxq-j5k9-n34w-mvxv-b5be-kqp5-b6hb-3bey-h5gg-swwd
For more on the format of these access keys, see the notes in
AccountKey
and SecurityKey
.
To get your own API access keys you can sign up for an API account here. Or, for basic development and testing, you can try out the free test account.
DegreeDaysApi
object
You'd typically create just one DegreeDaysApi
object for use
throughout your application. The default configuration is perfectly safe for
use from multiple threads. But there's nothing to stop you creating and using
as many instances as you like.
For more information and code samples on how to use a
DegreeDaysApi
object that you have created (let's call it
api
as per the example further above), please see the docs for
the 3 main methods accessible through it:
This class is designed to be safe for use from multiple concurrent threads. However, if you create a customized instance of this class (using a RequestProcessor
that you have written or customized), then the thread-safety of its operation will depend on the thread-safety of that RequestProcessor
.
Constructor and Description |
---|
DegreeDaysApi(AccountKey accountKey,
SecurityKey securityKey)
Constructs a
DegreeDaysApi object that internally uses a
default RequestProcessor configured with the specified access
keys. |
DegreeDaysApi(RequestProcessor requestProcessor)
Constructs a
DegreeDaysApi object that internally uses the
specified RequestProcessor . |
Modifier and Type | Method and Description |
---|---|
DataApi |
dataApi()
Returns a non-null
DataApi object, providing easy, type-safe
access to the API's data-related operations. |
RegressionApi |
regressionApi()
Returns a non-null
RegressionApi object, providing easy,
type-safe access to the API's regression-related operations. |
public DegreeDaysApi(AccountKey accountKey, SecurityKey securityKey)
DegreeDaysApi
object that internally uses a
default RequestProcessor
configured with the specified access
keys.accountKey
- a non-null AccountKey
object - a wrapper
around the string account key that identifies the Degree Days.net
API account.securityKey
- a non-null SecurityKey
object, a wrapper
around the string security key associated with the account.java.lang.NullPointerException
- if accountKey
or
securityKey
is null
.public DegreeDaysApi(RequestProcessor requestProcessor)
DegreeDaysApi
object that internally uses the
specified RequestProcessor
.
We can think of two main reasons that you might want to use this instead
of the constructor
that creates a default RequestProcessor
automatically:
RequestProcessor
for testing.XmlHttpRequestProcessor
. You might, for example, want to change
the endpoint URL, or swap the default java.net
-based
HttpRequestDispatcher
for one that
uses HttpClient instead (if your app uses HttpClient elsewhere).requestProcessor
- the non-null RequestProcessor
object
to use internally for all operations.java.lang.NullPointerException
- if requestProcessor
is
null
.public DataApi dataApi()
DataApi
object, providing easy, type-safe
access to the API's data-related operations.public RegressionApi regressionApi()
RegressionApi
object, providing easy,
type-safe access to the API's regression-related operations.
See www.degreedays.net/api/ for more about the Degree Days.net API.
You can sign up for a Degree Days.net API account and read the integration guide that is useful and applicable whether you are using Java or not.