Class: ShotgunApiRuby::Entities::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/shotgun_api_ruby/entities/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#connectionObject (readonly)

Returns the value of attribute connection.



11
12
13
# File 'lib/shotgun_api_ruby/entities/schema.rb', line 11

def connection
  @connection
end

#typeObject (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

#fieldsObject



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

#readObject



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