quickbase 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +42 -0
- data/lib/classes/api.rb +44 -0
- data/lib/classes/connection.rb +44 -0
- data/lib/classes/helper.rb +24 -0
- data/lib/classes/http.rb +40 -0
- data/lib/quickbase.rb +8 -0
- data/quickbase.gemspec +19 -0
- metadata +89 -0
data/README.rdoc
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
= Quickbase Ruby Gem
|
2
|
+
|
3
|
+
The Quickbase Gem provides integration access to the Intuit Quickbase API.
|
4
|
+
|
5
|
+
== Dependencies
|
6
|
+
|
7
|
+
* httparty
|
8
|
+
* libxml-ruby
|
9
|
+
* activesupport
|
10
|
+
|
11
|
+
== Installation
|
12
|
+
|
13
|
+
gem install quickbase
|
14
|
+
|
15
|
+
or, in your Gemfile
|
16
|
+
|
17
|
+
gem 'quickbase'
|
18
|
+
|
19
|
+
== Quick Start Example
|
20
|
+
|
21
|
+
Quickbase::Connection.username = QUICKBASE_USERNAME
|
22
|
+
Quickbase::Connection.password = QUICKBASE_PASSWORD
|
23
|
+
Quickbase::Connection.org = QUICKBASE_ORGANIZATION # defaults to www
|
24
|
+
|
25
|
+
require "rubygems"
|
26
|
+
require "quickbase"
|
27
|
+
|
28
|
+
quickbase = Quickbase::Connection.new(:apptoken => "apptoken", :dbid => "dbid")
|
29
|
+
|
30
|
+
records = quickbase.api.do_query(:query => "{'3'.EX.'5'}", :slist => "3", :clist => "3.6.7")
|
31
|
+
|
32
|
+
== More Examples
|
33
|
+
|
34
|
+
quickbase = Quickbase::Connection.new(:apptoken => "apptoken", :dbid => "dbid")
|
35
|
+
|
36
|
+
quickbase.api.add_record({:name => "John Smith", "6" => "New York City"})
|
37
|
+
|
38
|
+
quickbase.api.edit_record(6, {:city => "Washington"})
|
39
|
+
|
40
|
+
quickbase.api.delete_record(7)
|
41
|
+
|
42
|
+
==
|
data/lib/classes/api.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Quickbase
|
2
|
+
class Api
|
3
|
+
attr_accessor :connection
|
4
|
+
|
5
|
+
def initialize(connection)
|
6
|
+
instance_variable_set "@connection", connection
|
7
|
+
end
|
8
|
+
|
9
|
+
# Documentation at http://www.quickbase.com/api-guide/do_query.html
|
10
|
+
def do_query(params)
|
11
|
+
params.merge!({:fmt => "structured"})
|
12
|
+
clist = params[:clist].to_s.split(".")
|
13
|
+
response = connection.http.post("API_DoQuery", Quickbase::Helper.hash_to_xml(params))
|
14
|
+
array_of_records = response.find("//record[@type='array']/record")
|
15
|
+
records = array_of_records.empty? ? response.find("//record") : array_of_records
|
16
|
+
return [] if records.empty?
|
17
|
+
|
18
|
+
records.map{|record|
|
19
|
+
array_of_fields = record.find("f[@type='array']/f")
|
20
|
+
fields = array_of_fields.empty? ? record.find("f") : array_of_fields
|
21
|
+
Hash[fields.to_enum(:each_with_index).collect{|field,index| Hash[clist[index],field.content] }.map(&:flatten)]
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Documentation at http://www.quickbase.com/api-guide/add_record.html
|
26
|
+
def add_record(fields)
|
27
|
+
fields = Quickbase::Helper.generate_fields(fields)
|
28
|
+
connection.http.post("API_AddRecord", fields)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Documentation at http://www.quickbase.com/api-guide/edit_record.html
|
32
|
+
def edit_record(rid, fields)
|
33
|
+
tags = Quickbase::Helper.generate_fields(fields)
|
34
|
+
tags << Quickbase::Helper.hash_to_xml({:rid => rid.to_s})
|
35
|
+
connection.http.post("API_EditRecord", tags)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Documentation at http://www.quickbase.com/api-guide/delete_record.html
|
39
|
+
def delete_record(rid)
|
40
|
+
tags = Quickbase::Helper.hash_to_xml({:rid => rid.to_s})
|
41
|
+
connection.http.post("API_DeleteRecord", tags)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Quickbase
|
2
|
+
class Connection
|
3
|
+
class << self
|
4
|
+
attr_writer :username, :password, :hours, :apptoken, :dbid, :org
|
5
|
+
end
|
6
|
+
attr_reader :username, :password, :hours, :apptoken, :dbid, :org
|
7
|
+
|
8
|
+
def self.expectant_reader(*attributes)
|
9
|
+
attributes.each do |attribute|
|
10
|
+
(class << self; self; end).send(:define_method, attribute) do
|
11
|
+
attribute_value = instance_variable_get("@#{attribute}")
|
12
|
+
attribute_value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
expectant_reader :username, :password, :hours, :apptoken, :dbid, :org
|
17
|
+
|
18
|
+
def initialize(options = {})
|
19
|
+
[:username, :password, :hours, :apptoken, :dbid, :org].each do |attr|
|
20
|
+
instance_variable_set "@#{attr}", (options[attr].nil? ? Quickbase::Connection.send(attr) : options[attr])
|
21
|
+
end
|
22
|
+
instance_variable_set "@org", "www" if org.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def instantiate
|
26
|
+
config = {
|
27
|
+
:username => username,
|
28
|
+
:password => password,
|
29
|
+
:hours => hours,
|
30
|
+
:apptoken => apptoken,
|
31
|
+
:dbid => dbid,
|
32
|
+
:org => org
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def http
|
37
|
+
Quickbase::Http.new(instantiate)
|
38
|
+
end
|
39
|
+
|
40
|
+
def api
|
41
|
+
Quickbase::Api.new(self)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Quickbase
|
2
|
+
class Helper
|
3
|
+
def self.hash_to_xml(hash)
|
4
|
+
hash.map{|key,value|
|
5
|
+
tag = LibXML::XML::Node.new(key)
|
6
|
+
tag.content = value.to_s
|
7
|
+
tag
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.generate_xml(params)
|
12
|
+
LibXML::XML::Document.string("<qdbapi>#{params.join}</qdbapi>")
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.generate_fields(fields)
|
16
|
+
fields.map{|key,value|
|
17
|
+
field = LibXML::XML::Node.new("field")
|
18
|
+
key =~ /^[-+]?[0-9]+$/ ? field["fid"] = key.to_s : field["name"] = key.to_s
|
19
|
+
field.content = value
|
20
|
+
field
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/classes/http.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Quickbase
|
2
|
+
class Http
|
3
|
+
include HTTParty
|
4
|
+
attr_accessor :qb_params
|
5
|
+
|
6
|
+
def initialize(config)
|
7
|
+
self.class.base_uri "https://#{config[:org]}.quickbase.com"
|
8
|
+
instance_variable_set "@qb_params", {:dbid => "main"}
|
9
|
+
response = post("API_Authenticate", Quickbase::Helper.hash_to_xml(config))
|
10
|
+
qb_params[:ticket] = response.find_first("//ticket").content
|
11
|
+
qb_params[:apptoken] = config[:apptoken]
|
12
|
+
qb_params[:dbid] = config[:dbid]
|
13
|
+
end
|
14
|
+
|
15
|
+
def post(quickbase_action, params = [])
|
16
|
+
params = params.concat(Quickbase::Helper.hash_to_xml(qb_params))
|
17
|
+
clean_xml_string = Quickbase::Helper.generate_xml(params).to_s
|
18
|
+
self.class.headers({"Content-Length" => clean_xml_string.length.to_s})
|
19
|
+
self.class.headers({"Content-Type" => "application/xml"})
|
20
|
+
self.class.headers({"QUICKBASE-ACTION" => quickbase_action})
|
21
|
+
response = LibXML::XML::Document.string(self.class.post("/db/#{qb_params[:dbid]}", :body => clean_xml_string).to_xml)
|
22
|
+
error_handler(response)
|
23
|
+
response
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def error_handler(response)
|
29
|
+
case response.find_first("//errcode").content.to_i
|
30
|
+
when 0
|
31
|
+
return true
|
32
|
+
else
|
33
|
+
errcode = response.find_first('//errcode').content
|
34
|
+
errtext = response.find_first('//errtext').content
|
35
|
+
raise "#{errcode}: #{errtext}"
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/quickbase.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require "libxml"
|
2
|
+
require "httparty"
|
3
|
+
require "active_support/all"
|
4
|
+
|
5
|
+
require File.dirname(__FILE__) + "/classes/api.rb"
|
6
|
+
require File.dirname(__FILE__) + "/classes/connection.rb"
|
7
|
+
require File.dirname(__FILE__) + "/classes/helper.rb"
|
8
|
+
require File.dirname(__FILE__) + "/classes/http.rb"
|
data/quickbase.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{quickbase}
|
3
|
+
s.version = "0.0.1"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Artem Kalinchuk"]
|
7
|
+
s.date = %q{2011-09-19}
|
8
|
+
s.description = %q{The Quickbase Gem provides integration access to the Intuit Quickbase API.}
|
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"]
|
11
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Quickbase"]
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.rubyforge_project = %q{quickbase}
|
14
|
+
s.rubygems_version = %q{1.8.5}
|
15
|
+
s.summary = %q{Quickbase Ruby Gem}
|
16
|
+
s.add_dependency(%q<libxml-ruby>, [">= 0"])
|
17
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
18
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quickbase
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Artem Kalinchuk
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-19 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: libxml-ruby
|
16
|
+
requirement: &4708360 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *4708360
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: httparty
|
27
|
+
requirement: &4707830 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *4707830
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activesupport
|
38
|
+
requirement: &4707380 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *4707380
|
47
|
+
description: The Quickbase Gem provides integration access to the Intuit Quickbase
|
48
|
+
API.
|
49
|
+
email: artem9@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- lib/quickbase.rb
|
55
|
+
- quickbase.gemspec
|
56
|
+
- README.rdoc
|
57
|
+
- lib/classes/api.rb
|
58
|
+
- lib/classes/connection.rb
|
59
|
+
- lib/classes/helper.rb
|
60
|
+
- lib/classes/http.rb
|
61
|
+
homepage:
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --line-numbers
|
66
|
+
- --inline-source
|
67
|
+
- --title
|
68
|
+
- Quickbase
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.2'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project: quickbase
|
85
|
+
rubygems_version: 1.8.10
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Quickbase Ruby Gem
|
89
|
+
test_files: []
|