class AusPostAPI::DCE::Endpoint

Abstract class that defines a DCE::Endpoint. It implements the ‘uri` & `headers` methods and expects the `api_uri` method to be implemented.

Constants

FORMATS
LIVE_URI

Public Instance Methods

headers() click to toggle source
# File lib/aus_post_api/dce/endpoint.rb, line 15
def headers
  { "Authorization" => "Basic #{basic_auth}" }
end
uri() click to toggle source
# File lib/aus_post_api/dce/endpoint.rb, line 11
def uri
  "#{LIVE_URI}/#{api_uri}.#{format}?#{params}"
end

Private Instance Methods

api_uri() click to toggle source
# File lib/aus_post_api/dce/endpoint.rb, line 21
def api_uri
  raise ImplementationError.new('api_uri')
end
basic_auth() click to toggle source
# File lib/aus_post_api/dce/endpoint.rb, line 43
def basic_auth
  Base64.encode64("#{username}:#{password}")
end
format() click to toggle source
# File lib/aus_post_api/dce/endpoint.rb, line 25
def format
  if @config[:FORMAT].nil?
    raise NoFormatProvidedError
  else
    if !FORMATS.include?(@config[:FORMAT])
      raise InvalidFormatError
    else
      @config[:FORMAT]
    end
  end
end
params() click to toggle source
# File lib/aus_post_api/dce/endpoint.rb, line 37
def params
  [].tap { |result|
    @attributes.keys.each { |a| result << "#{a}=#{self.send(a).split.join('+')}" }
  }.join('&')
end
password() click to toggle source
# File lib/aus_post_api/dce/endpoint.rb, line 53
def password
  raise NoHeaderProvidedError.new('PASSWORD') if @config[:PASSWORD].nil?

  @config[:PASSWORD]
end
username() click to toggle source
# File lib/aus_post_api/dce/endpoint.rb, line 47
def username
  raise NoHeaderProvidedError.new('USERNAME') if @config[:USERNAME].nil?

  @config[:USERNAME]
end