Class: OpenID::SReg::Response

Inherits:
Extension show all
Defined in:
lib/openid/extensions/sreg.rb

Overview

Represents the data returned in a simple registration response inside of an OpenID id_res response. This object will be created by the OpenID server, added to the id_res response object, and then extracted from the id_res message by the Consumer.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Extension

#to_message

Constructor Details

#initialize(data = {}, ns_uri = NS_URI) ⇒ Response

Returns a new instance of Response.



219
220
221
222
223
# File 'lib/openid/extensions/sreg.rb', line 219

def initialize(data = {}, ns_uri = NS_URI)
  @ns_alias = "sreg"
  @data = data
  @ns_uri = ns_uri
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



217
218
219
# File 'lib/openid/extensions/sreg.rb', line 217

def data
  @data
end

#ns_uriObject (readonly)

Returns the value of attribute ns_uri.



217
218
219
# File 'lib/openid/extensions/sreg.rb', line 217

def ns_uri
  @ns_uri
end

Class Method Details

.extract_response(request, data) ⇒ Object

Take a Request and a hash of simple registration values and create a Response object containing that data.



227
228
229
230
231
# File 'lib/openid/extensions/sreg.rb', line 227

def self.extract_response(request, data)
  arf = request.all_requested_fields
  resp_data = data.reject { |k, v| !arf.member?(k) || v.nil? }
  new(resp_data, request.ns_uri)
end

.from_success_response(success_response, signed_only = true) ⇒ Object

Create an Response object from an OpenID::Consumer::SuccessResponse from consumer.complete If you set the signed_only parameter to false, unsigned data from the id_res message from the server will be processed.



237
238
239
240
241
242
243
244
245
246
247
# File 'lib/openid/extensions/sreg.rb', line 237

def self.from_success_response(success_response, signed_only = true)
  ns_uri = OpenID.get_sreg_ns(success_response.message)
  if signed_only
    args = success_response.get_signed_ns(ns_uri)
    return if args.nil? # No signed args, so fail
  else
    args = success_response.message.get_args(ns_uri)
  end
  args.reject! { |k, _v| !DATA_FIELDS.member?(k) }
  new(args, ns_uri)
end

Instance Method Details

#[](field_name) ⇒ Object

Read-only hashlike interface. Raises an exception if the field name is bad



257
258
259
260
# File 'lib/openid/extensions/sreg.rb', line 257

def [](field_name)
  OpenID.check_sreg_field_name(field_name)
  data[field_name]
end

#empty?Boolean

Returns:

  • (Boolean)


262
263
264
# File 'lib/openid/extensions/sreg.rb', line 262

def empty?
  @data.empty?
end

#get_extension_argsObject

Get the fields to put in the simple registration namespace when adding them to an id_res message.



251
252
253
# File 'lib/openid/extensions/sreg.rb', line 251

def get_extension_args
  @data
end