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.



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

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.



225
226
227
# File 'lib/openid/extensions/sreg.rb', line 225

def data
  @data
end

#ns_uriObject (readonly)

Returns the value of attribute ns_uri.



225
226
227
# File 'lib/openid/extensions/sreg.rb', line 225

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.



235
236
237
238
239
# File 'lib/openid/extensions/sreg.rb', line 235

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.



245
246
247
248
249
250
251
252
253
254
255
# File 'lib/openid/extensions/sreg.rb', line 245

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 nil 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



265
266
267
268
# File 'lib/openid/extensions/sreg.rb', line 265

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

#empty?Boolean

Returns:

  • (Boolean)


270
271
272
# File 'lib/openid/extensions/sreg.rb', line 270

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.



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

def get_extension_args
  return @data
end