Commit f91962d
Changed files (3)
spec
scim
kit
lib/scim/kit/v2/meta.rb
@@ -21,6 +21,14 @@ module Scim
def disable_timestamps
@version = @created = @last_modified = nil
end
+
+ def self.from(hash)
+ meta = Meta.new(hash[:resourceType], hash[:location])
+ meta.created = hash[:created] ? DateTime.parse(hash[:created]) : nil
+ meta.last_modified = hash[:lastModified] ? DateTime.parse(hash[:lastModified]) : nil
+ meta.version = hash[:version]
+ meta
+ end
end
end
end
lib/scim/kit/v2/schema.rb
@@ -7,8 +7,8 @@ module Scim
class Schema
include Templatable
- attr_reader :id, :name, :attributes, :meta
- attr_accessor :description
+ attr_reader :id, :name, :attributes
+ attr_accessor :meta, :description
def initialize(id:, name:, location:)
@id = id
@@ -35,6 +35,13 @@ module Scim
yield item
item
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])
+ end
+ end
end
end
end
spec/scim/kit/v2/schema_spec.rb
@@ -122,4 +122,17 @@ RSpec.describe Scim::Kit::V2::Schema do
specify { expect(result[:meta][:resourceType]).to eql('Schema') }
specify { expect(result[:meta][:location]).to eql(location) }
end
+
+ describe ".parse" do
+ let(:result) { described_class.parse(subject.to_json) }
+
+ specify { expect(result.id).to eql(subject.id) }
+ specify { expect(result.name).to eql(subject.name) }
+ specify { expect(result.description).to eql(subject.description) }
+ specify { expect(result.meta.created).to eql(subject.meta.created) }
+ specify { expect(result.meta.last_modified).to eql(subject.meta.last_modified) }
+ specify { expect(result.meta.version).to eql(subject.meta.version) }
+ specify { expect(result.meta.location).to eql(subject.meta.location) }
+ specify { expect(result.meta.resource_type).to eql(subject.meta.resource_type) }
+ end
end