Access the Degree Days API using Wattics Ruby code
Book a Demo

Wattics customersDiscover how we can help you drive savings & increase sustainability for your customers or organization

Wattics companyLearn more about who we are, our core values and why our customers choose to partner with us

Access the Degree Days API using Wattics Ruby code

Degree days is a unit used to determine the heating requirements of buildings, representing a fall of one degree below a specified average outdoor temperature (usually 18°C or 65°F) for one day. It is a very important metric to be used when developing energy models and to validate savings in similar conditions.

For this reason, at Wattics we thought it would be useful to share with the community of energy analytics developers a sample code to show how to use Ruby to specify an XML request, send it to DegreeDays.net API servers (past the security system), and get an XML response back.

It’s not a full client library but it should work fine so long as you can specify your request in XML, and write some code to parse the XML response.

See the XML API docs for more information about how to specify the data you want in the XML request. There are lots of options, and the XML included in the Ruby code below is just a very simple example to get an API request working.

You can find the code also in the degreedays.net ruby page.

For any comment of feedbacks, contact Thiago Nuic: [email protected]

Enjoy.

 

require 'net/http'
require 'base64'

class DegreeDays
  @@account_key = 'test-test-test'
  @@security_key = 'test-test-test-test-test-test-test-test-test-test-test-test-test'
  @@url = 'https://apiv1.degreedays.net/xml'

  def self.perform_call
    timestamp = Time.now.utc.iso8601
    random = SecureRandom.uuid

    request_xml = %{
    <RequestEnvelope>
        <SecurityInfo>
            <Endpoint>#{@@url}</Endpoint>
            <AccountKey>#{@@account_key}</AccountKey>
            <Timestamp>#{timestamp}</Timestamp>
            <Random>#{random}</Random>
        </SecurityInfo>
        <LocationDataRequest>
            <PostalCodeLocation>
                <PostalCode>02532</PostalCode>
                <CountryCode>US</CountryCode>
            </PostalCodeLocation>
            <DataSpecs>
                <DatedDataSpec key="dailyHDDForLast7Days">
                    <HeatingDegreeDaysCalculation>
                        <FahrenheitBaseTemperature>65</FahrenheitBaseTemperature>
                    </HeatingDegreeDaysCalculation>
                    <DailyBreakdown>
                        <LatestValuesPeriod>
                            <NumberOfValues>7</NumberOfValues>
                        </LatestValuesPeriod>
                    </DailyBreakdown>
                </DatedDataSpec>
            </DataSpecs>
        </LocationDataRequest>
    </RequestEnvelope>
    }

    digest = OpenSSL::Digest.new('sha256')
    signature_bytes = OpenSSL::HMAC.digest(digest, @@security_key, request_xml)

    request_parameters = {
      request_encoding: 'base64url',
      signature_method: 'HmacSHA256',
      signature_encoding: 'base64url',
      encoded_request: Base64.urlsafe_encode64(request_xml),
      encoded_signature: Base64.urlsafe_encode64(signature_bytes)
    }

    uri = URI(@@url)
    res = Net::HTTP.post_form(uri, request_parameters)
    return res.body
  end
end

puts DegreeDays.perform_call

 

Sign up to our blog posts

Sign up to keep up-to-date with what’s happening within the industry

Technology Update

Check out our latest offering:

“WatticsAir – Air Quality Monitoring and Analytics”
Go to page