Class: ShotgridApiRuby::Entities::Schema
- Inherits:
-
Object
- Object
- ShotgridApiRuby::Entities::Schema
- Extended by:
- T::Sig
- Defined in:
- lib/shotgrid_api_ruby/entities/schema.rb
Instance Attribute Summary collapse
- #connection ⇒ Faraday::Connection readonly
- #type ⇒ String, Symbol readonly
Instance Method Summary collapse
- #fields ⇒ OpenStruct
- #initialize(connection, type, base_url_prefix) ⇒ void constructor
- #read ⇒ OpenStruct
Constructor Details
#initialize(connection, type, base_url_prefix) ⇒ void
16 17 18 19 20 |
# File 'lib/shotgrid_api_ruby/entities/schema.rb', line 16 def initialize(connection, type, base_url_prefix) @connection = T.let(connection.dup, Faraday::Connection) @type = T.let(type, T.any(String, Symbol)) @connection.url_prefix = "#{base_url_prefix}/schema/#{type}" end |
Instance Attribute Details
#connection ⇒ Faraday::Connection (readonly)
24 25 26 |
# File 'lib/shotgrid_api_ruby/entities/schema.rb', line 24 def connection @connection end |
#type ⇒ String, Symbol (readonly)
22 23 24 |
# File 'lib/shotgrid_api_ruby/entities/schema.rb', line 22 def type @type end |
Instance Method Details
#fields ⇒ OpenStruct
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/shotgrid_api_ruby/entities/schema.rb', line 43 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 ⇒ OpenStruct
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/shotgrid_api_ruby/entities/schema.rb', line 27 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 |