Class: OpenID::AX::KeyValueMessage

### Home Classes Methods

### In Files

- lib/openid/extensions/ax.rb

### Parent

OpenID::AX::AXMessage

### Methods

- ::new
- #[]
- #_get_extension_kv_args
- #add_value
- #count
- #get
- #get_single
- #parse_extension_args
- #set_values

### Files

- LICENSE

### Class/Module Index

Quicksearch

- OpenID
- OpenID::AX
- OpenID::AX::AXMessage
- OpenID::AX::AttrInfo
- OpenID::AX::Error
- OpenID::AX::FetchRequest
- OpenID::AX::FetchResponse
- OpenID::AX::KeyValueMessage
- OpenID::AX::StoreRequest
- OpenID::AX::StoreResponse
- OpenID::AssertionError
- OpenID::Association
- OpenID::AssociationNegotiator
- OpenID::Consumer
- OpenID::Consumer::AssociationManager
- OpenID::Consumer::CancelResponse
- OpenID::Consumer::CheckIDRequest
- OpenID::Consumer::DiffieHellmanSHA1Session
- OpenID::Consumer::DiffieHellmanSHA256Session
- OpenID::Consumer::DiffieHellmanSession
- OpenID::Consumer::DiscoveredServices
- OpenID::Consumer::DiscoveryManager
- OpenID::Consumer::FailureResponse
- OpenID::Consumer::IdResHandler
- OpenID::Consumer::NoEncryptionSession
- OpenID::Consumer::Response
- OpenID::Consumer::Session
- OpenID::Consumer::SetupNeededResponse
- OpenID::Consumer::SuccessResponse
- OpenID::CryptUtil
- OpenID::DiffieHellman
- OpenID::DiscoveryFailure
- OpenID::Extension
- OpenID::FetchingError
- OpenID::HTTPRedirectLimitReached
- OpenID::HTTPResponse
- OpenID::HTTPStatusError
- OpenID::InvalidOpenIDNamespace
- OpenID::KVFormError
- OpenID::KVPostNetworkError
- OpenID::Message
- OpenID::Message::KeyNotFound
- OpenID::NamespaceAliasRegistrationError
- OpenID::NamespaceMap
- OpenID::Nonce
- OpenID::OAuth
- OpenID::OAuth::Request
- OpenID::OAuth::Response
- OpenID::OpenIDError
- OpenID::OpenIDServiceEndpoint
- OpenID::PAPE
- OpenID::PAPE::Request
- OpenID::PAPE::Response
- OpenID::ProtocolError
- OpenID::RealmVerificationRedirected
- OpenID::SReg
- OpenID::SReg::NamespaceError
- OpenID::SReg::Request
- OpenID::SReg::Response
- OpenID::SSLFetchingError
- OpenID::Server
- OpenID::Server::AlreadySigned
- OpenID::Server::AssociateRequest
- OpenID::Server::BaseServerSession
- OpenID::Server::CheckAuthRequest
- OpenID::Server::CheckIDRequest
- OpenID::Server::Decoder
- OpenID::Server::DiffieHellmanSHA1ServerSession
- OpenID::Server::DiffieHellmanSHA256ServerSession
- OpenID::Server::Encoder
- OpenID::Server::EncodingError
- OpenID::Server::MalformedReturnURL
- OpenID::Server::MalformedTrustRoot
- OpenID::Server::NoReturnToError
- OpenID::Server::OpenIDRequest
- OpenID::Server::OpenIDResponse
- OpenID::Server::PlainTextServerSession
- OpenID::Server::ProtocolError
- OpenID::Server::Server
- OpenID::Server::Signatory
- OpenID::Server::SigningEncoder
- OpenID::Server::UntrustedReturnURL
- OpenID::Server::VersionError
- OpenID::Server::WebResponse
- OpenID::ServerError
- OpenID::StandardFetcher
- OpenID::Store
- OpenID::Store::Filesystem
- OpenID::Store::Interface
- OpenID::Store::Memcache
- OpenID::Store::Memory
- OpenID::TrustRoot
- OpenID::TrustRoot::TrustRoot
- OpenID::TypeURIMismatch
- OpenID::UI
- OpenID::UI::Request
- OpenID::URINorm
- OpenID::UndefinedOpenIDNamespace
- OpenID::Util
- OpenID::Yadis
- OpenID::Yadis::BasicServiceEndpoint
- OpenID::Yadis::CompoundFilter
- OpenID::Yadis::DiscoveryResult
- OpenID::Yadis::TransformFilterMaker
- OpenID::Yadis::XRDSError
- OpenID::Yadis::XRDSFraud
- OpenID::Yadis::XRI
- OpenID::Yadis::XRI::ProxyResolver
- OpenID::Yadis::XRI::XRIHTTPError
- HMAC
- HMAC::Base
- HMAC::SHA1
- HMAC::SHA256
- HMAC::SHA384
- HMAC::SHA512
- Net
- Net::HTTP
- HTMLComment
- HTMLTag
- HTMLText
- HTMLToken
- HTMLTokenizer
- HTMLTokenizerError
- Object

No matching classes.

# OpenID::AX::KeyValueMessage

Abstract class that implements a message that has attribute keys and values. It contains the common code between fetch_response and store_request.

### Attributes

data[R]

### Public Class Methods

new() click to toggle source

    # File lib/openid/extensions/ax.rb, line 275
    def initialize
      super()
      @mode = nil
      @data = Hash.new { |hash, key| hash[key] = [] }
    end

### Public Instance Methods

[](type_uri) click to toggle source

retrieve the list of values for this attribute

    # File lib/openid/extensions/ax.rb, line 385
    def [](type_uri)
      @data[type_uri]
    end

_get_extension_kv_args(aliases = nil) click to toggle source

Get the extension arguments for the key/value pairs contained in this message.

    # File lib/openid/extensions/ax.rb, line 297
    def _get_extension_kv_args(aliases = nil)
      aliases = NamespaceMap.new if aliases.nil?

      ax_args = new_args

      @data.each{|type_uri, values|
        name = aliases.add(type_uri)
        ax_args['type.'+name] = type_uri
        if values.size > 1
          ax_args['count.'+name] = values.size.to_s

          values.each_with_index{|value, i|
            key = "value.#{name}.#{i+1}"
            ax_args[key] = value
          }
          # for attributes with only a single value, use a
          # nice shortcut to only show the value w/o the count
        else
          values.each do |value|
            key = "value.#{name}"
            ax_args[key] = value
          end
        end
      }
      return ax_args
    end

add_value(type_uri, value) click to toggle source

Add a single value for the given attribute type to the message. If there are already values specified for this type, this value will be sent in addition to the values already specified.

    # File lib/openid/extensions/ax.rb, line 285
    def add_value(type_uri, value)
      @data[type_uri] = @data[type_uri] << value
    end

count(type_uri) click to toggle source

get the number of responses for this attribute

    # File lib/openid/extensions/ax.rb, line 390
    def count(type_uri)
      @data[type_uri].size
    end

get(type_uri) click to toggle source

retrieve the list of values for this attribute

    # File lib/openid/extensions/ax.rb, line 380
    def get(type_uri)
      @data[type_uri]
    end

get_single(type_uri, default = nil) click to toggle source

Get a single value for an attribute. If no value was sent for this attribute, use the supplied default. If there is more than one value for this attribute, this method will fail.

    # File lib/openid/extensions/ax.rb, line 369
    def get_single(type_uri, default = nil)
      values = @data[type_uri]
      return default if values.empty?
      if values.size != 1
        raise Error, "More than one value present for #{type_uri.inspect}"
      else
        return values[0]
      end
    end

parse_extension_args(ax_args) click to toggle source

Parse attribute exchange key/value arguments into this object.

    # File lib/openid/extensions/ax.rb, line 326
    def parse_extension_args(ax_args)
      check_mode(ax_args)
      aliases = NamespaceMap.new

      ax_args.each{|k, v|
        if k.index('type.') == 0
          type_uri = v
          name = k[5..-1]

          AX.check_alias(name)
          aliases.add_alias(type_uri,name)
        end
      }

      aliases.each{|type_uri, name|
        count_s = ax_args['count.'+name]
        count = count_s.to_i
        if count_s.nil?
          value = ax_args['value.'+name]
          if value.nil?
            raise IndexError, "Missing #{'value.'+name} in FetchResponse"
          elsif value.empty?
            values = []
          else
            values = [value]
          end
        elsif count_s.to_i == 0
          values = []
        else
          values = (1..count).inject([]){|l,i|
            key = "value.#{name}.#{i}"
            v = ax_args[key]
            raise IndexError, "Missing #{key} in FetchResponse" if v.nil?
            l << v
          }
        end
        @data[type_uri] = values
      }
    end

set_values(type_uri, values) click to toggle source

Set the values for the given attribute type. This replaces any values that have already been set for this attribute.

    # File lib/openid/extensions/ax.rb, line 291
    def set_values(type_uri, values)
      @data[type_uri] = values
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.