quickbase 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -2
- data/lib/classes/api.rb +10 -6
- data/lib/classes/connection.rb +2 -2
- data/lib/classes/helper.rb +6 -9
- data/lib/classes/http.rb +10 -6
- data/lib/quickbase.rb +1 -1
- data/quickbase.gemspec +3 -3
- data/spec/quickbase_spec.rb +75 -0
- metadata +9 -8
data/README.rdoc
CHANGED
@@ -5,7 +5,7 @@ The Quickbase Gem provides integration access to the Intuit Quickbase API.
|
|
5
5
|
== Dependencies
|
6
6
|
|
7
7
|
* httparty
|
8
|
-
*
|
8
|
+
* nokogiri
|
9
9
|
* activesupport
|
10
10
|
|
11
11
|
== Installation
|
@@ -41,4 +41,9 @@ or, in your Gemfile
|
|
41
41
|
|
42
42
|
quickbase.api.delete_record(7)
|
43
43
|
|
44
|
-
==
|
44
|
+
== Changes
|
45
|
+
|
46
|
+
01/13/2012
|
47
|
+
- Api was changed to API. Http was changed to HTTP.
|
48
|
+
- RSpec was added for testing.
|
49
|
+
- Replaced LibXML with Nokogiri
|
data/lib/classes/api.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Quickbase
|
2
|
-
class
|
2
|
+
class API
|
3
3
|
attr_accessor :connection
|
4
4
|
|
5
5
|
def initialize(connection)
|
@@ -13,15 +13,15 @@ module Quickbase
|
|
13
13
|
friendly = params[:friendly].to_s.split(".")
|
14
14
|
keys = friendly.empty? ? clist : friendly.map(&:to_sym)
|
15
15
|
response = connection.http.post("API_DoQuery", Quickbase::Helper.hash_to_xml(params))
|
16
|
-
array_of_records = response.
|
17
|
-
records = array_of_records.empty? ? response.
|
16
|
+
array_of_records = response.xpath("//record[@type='array']/record")
|
17
|
+
records = array_of_records.empty? ? response.xpath("//record") : array_of_records
|
18
18
|
return [] if records.empty?
|
19
19
|
|
20
20
|
records.map{|record|
|
21
|
-
array_of_fields = record.
|
22
|
-
fields = array_of_fields.empty? ? record.
|
21
|
+
array_of_fields = record.xpath("f[@type='array']/f")
|
22
|
+
fields = array_of_fields.empty? ? record.xpath("f") : array_of_fields
|
23
23
|
Hash[fields.to_enum(:each_with_index).collect{|field,index|
|
24
|
-
field.content = "" unless field.
|
24
|
+
field.content = "" unless field.xpath("id").first.nil? # QuickBase adds ID to the tag if its empty
|
25
25
|
Hash[keys[index],field.content]
|
26
26
|
}.map(&:flatten)]
|
27
27
|
}
|
@@ -46,4 +46,8 @@ module Quickbase
|
|
46
46
|
connection.http.post("API_DeleteRecord", tags)
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
50
|
+
class Api < API
|
51
|
+
puts "Class Api will be deprecated. Please use API instead."
|
52
|
+
end
|
49
53
|
end
|
data/lib/classes/connection.rb
CHANGED
data/lib/classes/helper.rb
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
module Quickbase
|
2
2
|
class Helper
|
3
3
|
def self.hash_to_xml(hash)
|
4
|
-
hash.map{|key,value|
|
5
|
-
|
6
|
-
tag.content = value.to_s
|
7
|
-
tag
|
4
|
+
hash.map{|key,value|
|
5
|
+
"<#{key}>#{value}</#{key}>"
|
8
6
|
}
|
9
7
|
end
|
10
8
|
|
11
9
|
def self.generate_xml(params)
|
12
|
-
|
10
|
+
Nokogiri::XML("<qdbapi>#{params.join}</qdbapi>")
|
13
11
|
end
|
14
12
|
|
15
13
|
def self.generate_fields(fields)
|
16
14
|
fields.map{|key,value|
|
17
|
-
field =
|
18
|
-
key =~ /^[-+]?[0-9]+$/ ? field
|
19
|
-
field.
|
20
|
-
field
|
15
|
+
field = "<field "
|
16
|
+
fid = (key =~ /^[-+]?[0-9]+$/) ? field.concat('fid="'+key.to_s+'"') : field.concat('name="'+key.to_s+'"')
|
17
|
+
field.concat(">#{value}</field>")
|
21
18
|
}
|
22
19
|
end
|
23
20
|
end
|
data/lib/classes/http.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Quickbase
|
2
|
-
class
|
2
|
+
class HTTP
|
3
3
|
include HTTParty
|
4
4
|
attr_accessor :qb_params
|
5
5
|
|
@@ -7,7 +7,7 @@ module Quickbase
|
|
7
7
|
self.class.base_uri "https://#{config[:org]}.quickbase.com"
|
8
8
|
instance_variable_set "@qb_params", {:dbid => "main"}
|
9
9
|
response = post("API_Authenticate", Quickbase::Helper.hash_to_xml(config))
|
10
|
-
qb_params[:ticket] = response.
|
10
|
+
qb_params[:ticket] = response.xpath("//ticket").first.content
|
11
11
|
qb_params[:apptoken] = config[:apptoken]
|
12
12
|
qb_params[:dbid] = config[:dbid]
|
13
13
|
end
|
@@ -18,7 +18,7 @@ module Quickbase
|
|
18
18
|
self.class.headers({"Content-Length" => clean_xml_string.length.to_s})
|
19
19
|
self.class.headers({"Content-Type" => "application/xml"})
|
20
20
|
self.class.headers({"QUICKBASE-ACTION" => quickbase_action})
|
21
|
-
response =
|
21
|
+
response = Nokogiri::XML([self.class.post("/db/#{qb_params[:dbid]}", :body => clean_xml_string)].to_xml)
|
22
22
|
error_handler(response)
|
23
23
|
response
|
24
24
|
end
|
@@ -26,15 +26,19 @@ module Quickbase
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def error_handler(response)
|
29
|
-
case response.
|
29
|
+
case response.xpath("//errcode").first.content.to_i
|
30
30
|
when 0
|
31
31
|
return true
|
32
32
|
else
|
33
|
-
errcode = response.
|
34
|
-
errtext = response.
|
33
|
+
errcode = response.xpath('//errcode').first.content
|
34
|
+
errtext = response.xpath('//errtext').first.content
|
35
35
|
raise "#{errcode}: #{errtext}"
|
36
36
|
return false
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
class Http < HTTP
|
42
|
+
puts "Class Http will be deprecated. Please use HTTP instead."
|
43
|
+
end
|
40
44
|
end
|
data/lib/quickbase.rb
CHANGED
data/quickbase.gemspec
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{quickbase}
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.4"
|
4
4
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
6
6
|
s.authors = ["Artem Kalinchuk"]
|
7
7
|
s.date = %q{2011-09-19}
|
8
8
|
s.description = %q{The Quickbase Gem provides integration access to the Intuit Quickbase API.}
|
9
9
|
s.email = %q{artem9@gmail.com}
|
10
|
-
s.files = ["lib/quickbase.rb", "quickbase.gemspec", "README.rdoc", "lib/classes/api.rb", "lib/classes/connection.rb", "lib/classes/helper.rb", "lib/classes/http.rb"]
|
10
|
+
s.files = ["lib/quickbase.rb", "quickbase.gemspec", "README.rdoc", "lib/classes/api.rb", "lib/classes/connection.rb", "lib/classes/helper.rb", "lib/classes/http.rb", "spec/quickbase_spec.rb"]
|
11
11
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Quickbase"]
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.rubyforge_project = %q{quickbase}
|
14
14
|
s.rubygems_version = %q{1.8.5}
|
15
15
|
s.summary = %q{Quickbase Ruby Gem}
|
16
|
-
s.add_dependency(%q<
|
16
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
17
17
|
s.add_dependency(%q<httparty>, [">= 0"])
|
18
18
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
19
19
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
gem "activerecord"
|
2
|
+
require "active_record"
|
3
|
+
require "cgi"
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
require File.dirname(__FILE__) + "/../lib/quickbase.rb"
|
7
|
+
|
8
|
+
Quickbase::Connection.username = ""
|
9
|
+
Quickbase::Connection.password = ""
|
10
|
+
Quickbase::Connection.org = ""
|
11
|
+
apptoken = ""
|
12
|
+
dbid = ""
|
13
|
+
|
14
|
+
describe Quickbase::Connection do
|
15
|
+
describe "initialize" do
|
16
|
+
it "initializes successfully" do
|
17
|
+
quickbase = Quickbase::Connection.new(:apptoken => apptoken, :dbid => dbid)
|
18
|
+
|
19
|
+
connection_hash = {
|
20
|
+
:apptoken => quickbase.apptoken,
|
21
|
+
:dbid => quickbase.dbid,
|
22
|
+
:hours => quickbase.hours,
|
23
|
+
:org => quickbase.org,
|
24
|
+
:password => quickbase.password,
|
25
|
+
:username => quickbase.username
|
26
|
+
}
|
27
|
+
|
28
|
+
default_values_hash = {
|
29
|
+
:apptoken => apptoken,
|
30
|
+
:dbid => dbid,
|
31
|
+
:hours => nil,
|
32
|
+
:org => Quickbase::Connection.org,
|
33
|
+
:password => Quickbase::Connection.password,
|
34
|
+
:username => Quickbase::Connection.username
|
35
|
+
}
|
36
|
+
|
37
|
+
connection_hash.should == default_values_hash
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe Quickbase::Helper do
|
43
|
+
describe "self.hash_to_xml" do
|
44
|
+
it "creates XML out of a hash" do
|
45
|
+
hash = {:test => "this is the content of the test tag", :test2 => "contents of test2"}
|
46
|
+
|
47
|
+
Quickbase::Helper.hash_to_xml(hash).join.should == "<test>this is the content of the test tag</test><test2>contents of test2</test2>"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "self.generate_xml" do
|
52
|
+
it "returns a formatted Quickbase XML" do
|
53
|
+
hash = {:test => "this is the content of the test tag", :test2 => "contents of test2"}
|
54
|
+
Quickbase::Helper.generate_xml(Quickbase::Helper.hash_to_xml(hash)).to_s.should == Nokogiri::XML("<qdbapi><test>this is the content of the test tag</test><test2>contents of test2</test2></qdbapi>").to_s
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "self.generate_fields" do
|
59
|
+
it "creates an array of tags with all the fields" do
|
60
|
+
fields = {:first_name => "John", :last_name => "Smith"}
|
61
|
+
Quickbase::Helper.generate_fields(fields).should == ["<field name=\"first_name\">John</field>", "<field name=\"last_name\">Smith</field>"]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe Quickbase::API do
|
67
|
+
describe "do_query" do
|
68
|
+
it "queries for data" do
|
69
|
+
quickbase = Quickbase::Connection.new(:apptoken => apptoken, :dbid => dbid)
|
70
|
+
|
71
|
+
results = quickbase.api.do_query(:query => "{'1'.XEX.'1'}", :clist => "1.2", :slist => "1")
|
72
|
+
results.length.should_not == 0
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quickbase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,8 +12,8 @@ cert_chain: []
|
|
12
12
|
date: 2011-09-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: &
|
15
|
+
name: nokogiri
|
16
|
+
requirement: &70162225377940 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70162225377940
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: httparty
|
27
|
-
requirement: &
|
27
|
+
requirement: &70162225376800 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70162225376800
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activesupport
|
38
|
-
requirement: &
|
38
|
+
requirement: &70162225374140 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70162225374140
|
47
47
|
description: The Quickbase Gem provides integration access to the Intuit Quickbase
|
48
48
|
API.
|
49
49
|
email: artem9@gmail.com
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/classes/connection.rb
|
59
59
|
- lib/classes/helper.rb
|
60
60
|
- lib/classes/http.rb
|
61
|
+
- spec/quickbase_spec.rb
|
61
62
|
homepage:
|
62
63
|
licenses: []
|
63
64
|
post_install_message:
|