Sha256: 70496de21493218a4f03cf6166cc791c163fe5abb330fdd2f44ed3935eaf7c12

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module ShotgunApiRuby
  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 "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 "Error while read schema fields for #{type}: #{resp.body}"
        end

        OpenStruct.new(
          resp_body["data"].transform_values do |value|
            OpenStruct.new(
              value.transform_values do |attribute|
                attribute["value"]
              end.merge(
                properties: OpenStruct.new(value["properties"].transform_values{ |prop| prop["value"] })
              )
            )
          end
        )
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shotgun_api_ruby-0.0.8.4 lib/shotgun_api_ruby/entities/schema.rb
shotgun_api_ruby-0.0.8.3 lib/shotgun_api_ruby/entities/schema.rb
shotgun_api_ruby-0.0.8.2 lib/shotgun_api_ruby/entities/schema.rb
shotgun_api_ruby-0.0.8 lib/shotgun_api_ruby/entities/schema.rb