class ShotgunApiRuby::Entities::Schema

Attributes

connection[R]
type[R]

Public Class Methods

new(connection, type, base_url_prefix) click to toggle source
# 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

Public Instance Methods

fields() click to toggle source
# 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() click to toggle source
# 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