Commit 9b34656
Changed files (6)
lib
scim
shady
spec
scim
builders
lib/scim/shady/builders/metadata.rb
@@ -7,10 +7,15 @@ module Scim
attr_accessor :location
attr_accessor :version
+ def initialize(resource)
+ @resource = resource
+ @created_at = @updated_at = Time.now
+ end
+
def to_h
{
'meta' => {
- 'resourceType' => self.class.name.split(/::/).last,
+ 'resourceType' => @resource.class.name.split(/::/).last,
'created' => created_at.to_time.utc.iso8601,
'lastModified' => updated_at.to_time.utc.iso8601,
'location' => location,
lib/scim/shady/builders/resource.rb
@@ -1,12 +1,15 @@
+require 'forwardable'
+
module Scim
module Shady
module Builders
class Resource
+ extend Forwardable
attr_accessor :id
+ def_delegators :@meta, :created_at=, :updated_at=, :location=, :version=
def initialize
- @created_at = @updated_at = Time.now
- @meta = Metadata.new
+ @meta = Metadata.new(self)
end
def meta
lib/scim/shady/builders/service_provider_configuration.rb
@@ -2,6 +2,9 @@ module Scim
module Shady
module Builders
class ServiceProviderConfiguration
+ extend Forwardable
+ def_delegators :@meta, :created_at=, :updated_at=, :location=, :version=
+ def_delegators :@meta, :created_at, :updated_at, :location, :version
attr_accessor :documentation_uri
attr_accessor :patch
attr_accessor :change_password_supported
@@ -11,7 +14,7 @@ module Scim
def initialize
@authentication_schemes = []
@created_at = @updated_at = Time.now
- @meta = Metadata.new
+ @meta = Metadata.new(self)
end
def bulk
@@ -53,7 +56,7 @@ module Scim
end
def to_h
- super.merge({
+ {
'schemas' => [Schemas::SERVICE_PROVIDER_CONFIG],
'documentationUri' => documentation_uri,
'patch' => { "supported" => patch },
@@ -72,7 +75,7 @@ module Scim
scheme['primary'] = true if index.zero?
scheme
end
- })
+ }.merge(@meta.to_h)
end
class Bulk
lib/scim/shady/builders/user.rb
@@ -98,9 +98,7 @@ module Scim
attr_accessor :middle_name
attr_accessor :honorific_prefix
attr_accessor :honorific_suffix
-
- def formatted
- end
+ attr_accessor :formatted
def to_h
{
@@ -132,10 +130,10 @@ module Scim
@items ||= []
@items.push(
type: type,
- street_address: street_address,
+ streetAddress: street_address,
locality: locality,
region: region,
- postal_code: postal_code,
+ postalCode: postal_code,
country: country,
primary: primary,
)
lib/scim/shady/user.rb
@@ -1,10 +1,74 @@
module Scim
module Shady
+ class Name
+ def initialize(hash)
+ @hash = hash
+ end
+
+ def formatted
+ to_h['formatted']
+ end
+
+ def to_h
+ @hash['name']
+ end
+ end
+
+ class Address
+ def initialize(hash)
+ @hash = hash
+ end
+
+ def street_address
+ to_h['streetAddress']
+ end
+
+ def locality
+ to_h['locality']
+ end
+
+ def region
+ to_h['region']
+ end
+
+ def postal_code
+ to_h['postalCode']
+ end
+
+ def country
+ to_h['country']
+ end
+
+ def formatted
+ "#{street_address}\n#{locality}, #{region} #{postal_code} #{country}"
+ end
+
+ def primary?
+ to_h['primary']
+ end
+
+ def to_h
+ @hash
+ end
+ end
+
class User < Resource
def username
to_h['userName']
end
+ def external_id
+ to_h['externalId']
+ end
+
+ def name
+ Name.new(to_h)
+ end
+
+ def addresses
+ to_h['addresses'].map { |x| Address.new(x) }
+ end
+
class << self
def build
builder do |builder|
spec/scim/builders/user_spec.rb
@@ -34,6 +34,7 @@ RSpec.describe Scim::Shady::Builders::User do
subject.external_id = "701984"
subject.username = "bjensen@example.com"
subject.name do |x|
+ x.formatted = "Ms. Barbara J Jensen, III"
x.family_name = "Jensen"
x.given_name = "Barbara"
x.middle_name = "Jane"