Class: Quickbase::HTTP

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/classes/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ HTTP

Returns a new instance of HTTP.



6
7
8
9
10
11
12
13
# File 'lib/classes/http.rb', line 6

def initialize(config)
  self.class.base_uri "https://#{config[:org]}.quickbase.com"
  instance_variable_set "@qb_params", {:dbid => "main"}
  response = post("API_Authenticate", Quickbase::Helper.hash_to_xml(config))
  qb_params[:ticket] = response.xpath("//ticket").first.content
  qb_params[:apptoken] = config[:apptoken]
  qb_params[:dbid] = config[:dbid]
end

Instance Attribute Details

#qb_paramsObject

Returns the value of attribute qb_params.



4
5
6
# File 'lib/classes/http.rb', line 4

def qb_params
  @qb_params
end

Instance Method Details

#post(quickbase_action, params = []) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/classes/http.rb', line 15

def post(quickbase_action, params = [])
  params = params.concat(Quickbase::Helper.hash_to_xml(qb_params))
  clean_xml_string = Quickbase::Helper.generate_xml(params).to_s
  self.class.headers({"Content-Length" => clean_xml_string.length.to_s})
  self.class.headers({"Content-Type" => "application/xml"})
  self.class.headers({"QUICKBASE-ACTION" => quickbase_action})
  response = Nokogiri::XML([self.class.post("/db/#{qb_params[:dbid]}", :body => clean_xml_string)].to_xml)
  error_handler(response)
  response
end