Class: AdvantageQuickbase::API
- Inherits:
-
Object
- Object
- AdvantageQuickbase::API
show all
- Includes:
- Table, User
- Defined in:
- lib/user.rb,
lib/table.rb,
lib/quickbase.rb
Defined Under Namespace
Modules: Table, User
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#add_record(db_id, new_values) ⇒ Object
-
#delete_record(db_id, record_id) ⇒ Object
-
#do_query(db_id, options) ⇒ Object
-
#do_query_count(db_id, query) ⇒ Object
-
#edit_record(db_id, record_id, new_values) ⇒ Object
-
#get_schema(db_id) ⇒ Object
-
#import_from_csv(db_id, data_array, columns) ⇒ Object
-
#initialize(domain, username, password, app_token = nil, ticket = nil) ⇒ API
constructor
Methods included from Table
#find_db_by_name, #get_db_info, #get_role_info, #get_users_access
Methods included from User
#add_user_to_role, #change_user_role, #deny_users, #get_app_access, #get_user_ids, #get_user_info, #get_user_role, #provision_user, #remove_access, #remove_user_from_role, #undeny_users
Constructor Details
#initialize(domain, username, password, app_token = nil, ticket = nil) ⇒ API
Returns a new instance of API.
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/quickbase.rb', line 16
def initialize( domain, username, password, app_token=nil, ticket=nil)
@domain = domain
if username && password
data = {
username: username,
password: password,
apptoken: app_token
}
else
@ticket = ticket if ticket
data = {}
end
request_xml = build_request_xml( data )
@http = Net::HTTP.new( base_domain, 443 )
@http.use_ssl = true
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
url = build_request_url( :authenticate )
= ( :authenticate, request_xml )
result = @http.post( url, request_xml, )
parsed_result = parse_xml( result.body )
ticket = get_tag_value( parsed_result, :ticket )
if ticket
@ticket = ticket
else
raise "Connection Failed\n\n#{result.body}"
end
end
|
Instance Attribute Details
#ticket ⇒ Object
Returns the value of attribute ticket.
11
12
13
|
# File 'lib/quickbase.rb', line 11
def ticket
@ticket
end
|
Instance Method Details
#add_record(db_id, new_values) ⇒ Object
80
81
82
83
84
85
|
# File 'lib/quickbase.rb', line 80
def add_record( db_id, new_values )
xml = build_update_xml( new_values )
result = send_request( :addRecord, db_id, nil, xml )
get_tag_value( result, :rid )
end
|
#delete_record(db_id, record_id) ⇒ Object
94
95
96
97
98
|
# File 'lib/quickbase.rb', line 94
def delete_record( db_id, record_id )
result = send_request( :deleteRecord, db_id, {rid: record_id} )
get_tag_value( result, :rid ).to_s == record_id.to_s
end
|
#do_query(db_id, options) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/quickbase.rb', line 55
def do_query( db_id, options )
if !options[ :fmt ]
options[ :fmt ] = 'structured'
end
options[ :clist ] = normalize_list( options[:clist] )
options[ :slist ] = normalize_list( options[:slist] )
result = send_request( :doQuery, db_id, options )
return_json = []
result.css( 'record' ).each do |record|
json_record = {}
record.css( 'f' ).each do |field|
json_record[ field['id'] ] = field.text
end
return_json << json_record
end
return_json
end
|
#do_query_count(db_id, query) ⇒ Object
50
51
52
53
|
# File 'lib/quickbase.rb', line 50
def do_query_count( db_id, query )
result = send_request( :doQueryCount, db_id, {query: query} )
get_tag_value( result, :nummatches ).to_i
end
|
#edit_record(db_id, record_id, new_values) ⇒ Object
87
88
89
90
91
92
|
# File 'lib/quickbase.rb', line 87
def edit_record( db_id, record_id, new_values )
xml = build_update_xml( new_values, record_id )
result = send_request( :editRecord, db_id, nil, xml )
get_tag_value( result, :rid ).to_s == record_id.to_s
end
|
#get_schema(db_id) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/quickbase.rb', line 108
def get_schema( db_id )
schema_hash = {}
result = send_request( :getSchema, db_id, {} )
schema_hash[ :app_id ] = get_tag_value( result, 'app_id' )
schema_hash[ :table_id ] = get_tag_value( result, 'table_id' )
schema_hash[ :name ] = get_tag_value( result, 'name' )
if schema_hash[ :app_id ] == schema_hash[ :table_id ]
schema_hash[ :mode ] = 'app'
schema_hash[ :tables ] = {}
tables = result.css( 'chdbid' )
tables.each do |table|
table_hash = {
dbid: table.text,
name: table.attributes['name'].to_s
}
table_hash[ :name ].gsub!( /^_dbid_/, '' )
table_hash[ :name ].gsub!( '_', ' ' )
table_hash[ :name ].capitalize!
schema_hash[ :tables ][ table_hash[:dbid] ] = table_hash
end
else
schema_hash[ :mode ] = 'table'
schema_hash[ :fields ] = {}
fields = result.css( 'field' )
fields.each do |field|
field_hash = {
id: field.attributes[ 'id' ].to_s,
data_type: field.attributes[ 'field_type' ].to_s,
base_type: field.attributes[ 'base_type' ].to_s,
name: get_tag_value( field, 'label' ),
required: get_tag_value( field, 'required' ).to_i == 1,
unique: get_tag_value( field, 'unique' ).to_i == 1,
}
case field.attributes[ 'mode' ].to_s
when 'virtual'
field_hash[ :field_type ] = 'formula'
when ''
field_hash[ :field_type ] = 'normal'
else
field_hash[ :field_type ] = field.attributes[ 'mode' ].to_s
end
choices = field.css( 'choice' )
if choices.length > 0
field_hash[ :choices ] = []
choices.each do |choice|
field_hash[ :choices ] << choice.text
end
end
schema_hash[ :fields ][ field_hash[:id] ] = field_hash
end
end
schema_hash
end
|
#import_from_csv(db_id, data_array, columns) ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/quickbase.rb', line 100
def import_from_csv( db_id, data_array, columns )
columns = normalize_list( columns )
xml = build_csv_xml( data_array, columns )
result = send_request( :importFromCSV, db_id, nil, xml )
result.css('rid').map{ |xml_node| xml_node.text.to_i }
end
|