class DoList::AuthToken

Public Class Methods

new(params = {}) click to toggle source
# File lib/do-list/auth_token.rb, line 5
def initialize(params = {})
  @headers = params[:headers]
  @account_id = params[:account_id]
  @api_key = params[:api_key]
  @uri = DoList::UrlParser.parse_url(params[:url])
  @http = DoList::UrlParser.request_http(@uri)
  @auth_key, @auth_depr_date = request_auth_key
end

Public Instance Methods

auth_key() click to toggle source
# File lib/do-list/auth_token.rb, line 14
def auth_key
  @auth_key, @auth_depr_date = request_auth_key if (DateTime.now + (1 / 24.0)) > @auth_depr_date
  @auth_key
end

Private Instance Methods

body() click to toggle source
# File lib/do-list/auth_token.rb, line 28
    def body
      <<-GETAUTHBODY
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://api.dolist.net/v2">
          <soapenv:Header/>
          <soapenv:Body>
             <v2:GetAuthenticationToken>
                <v2:authenticationRequest>
                   <v2:AccountID>#{@account_id}</v2:AccountID>
                   <v2:AuthenticationKey>#{@api_key}</v2:AuthenticationKey>
                </v2:authenticationRequest>
             </v2:GetAuthenticationToken>
          </soapenv:Body>
        </soapenv:Envelope>
      GETAUTHBODY
    end
request_auth_key() click to toggle source
# File lib/do-list/auth_token.rb, line 21
def request_auth_key
  document = DoList::UrlParser.post_http(@http, @uri, body, @headers)
  parsed = []
  parsed << document.xpath('//Key').children.to_s
  parsed << DateTime.parse(document.xpath('//DeprecatedDate').children.to_s)
end