Class: Quickbase::API
- Inherits:
-
Object
- Object
- Quickbase::API
- Defined in:
- lib/classes/api.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
-
#add_record(fields) ⇒ Object
Documentation at www.quickbase.com/api-guide/add_record.html.
-
#delete_record(rid) ⇒ Object
Documentation at www.quickbase.com/api-guide/delete_record.html.
-
#do_query(params) ⇒ Object
Documentation at www.quickbase.com/api-guide/do_query.html.
- #do_query_return_nokogiri_obj(params) ⇒ Object
-
#edit_record(rid, fields) ⇒ Object
Documentation at www.quickbase.com/api-guide/edit_record.html.
-
#initialize(connection) ⇒ API
constructor
A new instance of API.
Constructor Details
#initialize(connection) ⇒ API
Returns a new instance of API.
5 6 7 |
# File 'lib/classes/api.rb', line 5 def initialize(connection) instance_variable_set "@connection", connection end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
3 4 5 |
# File 'lib/classes/api.rb', line 3 def connection @connection end |
Instance Method Details
#add_record(fields) ⇒ Object
Documentation at www.quickbase.com/api-guide/add_record.html
43 44 45 46 |
# File 'lib/classes/api.rb', line 43 def add_record(fields) fields = Quickbase::Helper.generate_fields(fields) connection.http.post("API_AddRecord", fields) end |
#delete_record(rid) ⇒ Object
Documentation at www.quickbase.com/api-guide/delete_record.html
56 57 58 59 |
# File 'lib/classes/api.rb', line 56 def delete_record(rid) = Quickbase::Helper.hash_to_xml({:rid => rid.to_s}) connection.http.post("API_DeleteRecord", ) end |
#do_query(params) ⇒ Object
Documentation at www.quickbase.com/api-guide/do_query.html
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/classes/api.rb', line 10 def do_query(params) params[:fmt] = 'structured' if params[:fmt].nil? or params[:fmt].empty? clist = params[:clist].to_s.split(".") friendly = params[:friendly].to_s.split(".") keys = friendly.empty? ? clist : friendly.map(&:to_sym) response = connection.http.post("API_DoQuery", Quickbase::Helper.hash_to_xml(params)) array_of_records = response.xpath("//record[@type='array']/record") records = array_of_records.empty? ? response.xpath("//record") : array_of_records return [] if records.empty? records.map{|record| array_of_fields = record.xpath("f[@type='array']/f") fields = array_of_fields.empty? ? record.xpath("f") : array_of_fields Hash[fields.to_enum(:each_with_index).collect{|field,index| field_val = "" field_val_xpath = field.xpath("__content__").first field_val = field_val_xpath.content unless field_val_xpath.nil? Hash[keys[index],field_val] }.map(&:flatten)] } end |
#do_query_return_nokogiri_obj(params) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/classes/api.rb', line 32 def do_query_return_nokogiri_obj(params) #useful method for debugging params[:fmt] = 'structured' if params[:fmt].nil? or params[:fmt].empty? clist = params[:clist].to_s.split(".") friendly = params[:friendly].to_s.split(".") keys = friendly.empty? ? clist : friendly.map(&:to_sym) response = connection.http.post("API_DoQuery", Quickbase::Helper.hash_to_xml(params)) return response end |
#edit_record(rid, fields) ⇒ Object
Documentation at www.quickbase.com/api-guide/edit_record.html
49 50 51 52 53 |
# File 'lib/classes/api.rb', line 49 def edit_record(rid, fields) = Quickbase::Helper.generate_fields(fields) << Quickbase::Helper.hash_to_xml({:rid => rid.to_s}) connection.http.post("API_EditRecord", ) end |