Sha256: db6356d4aacfc44b1356d271f355b8dca04bfcda0f8d2e02e85e4f89c9edc0f4
Contents?: true
Size: 1.55 KB
Versions: 4
Compression:
Stored size: 1.55 KB
Contents
# frozen_string_literal: true module ShotgridApiRuby class Entities class Schema def initialize(connection, type, base_url_prefix) @connection = connection.dup @type = type @connection.url_prefix = "#{base_url_prefix}/schema/#{type}" end attr_reader :type, :connection 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 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 end end end
Version data entries
4 entries across 4 versions & 1 rubygems