Commit 44a88c7
Changed files (3)
lib
scim
kit
spec
scim
kit
lib/scim/kit/v2/configuration.rb
@@ -51,6 +51,13 @@ module Scim
uri = URI.join(base_url, 'ServiceProviderConfig')
self.service_provider_configuration =
ServiceProviderConfiguration.parse(client.get(uri).body)
+
+ response = client.get(URI.join(base_url, 'Schemas'))
+ schema_hashes = JSON.parse(response.body, symbolize_names: true)
+ schema_hashes.each do |schema_hash|
+ schema = Schema.from(schema_hash)
+ schemas[schema.id] = schema
+ end
end
private
lib/scim/kit/v2/schema.rb
@@ -30,21 +30,28 @@ module Scim
id.include?(Schemas::CORE) || id.include?(Messages::CORE)
end
- def self.build(*args)
- item = new(*args)
- yield item
- item
- end
+ class << self
+ def build(*args)
+ item = new(*args)
+ yield item
+ item
+ end
+
+ def from(hash)
+ Schema.new(
+ id: hash[:id],
+ name: hash[:name],
+ location: hash[:location]
+ ) do |x|
+ x.meta = Meta.from(hash[:meta])
+ hash[:attributes].each do |y|
+ x.attributes << AttributeType.from(y)
+ end
+ end
+ end
- def self.parse(json)
- hash = JSON.parse(json, symbolize_names: true)
- Schema.new(
- id: hash[:id],
- name: hash[:name],
- location: hash[:location]
- ) do |x|
- x.meta = Meta.from(hash[:meta])
- hash[:attributes].each { |y| x.attributes << AttributeType.from(y) }
+ def parse(json)
+ from(JSON.parse(json, symbolize_names: true))
end
end
end
spec/scim/kit/v2/configuration_spec.rb
@@ -43,13 +43,21 @@ RSpec.describe Scim::Kit::V2::Configuration do
let(:service_provider_configuration) do
Scim::Kit::V2::ServiceProviderConfiguration.new(location: FFaker::Internet.uri('https'))
end
+ let(:schema) do
+ Scim::Kit::V2::Schema.new(id: 'User', name: 'User', location: FFaker::Internet.uri('https'))
+ end
before do
stub_request(:get, "#{base_url}/ServiceProviderConfig")
.to_return(status: 200, body: service_provider_configuration.to_json)
+
+ stub_request(:get, "#{base_url}/Schemas")
+ .to_return(status: 200, body: [schema.to_h].to_json)
+
subject.load_from(base_url)
end
specify { expect(subject.service_provider_configuration.to_h).to eql(service_provider_configuration.to_h) }
+ specify { expect(subject.schemas[schema.id].to_h).to eql(schema.to_h) }
end
end