Class: ShotgunApiRuby::Entities::Schema
- Inherits:
-
Object
- Object
- ShotgunApiRuby::Entities::Schema
- Defined in:
- lib/shotgun_api_ruby/entities/schema.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #fields ⇒ Object
-
#initialize(connection, type, base_url_prefix) ⇒ Schema
constructor
A new instance of Schema.
- #read ⇒ Object
Constructor Details
#initialize(connection, type, base_url_prefix) ⇒ Schema
Returns a new instance of Schema.
6 7 8 9 10 |
# File 'lib/shotgun_api_ruby/entities/schema.rb', line 6 def initialize(connection, type, base_url_prefix) @connection = connection.dup @type = type @connection.url_prefix = "#{base_url_prefix}/schema/#{type}" end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
11 12 13 |
# File 'lib/shotgun_api_ruby/entities/schema.rb', line 11 def connection @connection end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/shotgun_api_ruby/entities/schema.rb', line 11 def type @type end |
Instance Method Details
#fields ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/shotgun_api_ruby/entities/schema.rb', line 25 def fields resp = @connection.get('fields') resp_body = JSON.parse(resp.body) if resp.status >= 300 raise "Error while read schema fields for #{type}: #{resp.body}" end OpenStruct.new( resp_body['data'].transform_values do |value| OpenStruct.new( value.transform_values { |attribute| attribute['value'] }.merge( properties: OpenStruct.new( value['properties'].transform_values do |prop| prop['value'] end, ), ), ) end, ) end |
#read ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/shotgun_api_ruby/entities/schema.rb', line 13 def read resp = @connection.get('') if resp.status >= 300 raise "Error while read schema for #{type}: #{resp.body}" end resp_body = JSON.parse(resp.body) OpenStruct.new(resp_body['data'].transform_values { |v| v['value'] }) end |