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 ⇒ Object
readonly
Returns the value of attribute connection.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #fields ⇒ Object
-
#initialize(connection, type, base_url_prefix) ⇒ Schema
constructor
A new instance of Schema.
- #read ⇒ Object
Constructor Details
#initialize(connection, type, base_url_prefix) ⇒ Schema
Returns a new instance of Schema.
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 ⇒ Object (readonly)
Returns the value of attribute connection.
24 25 26 |
# File 'lib/shotgrid_api_ruby/entities/schema.rb', line 24 def connection @connection end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
22 23 24 |
# File 'lib/shotgrid_api_ruby/entities/schema.rb', line 22 def type @type end |
Instance Method Details
#fields ⇒ Object
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 ⇒ Object
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 |