class ShotgridApiRuby::Entities::Schema

Attributes

connection[R]
type[R]

Public Class Methods

new(connection, type, base_url_prefix) click to toggle source
# File lib/shotgrid_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/shotgrid_api_ruby/entities/schema.rb, line 28
def fields
  resp = @connection.get('fields')
  resp_body = JSON.parse(resp.body)

  if resp.status >= 300
    raise ShotgridCallError.new(
            response: resp,
            message:
              "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/shotgrid_api_ruby/entities/schema.rb, line 13
def read
  resp = @connection.get('')

  if resp.status >= 300
    raise ShotgridCallError.new(
            response: resp,
            message: "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