advantage_quickbase 0.2.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/quickbase.rb +69 -0
- metadata +1 -1
data/lib/quickbase.rb
CHANGED
@@ -94,6 +94,75 @@ module AdvantageQuickbase
|
|
94
94
|
result.css('rid').map{ |xml_node| xml_node.text.to_i }
|
95
95
|
end
|
96
96
|
|
97
|
+
def get_schema( db_id )
|
98
|
+
schema_hash = {}
|
99
|
+
result = send_request( :getSchema, db_id, {} )
|
100
|
+
|
101
|
+
# Get the table data
|
102
|
+
schema_hash[ :app_id ] = get_tag_value( result, 'app_id' )
|
103
|
+
schema_hash[ :table_id ] = get_tag_value( result, 'table_id' )
|
104
|
+
schema_hash[ :name ] = get_tag_value( result, 'name' )
|
105
|
+
|
106
|
+
if schema_hash[ :app_id ] == schema_hash[ :table_id ]
|
107
|
+
# App Mode
|
108
|
+
schema_hash[ :mode ] = 'app'
|
109
|
+
|
110
|
+
schema_hash[ :tables ] = {}
|
111
|
+
tables = result.css( 'chdbid' )
|
112
|
+
tables.each do |table|
|
113
|
+
table_hash = {
|
114
|
+
dbid: table.text,
|
115
|
+
name: table.attributes['name'].to_s
|
116
|
+
}
|
117
|
+
|
118
|
+
table_hash[ :name ].gsub!( /^_dbid_/, '' )
|
119
|
+
table_hash[ :name ].gsub!( '_', ' ' )
|
120
|
+
table_hash[ :name ].capitalize!
|
121
|
+
|
122
|
+
schema_hash[ :tables ][ table_hash[:dbid] ] = table_hash
|
123
|
+
end
|
124
|
+
else
|
125
|
+
# Table mode
|
126
|
+
schema_hash[ :mode ] = 'table'
|
127
|
+
|
128
|
+
# Parse the field data
|
129
|
+
schema_hash[ :fields ] = {}
|
130
|
+
fields = result.css( 'field' )
|
131
|
+
fields.each do |field|
|
132
|
+
field_hash = {
|
133
|
+
id: field.attributes[ 'id' ].to_s,
|
134
|
+
data_type: field.attributes[ 'field_type' ].to_s,
|
135
|
+
base_type: field.attributes[ 'base_type' ].to_s,
|
136
|
+
name: get_tag_value( field, 'label' ),
|
137
|
+
required: get_tag_value( field, 'required' ).to_i == 1,
|
138
|
+
unique: get_tag_value( field, 'unique' ).to_i == 1,
|
139
|
+
}
|
140
|
+
|
141
|
+
# Field type (Summary, Formula, Lookup, etc) is poorly represented. Fix that.
|
142
|
+
case field.attributes[ 'mode' ].to_s
|
143
|
+
when 'virtual'
|
144
|
+
field_hash[ :field_type ] = 'formula'
|
145
|
+
when ''
|
146
|
+
field_hash[ :field_type ] = 'normal'
|
147
|
+
else
|
148
|
+
field_hash[ :field_type ] = field.attributes[ 'mode' ].to_s
|
149
|
+
end
|
150
|
+
|
151
|
+
choices = field.css( 'choice' )
|
152
|
+
if choices.length > 0
|
153
|
+
field_hash[ :choices ] = []
|
154
|
+
choices.each do |choice|
|
155
|
+
field_hash[ :choices ] << choice.text
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
schema_hash[ :fields ][ field_hash[:id] ] = field_hash
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
schema_hash
|
164
|
+
end
|
165
|
+
|
97
166
|
private
|
98
167
|
def normalize_list( list )
|
99
168
|
if list.is_a?( Array )
|