Class: Quickbase::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/classes/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Api



5
6
7
# File 'lib/classes/api.rb', line 5

def initialize(connection)
  instance_variable_set "@connection", connection
end

Instance Attribute Details

#connectionObject

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



26
27
28
29
# File 'lib/classes/api.rb', line 26

def add_record(fields)
  fields = Quickbase::Helper.generate_fields(fields)
  connection.http.post("API_AddRecord", fields)
end

#delete_record(rid) ⇒ Object



39
40
41
42
# File 'lib/classes/api.rb', line 39

def delete_record(rid)
  tags = Quickbase::Helper.hash_to_xml({:rid => rid.to_s})
  connection.http.post("API_DeleteRecord", tags)
end

#do_query(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/classes/api.rb', line 10

def do_query(params)
  params.merge!({:fmt => "structured"})
  clist = params[:clist].to_s.split(".")
  response = connection.http.post("API_DoQuery", Quickbase::Helper.hash_to_xml(params))
  array_of_records = response.find("//record[@type='array']/record")
  records = array_of_records.empty? ? response.find("//record") : array_of_records
  return [] if records.empty?

  records.map{|record|
    array_of_fields = record.find("f[@type='array']/f")
    fields = array_of_fields.empty? ? record.find("f") : array_of_fields
    Hash[fields.to_enum(:each_with_index).collect{|field,index| Hash[clist[index],field.content] }.map(&:flatten)]
  }
end

#edit_record(rid, fields) ⇒ Object



32
33
34
35
36
# File 'lib/classes/api.rb', line 32

def edit_record(rid, fields)
  tags = Quickbase::Helper.generate_fields(fields)
  tags << Quickbase::Helper.hash_to_xml({:rid => rid.to_s})
  connection.http.post("API_EditRecord", tags)
end