lib/scim/kit/v2/service_provider_configuration.rb in scim-kit-0.2.16 vs lib/scim/kit/v2/service_provider_configuration.rb in scim-kit-0.3.0

- old
+ new

@@ -4,18 +4,20 @@ module Kit module V2 # Represents a scim Service Provider Configuration class ServiceProviderConfiguration include Templatable - attr_reader :location - attr_accessor :documentation_uri - attr_reader :authentication_schemes - attr_reader :etag, :sort, :change_password, :patch - attr_reader :bulk, :filter, :meta + attr_accessor :bulk, :filter + attr_accessor :etag, :sort, :change_password, :patch + attr_accessor :meta, :documentation_uri + attr_accessor :authentication_schemes - def initialize(location:) - @meta = Meta.new('ServiceProviderConfig', location) + def initialize( + location:, + meta: Meta.new('ServiceProviderConfig', location) + ) + @meta = meta @authentication_schemes = [] @etag = Supportable.new @sort = Supportable.new @change_password = Supportable.new @patch = Supportable.new @@ -25,9 +27,24 @@ def add_authentication(type, primary: nil) scheme = AuthenticationScheme.build_for(type, primary: primary) yield scheme if block_given? @authentication_schemes << scheme + end + + class << self + def parse(json, hash = JSON.parse(json, symbolize_names: true)) + x = new(location: hash[:location], meta: Meta.from(hash[:meta])) + x.documentation_uri = hash[:documentationUri] + %i[patch changePassword sort etag filter bulk].each do |key| + x.send("#{key.to_s.underscore}=", Supportable.from(hash[key])) + end + schemes = hash[:authenticationSchemes] + x.authentication_schemes = schemes&.map do |auth| + AuthenticationScheme.from(auth) + end + x + end end end end end end