Last active
August 29, 2015 13:56
-
-
Save meetme2meat/8858681 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'json-schema' | |
## /poaster_instance.json | |
## Seem like the need to have access_control a part of this json | |
poaster_instance_schema = { | |
"type" => "object", | |
"required" => ['id','facades','name'], | |
"properties" => { | |
"id" => {"type" => "string"}, | |
"name" => {"type" => "string"}, | |
"company_id" => {"type" => "string"}, | |
"access_controls" => {'type' => 'object', | |
'properties' => { | |
'read' => {'type' => 'boolean'}, | |
'write' => {'type' => 'boolean'} | |
} | |
}, | |
"facades" => { | |
"type" => "array", | |
'required' => true, | |
'items' => { | |
'type' => 'object', | |
'required' => ['id','name','position','company_id','poaster_instance_id','shareatives'], | |
'properties' => { | |
'id' => {'type' => 'string' }, | |
'name' => {'type' => 'string' }, | |
'position' => {'type' => 'integer'}, | |
'company_id' => {'type' => 'integer'}, | |
'poaster_instance_id' => {'type' => 'integer'}, | |
'shareatives' => { | |
'type' => 'array', | |
'required' => true, | |
'items' => { | |
'type' => 'object', | |
'required' => ['id','name','shareative_type','active','shareative','facade_id'], | |
'properties' => { | |
'id' => {'type' => 'string'}, | |
'name' => {'type' => 'string'}, | |
'shareative_type' => {'type' => 'string'}, | |
'active' => {'type' => 'boolean'}, | |
'facade_id' => {'type' => 'string'}, | |
'shareative' => {'type' => 'object', | |
'required' => ['url','thumb'], | |
'properties' => { | |
'url' => {'type' => 'string'}, | |
'thumb' => {'type' => 'string'}, | |
'side2' => {'type' => 'object', | |
'required' => ['type','data'], | |
'properties' => { | |
'type' => {'type' => 'string'}, | |
'data' => {'type' => 'object', | |
'side2_text_data' => {'type' => 'string'}, | |
'side2_link_url' => {'type' => 'string'}, | |
'side2_link_text' => {'type' => 'string'}, | |
'url' => {'type' => 'string'}, | |
'thumb' => {'type' => 'string'} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
data = { | |
'id' => '1212121', | |
'name' => 'Poaster Boys n Girls', | |
'facades' => [ | |
{ | |
'id' => 'F00001','name' => 'Facade1','position' => 0,'poaster_instance_id'=> 'PI0001','company_id' => 'C0001', | |
'shareatives' => [ | |
{ | |
'id' => 'SA0001', | |
'name' => 'Shareative1', | |
'shareative_type' => 'Video', | |
'active' => true, | |
'facade_id' => 'F0001', | |
'shareative' => { | |
'url' => 'https://google.com', | |
'thumb' => 'https://thumb.google.com', | |
'side2' => { | |
'type' => 'text', | |
'data' => { | |
'side2_text_data' => 'Side2Text0001', | |
'side2_link_url' => 'Side2Link0001', | |
'side2_link_text' => 'Side2LinkText0001', | |
} | |
} | |
} | |
}, | |
{ | |
'id' => 'SA0002', | |
'name' => 'Shareative2', | |
'shareative_type' => 'Image', | |
'active' => true, | |
'facade_id' => 'F0001', | |
'shareative' => { | |
'url' => 'https://google.com', | |
'thumb' => 'https://thumb.google.com', | |
'side2' => { | |
'type' => 'image', | |
'data' => { | |
'url' => 'http://gooogle.com/image_1.png', | |
'thumb' => 'http://thumb.gooogle.com/image_1.png' | |
} | |
} | |
} | |
} | |
] | |
}, | |
{ | |
'id' => 'F00001','name' => 'Facade2','position' => 1,'poaster_instance_id'=> 'PI0001','company_id' => 'C0001', | |
'shareatives' => [ | |
{ | |
'id' => 'SA0003', | |
'name' => 'Shareative3', | |
'shareative_type' => 'Image', | |
'active' => true, | |
'facade_id' => 'F0001', | |
'shareative' => { | |
'url' => 'https://google.com', | |
'thumb' => 'https://thumb.google.com', | |
'side2' => { | |
'type' => 'image', | |
'data' => { | |
'url' => 'http://gooogle.com/image_1.png', | |
'thumb' => 'http://thumb.gooogle.com/image_1.png' | |
} | |
} | |
} | |
}, | |
{ | |
'id' => 'SA0004', | |
'name' => 'Shareative4', | |
'shareative_type' => 'Video', | |
'active' => true, | |
'facade_id' => 'F0001', | |
'shareative' => { | |
'url' => 'https://google.com', | |
'thumb' => 'https://thumb.google.com', | |
'side2' => { | |
'type' => 'text', | |
'data' => { | |
'side2_text_data' => 'Side2Text0004', | |
'side2_link_url' => 'Side2Link0004', | |
'side2_link_text' => 'Side2LinkText0004', | |
} | |
} | |
} | |
} | |
] | |
} | |
] | |
} | |
puts JSON::Validator.validate!(poaster_instance_schema, data, :strict => true,:insert_defaults => true) # ==> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the side2 data can be either a
null
representing no side2 information (this can happen for Shareative of type video) or it can contain an object for image Shareative typeso essentially a side2 json would look like this