class Quickbase::HTTP

Attributes

qb_params[RW]

Public Class Methods

new(config) click to toggle source
   # File lib/classes/http.rb
 7 def initialize(config)
 8   self.class.base_uri "https://#{config[:org]}.quickbase.com"
 9   instance_variable_set "@qb_params", {:dbid => "main"}
10 
11   http_proxy = config[:http_proxy] || ENV['http_proxy']
12   setup_proxy(http_proxy) if http_proxy
13 
14   qb_params[:dbid] = config[:dbid]
15   qb_params[:usertoken] = config[:usertoken]
16 end

Public Instance Methods

post(quickbase_action, params = []) click to toggle source
   # File lib/classes/http.rb
18 def post(quickbase_action, params = [])
19   params = params.concat(Quickbase::Helper.hash_to_xml(qb_params))
20   clean_xml_string = Quickbase::Helper.generate_xml(params).to_s
21   self.class.headers({"Content-Length" => clean_xml_string.length.to_s})
22   self.class.headers({"Content-Type" => "application/xml"})
23   self.class.headers({"QUICKBASE-ACTION" => quickbase_action})
24   response = Nokogiri::XML([self.class.post("/db/#{qb_params[:dbid]}", :body => clean_xml_string)].to_xml)
25   error_handler(response)
26   response
27 end

Private Instance Methods

auth_ticket(config) click to toggle source
   # File lib/classes/http.rb
30 def auth_ticket(config)
31   response = post("API_Authenticate", Quickbase::Helper.hash_to_xml(config))
32   response.xpath("//ticket").first.content
33 end
error_handler(response) click to toggle source
   # File lib/classes/http.rb
52 def error_handler(response)
53   errcode = response.xpath("//errcode").first.content
54 
55   unless errcode.to_i.zero?
56     errtext = response.xpath('//errtext').first.content
57     raise "#{errcode}: #{errtext}"
58   end
59 end
no_proxy?() click to toggle source
   # File lib/classes/http.rb
35 def no_proxy?
36   host = URI.parse(self.class.base_uri).host
37   ENV.fetch('no_proxy','').split(',').any? do |pattern|
38     # convert patterns like `*.example.com` into `.*\.example\.com`
39     host =~ Regexp.new(pattern.gsub(/\./,'\\.').gsub(/\*/,'.*'))
40   end
41 end
setup_proxy(proxy_url) click to toggle source
   # File lib/classes/http.rb
43 def setup_proxy(proxy_url)
44   return if no_proxy?
45 
46   proxy_url = URI.parse(proxy_url)
47 
48   self.class.http_proxy(proxy_url.host, proxy_url.port,
49                         proxy_url.user, proxy_url.password)
50 end